#include <BonnMotionFileCache.h>
Public Member Functions | |
virtual const BonnMotionFile * | getFile (const char *filename) |
Static Public Member Functions | |
static BonnMotionFileCache * | getInstance () |
static void | deleteInstance () |
Protected Types | |
typedef std::map< std::string, BonnMotionFile > | BMFileMap |
Protected Member Functions | |
void | parseFile (const char *filename, BonnMotionFile &bmFile) |
BonnMotionFileCache () | |
virtual | ~BonnMotionFileCache () |
Protected Attributes | |
BMFileMap | cache |
Static Protected Attributes | |
static BonnMotionFileCache * | inst |
typedef std::map<std::string,BonnMotionFile> BonnMotionFileCache::BMFileMap [protected] |
void BonnMotionFileCache::parseFile | ( | const char * | filename, | |
BonnMotionFile & | bmFile | |||
) | [protected] |
Referenced by getFile().
00063 { 00064 std::ifstream in(filename, std::ios::in); 00065 if (in.fail()) 00066 opp_error("Cannot open file '%s'",filename); 00067 00068 std::string line; 00069 while (std::getline(in, line)) 00070 { 00071 bmFile.lines.push_back(BonnMotionFile::Line()); 00072 BonnMotionFile::Line& vec = bmFile.lines.back(); 00073 00074 std::stringstream linestream(line); 00075 double d; 00076 while (linestream >> d) 00077 vec.push_back(d); 00078 } 00079 in.close(); 00080 }
BonnMotionFileCache * BonnMotionFileCache::getInstance | ( | ) | [static] |
Returns the singleton instance.
Referenced by BonnMotionMobility::initialize().
00034 { 00035 if (!inst) 00036 inst = new BonnMotionFileCache; 00037 return inst; 00038 }
void BonnMotionFileCache::deleteInstance | ( | ) | [static] |
const BonnMotionFile * BonnMotionFileCache::getFile | ( | const char * | filename | ) | [virtual] |
Returns the given document.
Referenced by BonnMotionMobility::initialize().
00050 { 00051 // if found, return it from cache 00052 BMFileMap::iterator it = cache.find(std::string(filename)); 00053 if (it!=cache.end()) 00054 return &(it->second); 00055 00056 // load and store in cache 00057 BonnMotionFile& bmFile = cache[filename]; 00058 parseFile(filename, bmFile); 00059 return &bmFile; 00060 }
BMFileMap BonnMotionFileCache::cache [protected] |
Referenced by getFile().
BonnMotionFileCache * BonnMotionFileCache::inst [static, protected] |
Referenced by deleteInstance(), and getInstance().