#ifndef _UTILS_H_ #define _UTILS_H_ #include #if defined (PSP) #include #include #include #include #include #include #include #include #include #include #endif #include #include #include #include #include #include #include #if defined( WIN32 ) || defined (LINUX) // enable this define to collect statistics on how many times an ifstream is created for a given file. //#define TRACK_FILE_USAGE_STATS #endif namespace wagic { #ifdef TRACK_FILE_USAGE_STATS class ifstream : public std::ifstream { public: explicit ifstream(const char *inFilename, ios_base::openmode inMode = ios_base::in) : std::ifstream(inFilename, inMode) { sFileMap[std::string(inFilename)] += 1; } static void Dump() { DebugTrace("-------------------"); DebugTrace("File Usage Statistics" << std::endl); std::map::const_iterator iter = sFileMap.begin(); for (; iter != sFileMap.end(); ++iter) { DebugTrace(iter->first << " -- " << iter->second); } DebugTrace("End File Usage Statistics"); DebugTrace("-------------------"); } private: static std::map sFileMap; }; #else typedef std::ifstream ifstream; #endif } //namespace wagic using std::string; //string manipulation methods string& trim(string& str); string& ltrim(string& str); string& rtrim(string& str); inline string trim(const string& str) { string value(str); return trim(value); } std::string join(vector& v, string delim = " "); std::vector& split(const std::string& s, char delim, std::vector& elems); std::vector split(const std::string& s, char delim); //splits a string with "delim" and returns a vector of strings. std::string wordWrap(const std::string& s, float width, int fontId); int loadRandValues(string s); int filesize(const char * filename); int fileExists(const char * filename); int WRand(); #ifdef LINUX void dumpStack(); #endif /* RAM simple check functions header */ // *** DEFINES *** #if defined (WIN32) || defined (LINUX) || defined (IOS) #define RAM_BLOCK (100 * 1024 * 1024) #else #define RAM_BLOCK (1024 * 1024) #endif // *** FUNCTIONS DECLARATIONS *** u32 ramAvailableLineareMax(void); u32 ramAvailable(void); #ifdef WIN32 #include #define MAKEDIR(name) mkdir(name) #else #include #define MAKEDIR(name) mkdir(name, 0777) #endif bool FileExists(const string& strFilename); #endif