INET Framework for OMNeT++/OMNEST
inet::BonnMotionFileCache Class Reference

Singleton object to read and store BonnMotion files. More...

#include <BonnMotionFileCache.h>

Public Member Functions

virtual const BonnMotionFilegetFile (const char *filename)
 Returns the given document. More...
 

Static Public Member Functions

static BonnMotionFileCachegetInstance ()
 Returns the singleton instance. More...
 
static void deleteInstance ()
 Deletes the singleton instance. More...
 

Protected Types

typedef std::map< std::string, BonnMotionFileBMFileMap
 

Protected Member Functions

void parseFile (const char *filename, BonnMotionFile &bmFile)
 
 BonnMotionFileCache ()
 
virtual ~BonnMotionFileCache ()
 

Protected Attributes

BMFileMap cache
 

Static Protected Attributes

static BonnMotionFileCacheinst
 

Detailed Description

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.

Author
Andras Varga

Member Typedef Documentation

typedef std::map<std::string, BonnMotionFile> inet::BonnMotionFileCache::BMFileMap
protected

Constructor & Destructor Documentation

inet::BonnMotionFileCache::BonnMotionFileCache ( )
inlineprotected
63 {}
virtual inet::BonnMotionFileCache::~BonnMotionFileCache ( )
inlineprotectedvirtual
64 {}

Member Function Documentation

void inet::BonnMotionFileCache::deleteInstance ( )
static

Deletes the singleton instance.

Referenced by inet::BonnMotionMobility::~BonnMotionMobility().

43 {
44  if (inst) {
45  delete inst;
46  inst = nullptr;
47  }
48 }
static BonnMotionFileCache * inst
Definition: BonnMotionFileCache.h:61
const BonnMotionFile * inet::BonnMotionFileCache::getFile ( const char *  filename)
virtual

Returns the given document.

Referenced by inet::BonnMotionMobility::initialize().

51 {
52  // if found, return it from cache
53  auto it = cache.find(std::string(filename));
54  if (it != cache.end())
55  return &(it->second);
56 
57  // load and store in cache
58  BonnMotionFile& bmFile = cache[filename];
59  parseFile(filename, bmFile);
60  return &bmFile;
61 }
void parseFile(const char *filename, BonnMotionFile &bmFile)
Definition: BonnMotionFileCache.cc:63
BMFileMap cache
Definition: BonnMotionFileCache.h:60
BonnMotionFileCache * inet::BonnMotionFileCache::getInstance ( )
static

Returns the singleton instance.

Referenced by inet::BonnMotionMobility::initialize().

36 {
37  if (!inst)
39  return inst;
40 }
static BonnMotionFileCache * inst
Definition: BonnMotionFileCache.h:61
BonnMotionFileCache()
Definition: BonnMotionFileCache.h:63
void inet::BonnMotionFileCache::parseFile ( const char *  filename,
BonnMotionFile bmFile 
)
protected
64 {
65  std::ifstream in(filename, std::ios::in);
66  if (in.fail())
67  throw cRuntimeError("Cannot open file '%s'", filename);
68 
69  std::string line;
70  while (std::getline(in, line)) {
71  bmFile.lines.push_back(BonnMotionFile::Line());
72  BonnMotionFile::Line& vec = bmFile.lines.back();
73 
74  std::stringstream linestream(line);
75  double d;
76  while (linestream >> d)
77  vec.push_back(d);
78  }
79  in.close();
80 }
std::vector< double > Line
Definition: BonnMotionFileCache.h:37

Member Data Documentation

BMFileMap inet::BonnMotionFileCache::cache
protected
BonnMotionFileCache * inet::BonnMotionFileCache::inst
staticprotected

The documentation for this class was generated from the following files: