INET Framework for OMNeT++/OMNEST
BonnMotionFileCache Class Reference

#include <BonnMotionFileCache.h>

List of all members.

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

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

Definition at line 53 of file BonnMotionFileCache.h.


Member Typedef Documentation

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

Definition at line 56 of file BonnMotionFileCache.h.


Constructor & Destructor Documentation

Definition at line 60 of file BonnMotionFileCache.h.

Referenced by getInstance().

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

Definition at line 61 of file BonnMotionFileCache.h.

{}

Member Function Documentation

Deletes the singleton instance.

Definition at line 40 of file BonnMotionFileCache.cc.

Referenced by BonnMotionMobility::~BonnMotionMobility().

{
    if (inst)
    {
        delete inst;
        inst = NULL;
    }
}
const BonnMotionFile * BonnMotionFileCache::getFile ( const char *  filename) [virtual]

Returns the given document.

Definition at line 49 of file BonnMotionFileCache.cc.

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;
}

Returns the singleton instance.

Definition at line 33 of file BonnMotionFileCache.cc.

Referenced by BonnMotionMobility::initialize().

{
    if (!inst)
        inst = new BonnMotionFileCache;
    return inst;
}
void BonnMotionFileCache::parseFile ( const char *  filename,
BonnMotionFile bmFile 
) [protected]

Definition at line 62 of file BonnMotionFileCache.cc.

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();
}

Member Data Documentation

Definition at line 57 of file BonnMotionFileCache.h.

Referenced by getFile().

Definition at line 58 of file BonnMotionFileCache.h.

Referenced by deleteInstance(), and getInstance().


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