diff options
Diffstat (limited to 'Client/ThirdParty/StaticConstructor/StaticConstructorSample')
8 files changed, 484 insertions, 0 deletions
diff --git a/Client/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp new file mode 100644 index 0000000..3ea12a3 --- /dev/null +++ b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp @@ -0,0 +1,43 @@ +// MyClass.cpp +// +#include "stdafx.h" +#include "MyClass.h" + + +// Initialization of protected static data members: +void* MyClass::mpStaticMemory = NULL; +const double MyClass::mPI = 3.141592; +std::string MyClass::mStaticStr = "Init Value"; + + +// Invoke the StaticConstructor & StaticDestructor of the class: +// Make sure you put this AFTER the initialization of the static data members! +INVOKE_STATIC_CONSTRUCTOR(MyClass); + + +// Default Constructor: +MyClass::MyClass() +{ +// PI = 5.0; // Cannot be done, as PI is const + mStaticStr = "Modified by Default Constructor"; +} + +// Destructor: +MyClass::~MyClass() +{ + mStaticStr = "Modified by Default Destructor"; +} + +// Static Constructor: +void MyClass::StaticConstructor() +{ + mStaticStr = "Modified by Static Constructor"; + mpStaticMemory = new double[10]; +} + +// Static Destructor: +void MyClass::StaticDestructor() +{ + delete[] mpStaticMemory; +} + diff --git a/Client/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h new file mode 100644 index 0000000..5f86f22 --- /dev/null +++ b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h @@ -0,0 +1,36 @@ +// MyClass.h +// +#include <string> +#include <StaticConstructor.h> + + +class MyClass +{ +protected: + // Declaration of protected static data members: + // Cannot be initialized here (C++ language limitation) + static void* mpStaticMemory; + static const double mPI; + static std::string mStaticStr; + +public: + // Static function members to get the static data members (to unify the Tests): + static const double& PI() { return mPI; }; + static std::string& StaticStr() { return mStaticStr; }; + +public: + // Default Constructor: + MyClass(); + + // Destructor: + virtual ~MyClass(); + + // Static Constructor: + // (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in the CPP file) + STATIC_CONSTRUCTOR(); + + // Static Destructor: + // (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in the CPP file) + STATIC_DESTRUCTOR(); +}; + diff --git a/Client/ThirdParty/StaticConstructor/StaticConstructorSample/MyTemplate.h b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/MyTemplate.h new file mode 100644 index 0000000..a0a147c --- /dev/null +++ b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/MyTemplate.h @@ -0,0 +1,48 @@ +// MyTemplate.h +// +#include <string> +#include <StaticConstructor.h> + + +template <typename Type> +class MyTemplate +{ +protected: + // Declaration and initialization of protected static Data-Function member: + STATIC_DF_MEMBER(Type*, pStaticMemory, NULL); + +public: + // Declaration and initialization of public static Data-Function members: + STATIC_DF_MEMBER(const double, PI, 3.141592); + STATIC_DF_MEMBER(std::string, StaticStr, "Init Value"); + +public: + // Default Constructor: + MyTemplate() + { + // PI() = 5.0; // Cannot be done, as PI is const + StaticStr() = "Modified by Default Constructor"; + } + + // Destructor: + virtual ~MyTemplate() + { + StaticStr() = "Modified by Default Destructor"; + } + + // Static Constructor: + // (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in one CPP file) + STATIC_CONSTRUCTOR() + { + StaticStr() = "Modified by Static Constructor"; + pStaticMemory() = new Type[10]; + } + + // Static Destructor: + // (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in one CPP file) + STATIC_DESTRUCTOR() + { + delete[] pStaticMemory(); + } +}; + diff --git a/Client/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.cpp b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.cpp new file mode 100644 index 0000000..26ff046 --- /dev/null +++ b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.cpp @@ -0,0 +1,76 @@ +// StaticConstructorSample.cpp : Defines the entry point for the console application. +// +#include "stdafx.h" +#include <iostream> +#include <string> + +// Sample Files: +#include "MyClass.h" +#include "MyTemplate.h" + + +// Sample code for StartUp +STATIC_STARTUP_CODE() +{ + std::cout << "Starting up..." << std::endl; +} + +// Sample code for FinishUp +STATIC_FINISHUP_CODE() +{ + std::cout << "Finishing up..." << std::endl; +} + + +// Template for testing each Type: +template <typename Type> +void TestType(const std::string& strType) +{ + using namespace std; + + // Static Constructor should have been already invoked: + cout << "Show static data members before creating any instance of " << strType << ":" << endl; + cout << "String: " << Type::StaticStr() << endl; + cout << "PI: " << Type::PI() << endl; + + // Temporary block: + // Destructor of local variable will be called at the end of this block. + { + Type myObj; + cout << "Show static data members after creating an instance of " << strType << ":" << endl; + cout << "String: " << myObj.StaticStr() << endl; + cout << "PI: " << myObj.PI() << endl; + } + + cout << "Show static data members after destroying the instance of " << strType << ":" << endl; + cout << "String: " << Type::StaticStr() << endl; + cout << "PI: " << Type::PI() << endl; + cout << endl; +} + + +// Declaration of alias (class names) for the template instaces: +typedef MyTemplate<int> MyTemplateInt; +typedef MyTemplate<double> MyTemplateDouble; + +// Invoke the StaticConstructor & StaticDestructor for each one of the template instances: +// Should be called with alias (class names) for the template instaces. +INVOKE_STATIC_CONSTRUCTOR(MyTemplateInt); +INVOKE_STATIC_CONSTRUCTOR(MyTemplateDouble); + + +// Main: +int _tmain(int argc, _TCHAR* argv[]) +{ + // Static Constructors have already been called before entering this function... + + // Run the same tests for each one of the classes: + TestType<MyClass>("MyClass"); + TestType<MyTemplateInt>("MyTemplateInt"); + TestType<MyTemplateDouble>("MyTemplateDouble"); + + // Static Destructors will be called after exiting this function... + return 0; +} + + diff --git a/Client/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.sln b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.sln new file mode 100644 index 0000000..265f06c --- /dev/null +++ b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StaticConstructorSample", "StaticConstructorSample.vcproj", "{41329043-C008-486E-99A9-BC1A0B4DF9A5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {41329043-C008-486E-99A9-BC1A0B4DF9A5}.Debug|Win32.ActiveCfg = Debug|Win32 + {41329043-C008-486E-99A9-BC1A0B4DF9A5}.Debug|Win32.Build.0 = Debug|Win32 + {41329043-C008-486E-99A9-BC1A0B4DF9A5}.Release|Win32.ActiveCfg = Release|Win32 + {41329043-C008-486E-99A9-BC1A0B4DF9A5}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Client/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.vcproj b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.vcproj new file mode 100644 index 0000000..0f66ceb --- /dev/null +++ b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.vcproj @@ -0,0 +1,229 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="9,00" + Name="StaticConstructorSample" + ProjectGUID="{41329043-C008-486E-99A9-BC1A0B4DF9A5}" + RootNamespace="StaticConstructorSample" + Keyword="Win32Proj" + TargetFrameworkVersion="196613" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="..\include" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="2" + WarningLevel="3" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + EnableIntrinsicFunctions="true" + AdditionalIncludeDirectories="..\include" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="2" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + 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="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="include" + > + <File + RelativePath="..\include\StaticConstructor.h" + > + </File> + </Filter> + <Filter + Name="Sample Files" + > + <File + RelativePath=".\MyClass.cpp" + > + </File> + <File + RelativePath=".\MyClass.h" + > + </File> + <File + RelativePath=".\MyTemplate.h" + > + </File> + </Filter> + <Filter + Name="Project Files" + > + <File + RelativePath=".\StaticConstructorSample.cpp" + > + </File> + <File + RelativePath=".\stdafx.cpp" + > + <FileConfiguration + Name="Debug|Win32" + > + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="1" + /> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="1" + /> + </FileConfiguration> + </File> + <File + RelativePath=".\stdafx.h" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/Client/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.cpp b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.cpp new file mode 100644 index 0000000..88d97ab --- /dev/null +++ b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// StaticConstructorSample.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/Client/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.h b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.h new file mode 100644 index 0000000..022bc3b --- /dev/null +++ b/Client/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.h @@ -0,0 +1,24 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +// STL includes +#include <stdio.h> +#include <tchar.h> + + +// TODO: reference additional headers your program requires here |