move instantiation to the source file (fixes linker error with gcc 4.0.1 on the mac), Thanks to Idar Tollefsen and Sam Miller
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@703 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
68a09a05be
commit
f628dc7165
5 changed files with 28 additions and 18 deletions
|
@ -856,8 +856,12 @@ namespace Loki
|
|||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LOKI_SINGLETON_EXPORT
|
||||
#define LOKI_SINGLETON_EXPORT
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
class Singleton
|
||||
class LOKI_SINGLETON_EXPORT Singleton
|
||||
{
|
||||
public:
|
||||
static T& Instance();
|
||||
|
@ -897,6 +901,9 @@ namespace Loki \
|
|||
#endif // SINGLETON_INC_
|
||||
|
||||
// $Log$
|
||||
// Revision 1.32 2006/09/15 06:30:16 syntheticpp
|
||||
// move instantiation to the source file (fixes linker error with gcc 4.0.1 on the mac), Thanks to Idar Tollefsen and Sam Miller
|
||||
//
|
||||
// Revision 1.31 2006/06/19 12:39:08 syntheticpp
|
||||
// replace tabs with 4 spaces
|
||||
//
|
||||
|
|
|
@ -3,8 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 9.00
|
|||
# Visual C++ Express 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client", "Client.vcproj", "{237F4D1A-6301-4656-8F34-B0F6496E929F}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0DCBE03A-DAC7-4669-B29B-102D8F563736} = {0DCBE03A-DAC7-4669-B29B-102D8F563736}
|
||||
{42E13925-28CE-421B-993E-162510C90CD6} = {42E13925-28CE-421B-993E-162510C90CD6}
|
||||
{0DCBE03A-DAC7-4669-B29B-102D8F563736} = {0DCBE03A-DAC7-4669-B29B-102D8F563736}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Foo", "foo.vcproj", "{42E13925-28CE-421B-993E-162510C90CD6}"
|
||||
|
|
|
@ -14,14 +14,13 @@
|
|||
|
||||
/*
|
||||
|
||||
Test for singletons in a shared libraries:
|
||||
Test for singletons with shared libraries:
|
||||
|
||||
- there is a Foo class in Foo.dll/so
|
||||
- there is a Foo singleton object which is exported by SingletonDll.dll/so
|
||||
- the Foo singleton object is managed by a Loki::SingletonHolder typedef
|
||||
- the declaration of the Loki::SingletonHolder type is visiable only
|
||||
in singletondll.cpp
|
||||
- a client (this file) imports the singleton object from SingletonDll.dll/so
|
||||
- the Foo class is in the shared library Foo.dll/so
|
||||
- the Foo singleton object is in another shared library: SingletonDll.dll/so
|
||||
- the Foo singleton object is managed by Loki::SingletonHolder
|
||||
- Loki::SingletonHolder is only used in singletondll.cpp
|
||||
- the client (this file) imports the singleton object from SingletonDll.dll/so
|
||||
|
||||
*/
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@ typedef Loki::SingletonHolder<Foo> FooSingleton;
|
|||
|
||||
LOKI_SINGLETON_INSTANCE_DEFINITION(FooSingleton)
|
||||
/*
|
||||
This code will be generated by the macro,
|
||||
(ObjectType is a typedef of SingletonHolder):
|
||||
|
||||
namespace Loki
|
||||
{
|
||||
template<>
|
||||
|
@ -35,8 +38,11 @@ namespace Loki
|
|||
template<>
|
||||
Foo& Singleton<Foo>::Instance()
|
||||
{
|
||||
return FooSingleton::Instance();
|
||||
return Loki::SingletonHolder<Foo>::Instance();
|
||||
}
|
||||
|
||||
|
||||
// explicit instantiations
|
||||
template class Singleton<Foo>;
|
||||
template class Loki::Singleton<Foo>;
|
||||
|
||||
|
|
|
@ -19,24 +19,22 @@
|
|||
class Foo;
|
||||
|
||||
// Use the predefined Loki::Singleton
|
||||
// and export Loki::Singleton<Foo>
|
||||
// of loki/Singleton.h and use the export
|
||||
// specifier of the current library
|
||||
#define LOKI_SINGLETON_EXPORT SINGLETONDLL_EXPORT
|
||||
#include <loki/Singleton.h>
|
||||
|
||||
template class SINGLETONDLL_EXPORT Loki::Singleton<Foo>;
|
||||
|
||||
|
||||
// declare the Singleton template by yourself
|
||||
// and export Singleton<Foo>
|
||||
// so the singleton is not in the Loki namespace
|
||||
// and export Singleton<Foo>, so the singleton
|
||||
// is not in the Loki namespace
|
||||
template<class T>
|
||||
class Singleton
|
||||
class SINGLETONDLL_EXPORT Singleton
|
||||
{
|
||||
public:
|
||||
static T& Instance();
|
||||
};
|
||||
|
||||
template class SINGLETONDLL_EXPORT Singleton<Foo>;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue