add register test code

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@596 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
syntheticpp 2006-03-08 16:50:18 +00:00
parent 5f12e7ee82
commit e4d7c445d8
9 changed files with 628 additions and 0 deletions

21
test/Register/Makefile Executable file
View file

@ -0,0 +1,21 @@
BIN = main
LIB1 = libfoo.a
CXXFLAGS = -Wall -Wold-style-cast -Wundef -Wsign-compare -Wconversion -Wpointer-arith -pedantic -O2 -DLOKI_FUNCTOR_IS_NOT_A_SMALLOBJECT
CPPFLAGS = -I../../include -DNDEBUG
LDFLAGS = -L../../lib
LDLIBS = -lloki
.PHONY: build clean
build: $(BIN)
$(BIN): $(LIB1)
$(CXX) $(CXXFLAGS) -L. $(LDFLAGS) $(CPPFLAGS) -o $(BIN) main.cpp $(LDLIBS) -lfoo
$(LIB1): foo.o
ar rs $(LIB1) foo.o
%.a : %.cpp
$(CXX) -c $(CXXFLAGS) -fPIC $(CPPFLAGS) -o $@ $<
clean:
rm -f $(BIN) $(LIB1)

26
test/Register/Register.sln Executable file
View file

@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual C++ Express 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foo", "foo.vcproj", "{42E13925-28CE-421B-993E-162510C90CD6}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "main", "main.vcproj", "{237F4D1A-6301-4656-8F34-B0F6496E929F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{42E13925-28CE-421B-993E-162510C90CD6}.Debug|Win32.ActiveCfg = Debug|Win32
{42E13925-28CE-421B-993E-162510C90CD6}.Debug|Win32.Build.0 = Debug|Win32
{42E13925-28CE-421B-993E-162510C90CD6}.Release|Win32.ActiveCfg = Release|Win32
{42E13925-28CE-421B-993E-162510C90CD6}.Release|Win32.Build.0 = Release|Win32
{237F4D1A-6301-4656-8F34-B0F6496E929F}.Debug|Win32.ActiveCfg = Debug|Win32
{237F4D1A-6301-4656-8F34-B0F6496E929F}.Debug|Win32.Build.0 = Debug|Win32
{237F4D1A-6301-4656-8F34-B0F6496E929F}.Release|Win32.ActiveCfg = Release|Win32
{237F4D1A-6301-4656-8F34-B0F6496E929F}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

36
test/Register/classlist.h Executable file
View file

@ -0,0 +1,36 @@
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2006 Peter Kümmel
// Permission to use, copy, modify, distribute and sell this software for any
// purpose is hereby granted without fee, provided that the above copyright
// notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation.
// The author makes no representations about the
// suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
#ifndef CLASSLIST_H
#define CLASSLIST_H
// $Header$
#include <string>
#include <loki/Register.h>
struct Base
{
virtual void foo() = 0;
};
bool registerClass(std::string, Base*(*)() );
typedef Loki::Seq
<
struct Foo,
struct Boo
>::Type ClassList;
#endif

60
test/Register/foo.cpp Executable file
View file

@ -0,0 +1,60 @@
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2006 Peter Kümmel
// Permission to use, copy, modify, distribute and sell this software for any
// purpose is hereby granted without fee, provided that the above copyright
// notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation.
// The author makes no representations about the
// suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// $Header$
#include "foo.h"
#include <iostream>
Foo::Foo(){}
Boo::Boo(){}
void Foo::foo(){std::cout << "Foo::foo() called, this: " << this << "\n"; }
void Boo::foo(){std::cout << "Boo::foo() called, this: " << this << "\n"; }
// Register code
#include "classlist.h"
LOKI_CHECK_CLASS_IN_LIST( Foo, ClassList )
LOKI_CHECK_CLASS_IN_LIST( Boo, ClassList )
Base* createFoo(){ return new Foo; }
Base* createBoo(){ return new Boo; }
namespace Loki
{
template<> bool RegisterFunction<Foo>()
{
std::cout << "RegisterFunction<Foo>\n";
return registerClass("Foo", &createFoo);
}
template<> bool RegisterFunction<Boo>()
{
std::cout << "RegisterFunction<Boo>\n";
return registerClass("Boo", &createBoo);
}
template<> bool UnRegisterFunction<Foo>()
{
std::cout << "UnRegisterFunction<Foo>\n";
return true;
}
template<> bool UnRegisterFunction<Boo>()
{
std::cout << "UnRegisterFunction<Boo>\n";
return true;
}
}

34
test/Register/foo.h Executable file
View file

