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.

Member Typedef Documentation

◆ BmFileMap

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

Constructor & Destructor Documentation

◆ BonnMotionFileCache()

inet::BonnMotionFileCache::BonnMotionFileCache ( )
inlineprotected
52 {}

Referenced by getInstance().

◆ ~BonnMotionFileCache()

virtual inet::BonnMotionFileCache::~BonnMotionFileCache ( )
inlineprotectedvirtual
53 {}

Member Function Documentation

◆ deleteInstance()

void inet::BonnMotionFileCache::deleteInstance ( )
static

Deletes the singleton instance.

33 {
34  if (inst) {
35  delete inst;
36  inst = nullptr;
37  }
38 }

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

◆ getFile()

const BonnMotionFile * inet::BonnMotionFileCache::getFile ( const char *  filename)
virtual

Returns the given document.

41 {
42  // if found, return it from cache
43  auto it = cache.find(std::string(filename));
44  if (it != cache.end())
45  return &(it->second);
46 
47  // load and store in cache
48  BonnMotionFile& bmFile = cache[filename];
49  parseFile(filename, bmFile);
50  return &bmFile;
51 }

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

◆ getInstance()

BonnMotionFileCache * inet::BonnMotionFileCache::getInstance ( )
static

Returns the singleton instance.

26 {
27  if (!inst)
29  return inst;
30 }

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

◆ parseFile()

void inet::BonnMotionFileCache::parseFile ( const char *  filename,
BonnMotionFile bmFile 
)
protected
54 {
55  std::ifstream in(filename, std::ios::in);
56  if (in.fail())
57  throw cRuntimeError("Cannot open file '%s'", filename);
58 
59  std::string line;
60  while (std::getline(in, line)) {
61  bmFile.lines.push_back(BonnMotionFile::Line());
62  BonnMotionFile::Line& vec = bmFile.lines.back();
63 
64  std::stringstream linestream(line);
65  double d;
66  while (linestream >> d)
67  vec.push_back(d);
68  }
69  in.close();
70 }

Referenced by getFile().

Member Data Documentation

◆ cache

BmFileMap inet::BonnMotionFileCache::cache
protected

Referenced by getFile().

◆ inst

BonnMotionFileCache * inet::BonnMotionFileCache::inst
staticprotected

Referenced by deleteInstance(), and getInstance().


The documentation for this class was generated from the following files:
inet::BonnMotionFileCache::cache
BmFileMap cache
Definition: BonnMotionFileCache.h:49
inet::BonnMotionFileCache::inst
static BonnMotionFileCache * inst
Definition: BonnMotionFileCache.h:50
inet::BonnMotionFileCache::BonnMotionFileCache
BonnMotionFileCache()
Definition: BonnMotionFileCache.h:52
inet::BonnMotionFile::Line
std::vector< double > Line
Definition: BonnMotionFileCache.h:27
inet::BonnMotionFileCache::parseFile
void parseFile(const char *filename, BonnMotionFile &bmFile)
Definition: BonnMotionFileCache.cc:53