bug fix: Unix compilation problems
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@318 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
f682afc33b
commit
7d66b82b9a
4 changed files with 45 additions and 45 deletions
|
@ -21,7 +21,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "loki/Singleton.h"
|
#include "loki/Singleton.h"
|
||||||
#include "loki/TypeList.h"
|
#include "loki/Typelist.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Loki
|
namespace Loki
|
||||||
|
|
|
@ -12,14 +12,14 @@
|
||||||
// singletons and globally and locally defined dynamically allocated
|
// singletons and globally and locally defined dynamically allocated
|
||||||
// objects.
|
// objects.
|
||||||
//
|
//
|
||||||
// The program defines three classes: Example, Keyboard and Log.
|
// The program defines three classes: Example, Keyboard and LogClass.
|
||||||
//
|
//
|
||||||
// The purpose of the Example class is to send a message to cout
|
// The purpose of the Example class is to send a message to cout
|
||||||
// when an Example object is being destroyed.
|
// when an Example object is being destroyed.
|
||||||
//
|
//
|
||||||
// The Keyboard class is a singleton.
|
// The Keyboard class is a singleton.
|
||||||
//
|
//
|
||||||
// The Log class is also a singleton.
|
// The LogClass class is also a singleton.
|
||||||
//
|
//
|
||||||
// The pGlobal object is deleted using an adapter functor to
|
// The pGlobal object is deleted using an adapter functor to
|
||||||
// customize Example's destruction (see destGlobal()).
|
// customize Example's destruction (see destGlobal()).
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
// 1) The global object
|
// 1) The global object
|
||||||
// 2) The local object
|
// 2) The local object
|
||||||
// 3) The Keyboard singleton
|
// 3) The Keyboard singleton
|
||||||
// 4) The Log singleton
|
// 4) The LogClass singleton
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
// longevity 1 2 3 4
|
// longevity 1 2 3 4
|
||||||
|
@ -104,23 +104,23 @@ inline unsigned int GetLongevity(Keyboard *)
|
||||||
typedef SingletonHolder<Keyboard, CreateUsingNew, SingletonWithLongevity> keyboard;
|
typedef SingletonHolder<Keyboard, CreateUsingNew, SingletonWithLongevity> keyboard;
|
||||||
|
|
||||||
|
|
||||||
// A singleton Log object derived from the Example class.
|
// A singleton LogClass object derived from the Example class.
|
||||||
// Its longevity is set by the user on the command line.
|
// Its longevity is set by the user on the command line.
|
||||||
//
|
//
|
||||||
class Log : public Example
|
class LogClass : public Example
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Log() : Example("Destroying Log")
|
LogClass() : Example("Destroying LogClass")
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
inline unsigned int GetLongevity(Log *)
|
inline unsigned int GetLongevity(LogClass *)
|
||||||
{
|
{
|
||||||
return logPriority;
|
return logPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef SingletonHolder<Log, CreateUsingNew, SingletonWithLongevity> log;
|
typedef SingletonHolder<LogClass, CreateUsingNew, SingletonWithLongevity> LogBook;
|
||||||
|
|
||||||
|
|
||||||
// Instantiate a global Example object. It's not a singleton
|
// Instantiate a global Example object. It's not a singleton
|
||||||
|
@ -146,7 +146,7 @@ void help(const char *s)
|
||||||
cout << " par1: global object\n";
|
cout << " par1: global object\n";
|
||||||
cout << " par2: local object\n";
|
cout << " par2: local object\n";
|
||||||
cout << " par3: keyboard singleton\n";
|
cout << " par3: keyboard singleton\n";
|
||||||
cout << " par4: log singleton\n";
|
cout << " par4: LogBook singleton\n";
|
||||||
cout << "Example: " << s << " 1 2 3 4" << endl;
|
cout << "Example: " << s << " 1 2 3 4" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ int main(int argc, char *argv[])
|
||||||
pLocal->echo("pLocal created after main() started.");
|
pLocal->echo("pLocal created after main() started.");
|
||||||
|
|
||||||
// Instantiate both singletons by calling them...
|
// Instantiate both singletons by calling them...
|
||||||
log::Instance().echo("Log singleton instantiated");
|
LogBook::Instance().echo("LogClass singleton instantiated");
|
||||||
keyboard::Instance().echo("Keyboard singleton instantiated");
|
keyboard::Instance().echo("Keyboard singleton instantiated");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -12,14 +12,14 @@
|
||||||
//
|
//
|
||||||
// Expected output:
|
// Expected output:
|
||||||
//
|
//
|
||||||
// Log::Log()
|
// LogClass::LogClass()
|
||||||
// Log singleton instantiated
|
// LogClass singleton instantiated
|
||||||
// Going to manually delete log.
|
// Going to manually delete LogBook.
|
||||||
// Log::~Log()
|
// LogClass::~LogClass()
|
||||||
// Log::Log()
|
// LogClass::LogClass()
|
||||||
// Log reinstantiated.
|
// LogClass reinstantiated.
|
||||||
// Going to terminate program now.
|
// Going to terminate program now.
|
||||||
// Log::~Log()
|
// LogClass::~LogClass()
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -28,19 +28,19 @@
|
||||||
using namespace std; // okay for small programs
|
using namespace std; // okay for small programs
|
||||||
using namespace Loki; // okay for small programs
|
using namespace Loki; // okay for small programs
|
||||||
|
|
||||||
// A singleton Log object derived from the Example class.
|
// A singleton LogClass object derived from the Example class.
|
||||||
// Its longevity is set by the user on the command line.
|
// Its longevity is set by the user on the command line.
|
||||||
//
|
//
|
||||||
class Log
|
class LogClass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Log()
|
LogClass()
|
||||||
{
|
{
|
||||||
print("Log::Log()");
|
print("LogClass::LogClass()");
|
||||||
};
|
};
|
||||||
~Log()
|
~LogClass()
|
||||||
{
|
{
|
||||||
print("Log::~Log()");
|
print("LogClass::~LogClass()");
|
||||||
}
|
}
|
||||||
void print(const char *s)
|
void print(const char *s)
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SingletonHolder<Log, CreateUsingNew, DeletableSingleton> log;
|
typedef SingletonHolder<LogClass, CreateUsingNew, DeletableSingleton> LogBook;
|
||||||
|
|
||||||
class Example
|
class Example
|
||||||
{
|
{
|
||||||
|
@ -63,13 +63,13 @@ public:
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// Instantiate both singletons by calling them...
|
// Instantiate both singletons by calling them...
|
||||||
log::Instance().print("Log singleton instantiated");
|
LogBook::Instance().print("LogClass singleton instantiated");
|
||||||
log::Instance().print("Going to manually delete log.");
|
LogBook::Instance().print("Going to manually delete LogBook.");
|
||||||
|
|
||||||
DeletableSingleton<Log>::GracefulDelete();
|
DeletableSingleton<LogClass>::GracefulDelete();
|
||||||
|
|
||||||
log::Instance().print("Log reinstantiated.");
|
LogBook::Instance().print("LogClass reinstantiated.");
|
||||||
log::Instance().print("Going to terminate program now.");
|
LogBook::Instance().print("Going to terminate program now.");
|
||||||
|
|
||||||
#if defined(__BORLANDC__) || defined(__GNUC__) || defined(_MSC_VER)
|
#if defined(__BORLANDC__) || defined(__GNUC__) || defined(_MSC_VER)
|
||||||
system("pause"); // Stop console window from closing if run from IDE.
|
system("pause"); // Stop console window from closing if run from IDE.
|
||||||
|
|
|
@ -8,19 +8,19 @@
|
||||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// A singleton Log object that resurrects itself after
|
// A singleton LogClass object that resurrects itself after
|
||||||
// it has been automatically destroyed during program
|
// it has been automatically destroyed during program
|
||||||
// termination. When a dead-reference to the Log
|
// termination. When a dead-reference to the LogClass
|
||||||
// singleton is detected, it is resurrected automatically.
|
// singleton is detected, it is resurrected automatically.
|
||||||
//
|
//
|
||||||
// Expected output:
|
// Expected output:
|
||||||
// Example c'tor
|
// Example c'tor
|
||||||
// Log c'tor
|
// LogClass c'tor
|
||||||
// Log now instantiated.
|
// LogClass now instantiated.
|
||||||
// Log d'tor
|
// LogClass d'tor
|
||||||
// Example d'tor starting
|
// Example d'tor starting
|
||||||
// Log c'tor
|
// LogClass c'tor
|
||||||
// Log: inside Example d'tor
|
// LogClass: inside Example d'tor
|
||||||
// Example d'tor finished
|
// Example d'tor finished
|
||||||
//
|
//
|
||||||
// The last line of the output only appears when this
|
// The last line of the output only appears when this
|
||||||
|
@ -34,16 +34,16 @@
|
||||||
using namespace std; // okay for small programs
|
using namespace std; // okay for small programs
|
||||||
using namespace Loki; // okay for small programs
|
using namespace Loki; // okay for small programs
|
||||||
|
|
||||||
class Log
|
class LogClass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Log()
|
LogClass()
|
||||||
{
|
{
|
||||||
echo("Log c'tor");
|
echo("LogClass c'tor");
|
||||||
}
|
}
|
||||||
~Log()
|
~LogClass()
|
||||||
{
|
{
|
||||||
echo("Log d'tor");
|
echo("LogClass d'tor");
|
||||||
}
|
}
|
||||||
void echo(const char *s)
|
void echo(const char *s)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SingletonHolder<Log, CreateUsingNew, PhoenixSingleton> log;
|
typedef SingletonHolder<LogClass, CreateUsingNew, PhoenixSingleton> LogBook;
|
||||||
|
|
||||||
|
|
||||||
// A generic example class that stores and echoes a const char.
|
// A generic example class that stores and echoes a const char.
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
~Example()
|
~Example()
|
||||||
{
|
{
|
||||||
echo("Example d'tor starting");
|
echo("Example d'tor starting");
|
||||||
log::Instance().echo("Log: inside Example d'tor");
|
LogBook::Instance().echo("LogClass: inside Example d'tor");
|
||||||
echo("Example d'tor finished");
|
echo("Example d'tor finished");
|
||||||
}
|
}
|
||||||
void echo(const char *s)
|
void echo(const char *s)
|
||||||
|
@ -80,7 +80,7 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
Example *example = new Example();
|
Example *example = new Example();
|
||||||
SetLongevity<Example, void (*)(Example*)>(example, 1, &Loki::Private::Deleter<Example>::Delete);
|
SetLongevity<Example, void (*)(Example*)>(example, 1, &Loki::Private::Deleter<Example>::Delete);
|
||||||
log::Instance().echo("Log now instantiated.");
|
LogBook::Instance().echo("LogClass now instantiated.");
|
||||||
|
|
||||||
#if defined(__BORLANDC__) || defined(__GNUC__) || defined(_MSC_VER)
|
#if defined(__BORLANDC__) || defined(__GNUC__) || defined(_MSC_VER)
|
||||||
system("pause"); // Stop console window from closing if run from IDE.
|
system("pause"); // Stop console window from closing if run from IDE.
|
||||||
|
|
Loading…
Reference in a new issue