Adding DeletableSingleton project to CVS.

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@540 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
rich_sposato 2006-02-20 23:22:14 +00:00
parent 2c0f44456f
commit 503733513f
2 changed files with 259 additions and 0 deletions

View file

@ -0,0 +1,80 @@
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2005 by Curtis Krauskopf
// Copyright (c) 2005 by Peter Kuemmel
//
// Code covered by the MIT License
// The authors make no representations about the suitability of this software
// for any purpose. It is provided "as is" without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Show an example of a Loki policy that uses DeletableSingleton.
//
// Expected output:
//
// LogClass::LogClass()
// LogClass singleton instantiated
// Going to manually delete LogBook.
// LogClass::~LogClass()
// LogClass::LogClass()
// LogClass reinstantiated.
// Going to terminate program now.
// LogClass::~LogClass()
//
#include <iostream>
#include <loki/Singleton.h> // for Loki::SingletonHolder
using namespace std; // okay for small programs
using namespace Loki; // okay for small programs
// A singleton LogClass object derived from the Example class.
// Its longevity is set by the user on the command line.
//
class LogClass
{
public:
LogClass()
{
print("LogClass::LogClass()");
};
~LogClass()
{
print("LogClass::~LogClass()");
}
void print(const char *s)
{
cout << s << endl;
}
};
typedef SingletonHolder<LogClass, CreateUsingNew, DeletableSingleton> LogBook;
class Example
{
public:
void method()
{
cout << "test\n";
}
};
int main(int argc, char *argv[])
{
// Instantiate both singletons by calling them...
LogBook::Instance().print("LogClass singleton instantiated");
LogBook::Instance().print("Going to manually delete LogBook.");
DeletableSingleton<LogClass>::GracefulDelete();
LogBook::Instance().print("LogClass reinstantiated.");
LogBook::Instance().print("Going to terminate program now.");
#if defined(__BORLANDC__) || defined(_MSC_VER)
system("PAUSE");
#endif
return 0;
}

View file

@ -0,0 +1,179 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="DeletableSingleton"
ProjectGUID="{B87B3522-7DAA-400D-A47D-A74B9B8B3552}"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\include"
WarningLevel="4"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\include"
WarningLevel="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\DeletableSingleton.cpp"
>
</File>
<File
RelativePath="..\..\src\Singleton.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\..\include\loki\Singleton.h"
>
</File>
<File
RelativePath="..\..\include\loki\Threads.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>