00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef WM4SYSTEM_H
00018 #define WM4SYSTEM_H
00019
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4Platforms.h"
00022
00023
00024 #include <cassert>
00025 #include <cctype>
00026 #include <cfloat>
00027 #include <cmath>
00028 #include <cstdarg>
00029 #include <cstddef>
00030 #include <cstdio>
00031 #include <cstdlib>
00032 #include <cstring>
00033 #include <ctime>
00034 #include <iostream>
00035 #include <fstream>
00036
00037
00038 #include <algorithm>
00039 #include <exception>
00040 #include <list>
00041 #include <map>
00042 #include <queue>
00043 #include <set>
00044 #include <stack>
00045 #include <string>
00046 #include <utility>
00047 #include <vector>
00048
00049
00050 #include "Wm4Memory.h"
00051
00052 namespace Wm4
00053 {
00054
00055 class WM4_FOUNDATION_ITEM System
00056 {
00057 public:
00058
00059 static void SwapBytes (int iSize, void* pvValue);
00060 static void SwapBytes (int iSize, int iQuantity, void* pvValue);
00061
00062
00063 static bool IsBigEndian ();
00064 static void EndianCopy (int iSize, const void* pvSrc, void* pvDst);
00065 static void EndianCopy (int iSize, int iQuantity, const void* pvSrc,
00066 void* pvDst);
00067
00068
00069 static double GetTime ();
00070
00071
00072 static bool Load (const char* acFilename, char*& racBuffer, int& riSize);
00073 static bool Save (const char* acFilename, const char* acBuffer,
00074 int iSize);
00075 static bool Append (const char* acFilename, char* acBuffer, int iSize);
00076
00077
00078
00079 static int Read1 (const char* acBuffer, int iQuantity, void* pvData);
00080 static int Write1 (char* acBuffer, int iQuantity, const void* pvData);
00081 static int Read1 (FILE* pkFile, int iQuantity, void* pvData);
00082 static int Write1 (FILE* pkFile, int iQuantity, const void* pvData);
00083
00084
00085
00086
00087
00088 static int Read2le (const char* acBuffer, int iQuantity, void* pvData);
00089 static int Read4le (const char* acBuffer, int iQuantity, void* pvData);
00090 static int Read8le (const char* acBuffer, int iQuantity, void* pvData);
00091 static int Write2le (char* acBuffer, int iQuantity, const void* pvData);
00092 static int Write4le (char* acBuffer, int iQuantity, const void* pvData);
00093 static int Write8le (char* acBuffer, int iQuantity, const void* pvData);
00094 static int Read2le (FILE* pkFile, int iQuantity, void* pvData);
00095 static int Read4le (FILE* pkFile, int iQuantity, void* pvData);
00096 static int Read8le (FILE* pkFile, int iQuantity, void* pvData);
00097 static int Write2le (FILE* pkFile, int iQuantity, const void* pvData);
00098 static int Write4le (FILE* pkFile, int iQuantity, const void* pvData);
00099 static int Write8le (FILE* pkFile, int iQuantity, const void* pvData);
00100
00101
00102
00103
00104
00105 static int Read2be (const char* acBuffer, int iQuantity, void* pvData);
00106 static int Read4be (const char* acBuffer, int iQuantity, void* pvData);
00107 static int Read8be (const char* acBuffer, int iQuantity, void* pvData);
00108 static int Write2be (char* acBuffer, int iQuantity, const void* pvData);
00109 static int Write4be (char* acBuffer, int iQuantity, const void* pvData);
00110 static int Write8be (char* acBuffer, int iQuantity, const void* pvData);
00111 static int Read2be (FILE* pkFile, int iQuantity, void* pvData);
00112 static int Read4be (FILE* pkFile, int iQuantity, void* pvData);
00113 static int Read8be (FILE* pkFile, int iQuantity, void* pvData);
00114 static int Write2be (FILE* pkFile, int iQuantity, const void* pvData);
00115 static int Write4be (FILE* pkFile, int iQuantity, const void* pvData);
00116 static int Write8be (FILE* pkFile, int iQuantity, const void* pvData);
00117
00118
00119
00120
00121
00122
00123
00124 static const char* GetPath (const char* acDirectory,
00125 const char* acFilename);
00126
00127
00128
00129
00130
00131
00132
00133 static void Initialize ();
00134 static void Terminate ();
00135 static int GetDirectoryQuantity ();
00136 static const char* GetDirectory (int i);
00137 static bool InsertDirectory (const char* acDirectory);
00138 static bool RemoveDirectory (const char* acDirectory);
00139 static void RemoveAllDirectories ();
00140
00141
00142
00143
00144
00145 enum
00146 {
00147 SM_READ,
00148 SM_WRITE,
00149 SM_READ_WRITE
00150 };
00151 static const char* GetPath (const char* acFilename, int eMode);
00152
00153
00154 static unsigned int MakeRGB (unsigned char ucR, unsigned char ucG,
00155 unsigned char ucB);
00156 static unsigned int MakeRGBA (unsigned char ucR, unsigned char ucG,
00157 unsigned char ucB, unsigned char ucA);
00158
00159
00160
00161
00162
00163
00164 static FILE* Fopen (const char* acFilename, const char* acMode);
00165 static int Fprintf (FILE* pkFile, const char* acFormat, ...);
00166 static int Fclose (FILE* pkFile);
00167 static const char* GetEnv (const char* acEnvVarName);
00168 static void* Memcpy (void* pvDst, size_t uiDstSize, const void* pvSrc,
00169 size_t uiSrcSize);
00170 static int Sprintf (char* acDst, size_t uiDstSize, const char* acFormat,
00171 ...);
00172 static char* Strcpy (char* acDst, size_t uiDstSize, const char* acSrc);
00173 static char* Strcat (char* acDst, size_t uiDstSize, const char* acSrc);
00174 static char* Strncpy (char* acDst, size_t uiDstSize, const char* acSrc,
00175 size_t uiSrcSize);
00176 static char* Strtok (char* acToken, const char* acDelimiters,
00177 char*& racNextToken);
00178
00179 private:
00180 enum { SYSTEM_MAX_PATH = 1024, SYSTEM_MAX_ENVVAR = 1024 };
00181 static char ms_acPath[SYSTEM_MAX_PATH];
00182 static char ms_acEnvVar[SYSTEM_MAX_ENVVAR];
00183 static std::vector<std::string>* ms_pkDirectories;
00184
00185 public:
00186 static char WM4_PATH[SYSTEM_MAX_ENVVAR];
00187 };
00188
00189
00190
00191 template <class T> void Allocate (int iCols, int iRows, T**& raatArray);
00192 template <class T> static void Deallocate (T**& raatArray);
00193
00194
00195
00196 template <class T> void Allocate (int iCols, int iRows, int iSlices,
00197 T***& raaatArray);
00198 template <class T> void Deallocate (T***& raaatArray);
00199
00200 }
00201
00202 #include "Wm4System.inl"
00203
00204
00205
00206
00207 #include "Wm4THashSet.h"
00208 #include "Wm4THashTable.h"
00209 #include "Wm4TMinHeap.h"
00210 #include "Wm4TStringHashTable.h"
00211 #include "Wm4TSmallUnorderedSet.h"
00212 #include "Wm4TTuple.h"
00213
00214 #endif