BonnMotionFileCache Class Reference

#include <BonnMotionFileCache.h>

List of all members.


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

Public Member Functions

virtual const BonnMotionFilegetFile (const char *filename)

Static Public Member Functions

static BonnMotionFileCachegetInstance ()
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 BonnMotionFileCacheinst

Member Typedef Documentation

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


Constructor & Destructor Documentation

BonnMotionFileCache::BonnMotionFileCache (  )  [inline, protected]

00060 {}

virtual BonnMotionFileCache::~BonnMotionFileCache (  )  [inline, protected, virtual]

00061 {}


Member Function Documentation

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]

Deletes the singleton instance.

Referenced by BonnMotionMobility::~BonnMotionMobility().

00041 {
00042     if (inst) 
00043     {
00044         delete inst;
00045         inst = NULL;
00046     }
00047 }

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 }


Member Data Documentation

Referenced by getFile().

Referenced by deleteInstance(), and getInstance().


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

Generated on Fri Mar 20 18:51:18 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5