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