|
INET Framework for OMNeT++/OMNEST
|
#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 |
Singleton object to read and store BonnMotion files. Used within BonnMotionMobility. Needed because otherwise every node would have to open and read the file independently.
typedef std::map<std::string,BonnMotionFile> BonnMotionFileCache::BMFileMap [protected] |
| BonnMotionFileCache::BonnMotionFileCache | ( | ) | [inline, protected] |
Referenced by getInstance().
{}
| virtual BonnMotionFileCache::~BonnMotionFileCache | ( | ) | [inline, protected, virtual] |
{}
| void BonnMotionFileCache::deleteInstance | ( | ) | [static] |
Deletes the singleton instance.
Referenced by BonnMotionMobility::~BonnMotionMobility().
| const BonnMotionFile * BonnMotionFileCache::getFile | ( | const char * | filename | ) | [virtual] |
Returns the given document.
Referenced by BonnMotionMobility::initialize().
{
// if found, return it from cache
BMFileMap::iterator it = cache.find(std::string(filename));
if (it!=cache.end())
return &(it->second);
// load and store in cache
BonnMotionFile& bmFile = cache[filename];
parseFile(filename, bmFile);
return &bmFile;
}
| BonnMotionFileCache * BonnMotionFileCache::getInstance | ( | ) | [static] |
Returns the singleton instance.
Referenced by BonnMotionMobility::initialize().
{
if (!inst)
inst = new BonnMotionFileCache;
return inst;
}
| void BonnMotionFileCache::parseFile | ( | const char * | filename, |
| BonnMotionFile & | bmFile | ||
| ) | [protected] |
Referenced by getFile().
{
std::ifstream in(filename, std::ios::in);
if (in.fail())
opp_error("Cannot open file '%s'",filename);
std::string line;
while (std::getline(in, line))
{
bmFile.lines.push_back(BonnMotionFile::Line());
BonnMotionFile::Line& vec = bmFile.lines.back();
std::stringstream linestream(line);
double d;
while (linestream >> d)
vec.push_back(d);
}
in.close();
}
BMFileMap BonnMotionFileCache::cache [protected] |
Referenced by getFile().
BonnMotionFileCache * BonnMotionFileCache::inst [static, protected] |
Referenced by deleteInstance(), and getInstance().