@ -0,0 +1,34 @@
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2006 Peter Kümmel
// Permission to use, copy, modify, distribute and sell this software for any
// purpose is hereby granted without fee, provided that the above copyright
// notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation.
// The author makes no representations about the
// suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
#ifndef LOKI_FOO_H
#define LOKI_FOO_H
// $Header$
#include "classlist.h"
struct Foo : Base
{
Foo();
void foo();
};
struct Boo : Base
{
Boo();
void foo();
};
#endif

193
test/Register/foo.vcproj Executable file
View file

@ -0,0 +1,193 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="foo"
ProjectGUID="{42E13925-28CE-421B-993E-162510C90CD6}"
RootNamespace="Foo"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory="."
IntermediateDirectory="Release\"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
WarningLevel="0"
DefaultCharType="0"
EnableErrorChecks="1"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-Zm200 -EHsc /wd4127 /wd4512"
Optimization="2"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="NDEBUG,_WINDOWS,UNICODE,WIN32,LOKI_FUNCTOR_IS_NOT_A_SMALLOBJECT"
GeneratePreprocessedFile="0"
MinimalRebuild="false"
ExceptionHandling="1"
RuntimeLibrary="2"
BufferSecurityCheck="false"
AssemblerListingLocation="Release\"
ObjectFile="Release\"
ProgramDataBaseFileName=".\"
WarningLevel="4"
SuppressStartupBanner="true"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
WarningLevel="0"
DefaultCharType="0"
EnableErrorChecks="1"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-Zm200 -EHsc /wd4127 /wd4512 "
Optimization="4"
AdditionalIncludeDirectories=".;..\..\include"
PreprocessorDefinitions="_WINDOWS;UNICODE;WIN32;_DEBUG,LOKI_FUNCTOR_IS_NOT_A_SMALLOBJECT"
GeneratePreprocessedFile="0"
MinimalRebuild="true"
ExceptionHandling="1"
RuntimeLibrary="3"
BufferSecurityCheck="false"
FloatingPointModel="0"
AssemblerListingLocation=""
ProgramDataBaseFileName="$(IntDir)\vc80foo.pdb"
WarningLevel="4"
SuppressStartupBanner="true"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CallingConvention="0"
DisableSpecificWarnings="4251"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath=".\classlist.h"
>
</File>
<File
RelativePath=".\foo.cpp"
>
</File>
<File
RelativePath=".\foo.h"
>
</File>
<File
RelativePath="..\..\include\loki\Register.h"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

54
test/Register/main.cpp Executable file
View file

@ -0,0 +1,54 @@
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2006 Peter Kümmel
// Permission to use, copy, modify, distribute and sell this software for any
// purpose is hereby granted without fee, provided that the above copyright
// notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation.
// The author makes no representations about the
// suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// $Header$
#include <iostream>
#include <loki/Factory.h>
#include <loki/Singleton.h>
#include "classlist.h"
typedef Loki::SingletonHolder
<
Loki::Factory<Base, std::string>
>
BaseFactory;
bool registerClass(std::string key, Base*(*creator)() )
{
return BaseFactory::Instance().Register(key,creator);
}
Loki::RegisterOnCreateSet<ClassList> registerAllClasses;
Loki::UnRegisterOnDeleteSet<ClassList> unregisterAllClasses;
int main()
{
Base* foo = BaseFactory::Instance().CreateObject("Foo");
Base* boo = BaseFactory::Instance().CreateObject("Boo");
foo->foo();
boo->foo();
delete foo;
delete boo;
#if defined(__BORLANDC__) || defined(_MSC_VER)
system("PAUSE");
#endif
return 0;
}

186
test/Register/main.vcproj Executable file
View file

@ -0,0 +1,186 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="main"
ProjectGUID="{237F4D1A-6301-4656-8F34-B0F6496E929F}"
RootNamespace="main"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-wd4996"
Optimization="0"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE _SECURE_SCL=1,LOKI_FUNCTOR_IS_NOT_A_SMALLOBJECT"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="$(OutDir)\foo.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
AdditionalLibraryDirectories="..\..\loki\lib"
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="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;LOKI_FUNCTOR_IS_NOT_A_SMALLOBJECT"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies=" foo.lib"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<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>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath="..\..\src\Singleton.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

18
test/Register/make.msvc.bat Executable file
View file

@ -0,0 +1,18 @@
:: build Foo.dll
cl -c -Zm200 -O2 -DNDEBUG -MT -EHsc -GR -W4 -wd4251 -I"." -I"..\..\include" Foo.cpp
link /lib /NOLOGO /OUT:"Foo.lib" Foo.obj
:: build main.exe
cl -c -Zm200 -O2 -DNDEBUG -MT -D_WINDLL -EHsc -GR -W4 -wd4251 -I"." -I"..\..\include" main.cpp
link /NOLOGO /SUBSYSTEM:CONSOLE /OUT:"main-msvc.exe" main.obj foo.lib ..\..\lib\loki.lib
del *.obj
del *.lib