Go to the documentation of this file.00001 #ifndef __CPP_UTILITIES_H__
00002 #define __CPP_UTILITIES_H__
00003
00004 #if !defined( WIN32_PLATFORM ) && !defined( NIX_PLATFORM ) && !defined( MINGW_PLATFORM ) && !defined( CYGWIN_PLATFORM )
00005 #define WIN32_PLATFORM
00006 #endif
00007
00008 #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM ) || defined( CYGWIN_PLATFORM )
00009 #define NITRO_EXPORTING __declspec( dllexport )
00010 #define NITRO_IMPORTING __declspec( dllimport )
00011 #endif
00012 #if defined( NIX_PLATFORM )
00013 #define NITRO_EXPORTING
00014 #define NITRO_IMPORTING
00015 #endif
00016
00017 #define EXTERN_C extern "C"
00018
00019 #define VIRTUAL virtual
00020
00021 #define NON_VIRTUAL
00022
00023 #define DECLARE_DESTRUCTOR( VIRTUALITY , TYPE_NAME )\
00024 VIRTUALITY ~TYPE_NAME();
00025
00026 #define DEFINE_SIMPLE_DESTRUCTOR( TYPE_NAME )\
00027 TYPE_NAME::~TYPE_NAME()\
00028 {\
00029 try\
00030 {\
00031 }\
00032 catch( ... )\
00033 {\
00034 }\
00035 }
00036
00037 #define DEFINE_RELEASING_DESTRUCTOR( TYPE_NAME , RELEASE_FUNCTION_NAME )\
00038 TYPE_NAME::~TYPE_NAME()\
00039 {\
00040 try\
00041 {\
00042 this->RELEASE_FUNCTION_NAME();\
00043 }\
00044 catch( ... )\
00045 {\
00046 }\
00047 }
00048
00049 #define DEFINE_DYNAMIC_ARRAY( TYPE_NAME , ARRAY_NAME , ARRAY_SIZE )\
00050 TYPE_NAME * ARRAY_NAME( new TYPE_NAME[ ARRAY_SIZE ] );\
00051 nitro::DynamicArrayKeeper< TYPE_NAME > ARRAY_NAME##Keeper( ARRAY_NAME );
00052
00053 #define DEFINE_DYNAMIC_OBJECT( TYPE_NAME , OBJECT_NAME )\
00054 TYPE_NAME * OBJECT_NAME( new TYPE_NAME );\
00055 nitro::DynamicObjectKeeper< TYPE_NAME > OBJECT_NAME##Keeper( OBJECT_NAME );
00056
00057 #define DECLARE_PLUGIN_BEGIN( PLUGIN_NAME )\
00058 class PLUGIN_NAME{
00059
00060 #define DECLARE_PLUGIN_METHOD_0( METHOD_NAME )\
00061 private:\
00062 void ( * FunctionPointer##METHOD_NAME )( void );\
00063 public:\
00064 void METHOD_NAME( void );
00065
00066 #define DECLARE_PLUGIN_METHOD_1( METHOD_NAME , TYPE_1_NAME )\
00067 private:\
00068 void ( * FunctionPointer##METHOD_NAME )( TYPE_1_NAME );\
00069 public:\
00070 void METHOD_NAME( TYPE_1_NAME );
00071
00072 #define DECLARE_PLUGIN_END()\
00073 };
00074
00075 #define DECLARE_PLUGIN_GATEWAY( TYPE_NAME )\
00076 EXTERN_C NITRO_EXPORTING TYPE_NAME * Get##TYPE_NAME##Instance( void )\
00077 {\
00078 return( new TYPE_NAME() );\
00079 }\
00080 EXTERN_C NITRO_EXPORTING void Release##TYPE_NAME##Instance( TYPE_NAME * Instance )\
00081 {\
00082 delete Instance;\
00083 }
00084
00085 namespace nitro
00086 {
00099 template< class type >class DynamicArrayKeeper{
00100 public:
00101
00112 DynamicArrayKeeper( type * theKeepingArray )
00113 {
00114 KeepingArray = theKeepingArray;
00115 }
00116
00127 virtual ~DynamicArrayKeeper()
00128 {
00129 delete [] KeepingArray;
00130 }
00131
00132 private:
00133
00144 type * KeepingArray;
00145 };
00146
00159 template< class type >class DynamicObjectKeeper{
00160 public:
00161
00172 DynamicObjectKeeper( type * theKeepingObject )
00173 {
00174 KeepingObject = theKeepingObject;
00175 }
00176
00187 virtual ~DynamicObjectKeeper()
00188 {
00189 delete KeepingObject;
00190 }
00191
00192 private:
00193
00204 type * KeepingObject;
00205 };
00206 };
00207
00208 #endif