Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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 BonnMotionFileCacheinstance ()
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]
 

00061 {}

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

00062 {}


Member Function Documentation

void BonnMotionFileCache::deleteInstance  )  [static]
 

Deletes the singleton instance.

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

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 }


Member Data Documentation

BMFileMap BonnMotionFileCache::cache [protected]
 

BonnMotionFileCache * BonnMotionFileCache::inst [static, protected]
 


The documentation for this class was generated from the following files:
Generated on Sat Apr 1 20:52:21 2006 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.1