AbstractTimeDependence.cpp 1.27 KB
Newer Older
kraus's avatar
kraus committed
1
#include "Algorithms/AbstractTimeDependence.h"
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include <sstream>

std::map<std::string, AbstractTimeDependence*> AbstractTimeDependence::td_map =
                              std::map<std::string, AbstractTimeDependence*>();

AbstractTimeDependence* AbstractTimeDependence::getTimeDependence(std::string name) {
    if (td_map.find(name) != td_map.end()) {
        return td_map[name];
    } else {
        throw OpalException("AbstractTimeDependence::getTimeDependence",
                            "Could not find TimeDependence called "+name);
    }
}

void AbstractTimeDependence::setTimeDependence(std::string name,
                                               AbstractTimeDependence* time_dep) {
    if (td_map.find(name) != td_map.end()) {
        delete td_map[name];
    }
    td_map[name] = time_dep;
}

std::string AbstractTimeDependence::getName(AbstractTimeDependence* time_dep) {
    typedef std::map<std::string, AbstractTimeDependence*>::iterator iter;
    for (iter i = td_map.begin(); i != td_map.end(); ++i) {
        if (i->second == time_dep)
            return i->first;
    }
    std::stringstream ss;
    ss << time_dep;
    throw OpalException("AbstractTimeDependence::getTimeDependence",
                        "Could not find TimeDependence with address "+ss.str());
}