AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzUtil.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if !defined(_CCZ_UTIL_H_)
00015 #define _CCZ_UTIL_H_
00016 
00017 #include "CzTypes.h"
00018 #include "CzDebug.h"
00019 
00020 class CzApp;
00021 
00022 /**
00023  @addtogroup Core
00024  @{
00025  */
00026  
00027 #ifndef NULL
00028     #define NULL 0
00029 #endif
00030 
00031 /**
00032  @def   SAFE_DELETE(x) if (x != NULL)
00033 
00034  @brief A macro that safely deletes an object.
00035 
00036  @param x   the object to delete.
00037  */
00038 
00039 #define SAFE_DELETE(x) if (x != NULL) { delete x; x = NULL; }
00040 
00041 /**
00042  @def   SAFE_DELETE_ARRAY(x) if (x != NULL)
00043 
00044  @brief A macro that safely deletes an array of objects.
00045 
00046  @param x   The rray of objects to delete.
00047  */
00048 
00049 #define SAFE_DELETE_ARRAY(x) if (x != NULL) { delete [] x; x = NULL; }
00050 
00051 /**
00052  @def   CZ_HASH(x) (CzString::CalculateHash(x));
00053 
00054  @brief A macro that calculates the hash of a string.
00055 
00056  @param x   The string.
00057  */
00058 
00059 #define CZ_HASH(x)              (CzString::CalculateHash(x))
00060 
00061 /**
00062  @def   FRAME_SPEED_LOCK_MS();
00063 
00064  @brief A macro that defines the frame speed lock in milliseconds.
00065 
00066  This value is calculates from 1000 / target_frame-rate 
00067 
00068  */
00069 
00070 #define FRAME_SPEED_LOCK_MS     16.67f
00071 
00072 //
00073 //
00074 // SINGLETONS
00075 //
00076 //
00077 //
00078 // Define a class as a singleton (Add to class definition in header file)
00079 //
00080 #define CDEFINE_SINGLETON(the_class)                \
00081 private:                                        \
00082     static the_class* _instance;                \
00083     the_class() {}                              \
00084     ~the_class() {}                             \
00085     the_class(const the_class &);               \
00086     the_class& operator=(const the_class &);    \
00087 public:                                         \
00088     static void Create();                       \
00089     static void Destroy();                      \
00090     static the_class* getInstance();
00091 
00092 //
00093 // Declare singleton methods (Add to source file)
00094 //
00095 #define CDECLARE_SINGLETON(the_class)       \
00096 the_class* the_class::_instance = NULL;     \
00097 void the_class::Create()                    \
00098 {                                           \
00099     if (_instance == NULL)                  \
00100         _instance = new the_class;          \
00101 }                                           \
00102 void the_class::Destroy()                   \
00103 {                                           \
00104     if (_instance != NULL)                  \
00105     {                                       \
00106         delete _instance;                   \
00107         _instance = NULL;                   \
00108     }                                       \
00109 }                                           \
00110 the_class* the_class::getInstance()         \
00111 {                                           \
00112   return _instance;                         \
00113 }
00114 
00115 
00116 //
00117 //
00118 //
00119 //
00120 // CzCallback - Game callback type
00121 //
00122 //
00123 //
00124 //
00125 typedef int (*CzCallback)(void* caller, void* data);
00126 typedef void* CzCallbackData;
00127 
00128 /**
00129  @class CzUtils
00130 
00131  @brief CzUtils - Pure static utility class.
00132 
00133  */
00134 
00135 class CzUtils
00136 {
00137 public:
00138 
00139 public:
00140     static const char*  GetGraphicModeName(int width, int height);
00141     static int          GetGraphicModeIndex(int width, int height);
00142     static int          CountDigits(int number);
00143 
00144 
00145 };
00146 
00147 /**
00148  @class CzMetrics
00149 
00150  @brief CzMetrics - Metrics class.
00151 
00152  Used to gather certain metrics
00153 
00154  */
00155 
00156 class CzMetrics
00157 {
00158 public:
00159     static int      TotalSpritesProcessed;          ///< Total sprites that were processed
00160     static int      TotalSpritesCreated;            ///< Total sprites that were created
00161     static int      TotalSpritesDestroyed;          ///< Total sprites that were destroyed
00162     static int      TotalActorsProcessed;           ///< Total actors that were processed
00163     static int      TotalActorsCreated;             ///< Total actors that were created
00164     static int      TotalActorsDestroyed;           ///< Total actors that were destroyed
00165 
00166 };
00167 
00168 /**
00169  @class CzGlobals
00170 
00171  @brief CzGlobals - Global data.
00172 
00173  */
00174 
00175 class CzGlobals
00176 {
00177 public:
00178     static CzApp*       App;        ///< The app
00179 };
00180 
00181 //#define CZ_ENABLE_METRICS
00182 
00183 /// @}
00184 
00185 #endif  // _CCZ_UTIL_H_