X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingRefCountObject.cxx;h=725c1cf19a17212cac7b6c5e2827276e4f4debef;hb=ac1df6b0ba8b337555fb39610c89f678d889580d;hp=7e490003817d8b3000484fdca8db76d6dfaef668;hpb=1e36a6710aab710674e20fbd89f6a9a8f238c023;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.cxx b/src/MEDCoupling/MEDCouplingRefCountObject.cxx index 7e4900038..725c1cf19 100644 --- a/src/MEDCoupling/MEDCouplingRefCountObject.cxx +++ b/src/MEDCoupling/MEDCouplingRefCountObject.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -21,11 +21,15 @@ #include "MEDCouplingRefCountObject.hxx" #include "MEDCoupling_version.h" +#include "InterpKernelException.hxx" + #include #include using namespace MEDCoupling; +GlobalDict *GlobalDict::UNIQUE_INSTANCE=0; + const char *MEDCoupling::MEDCouplingVersionStr() { return MEDCOUPLING_VERSION_STR; @@ -273,3 +277,82 @@ RefCountObject::RefCountObject(const RefCountObject& other):RefCountObjectOnly(o RefCountObject::~RefCountObject() { } + +//= + +GlobalDict *GlobalDict::GetInstance() +{ + if(!UNIQUE_INSTANCE) + UNIQUE_INSTANCE=new GlobalDict; + return UNIQUE_INSTANCE; +} + +bool GlobalDict::hasKey(const std::string& key) const +{ + std::map::const_iterator it(_my_map.find(key)); + return it!=_my_map.end(); +} + +std::string GlobalDict::value(const std::string& key) const +{ + std::map::const_iterator it(_my_map.find(key)); + if(it==_my_map.end()) + { + std::ostringstream oss; + oss << "GlobalDict::value : key \"" << key << "\" is not in map !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return (*it).second; +} + +std::vector GlobalDict::keys() const +{ + std::vector ret; + for(std::map::const_iterator it=_my_map.begin();it!=_my_map.end();it++) + ret.push_back((*it).first); + return ret; +} + +void GlobalDict::erase(const std::string& key) +{ + std::map::iterator it(_my_map.find(key)); + if(it==_my_map.end()) + { + std::ostringstream oss; + oss << "GlobalDict::erase : key \"" << key << "\" is not in map !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + _my_map.erase(it); +} + +void GlobalDict::clear() +{ + _my_map.clear(); +} + +void GlobalDict::setKeyValue(const std::string& key, const std::string& val) +{ + std::map::const_iterator it(_my_map.find(key)); + if(it!=_my_map.end()) + { + std::ostringstream oss; + oss << "GlobalDict::setKeyValue : key \"" << key << "\" already exists !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + _my_map[key]=val; +} + +void GlobalDict::setKeyValueForce(const std::string& key, const std::string& val) +{ + _my_map[key]=val; +} + +std::string GlobalDict::printSelf() const +{ + std::ostringstream oss; + for(std::map::const_iterator it=_my_map.begin();it!=_my_map.end();it++) + { + oss << "(" << (*it).first << "," << (*it).second << ")" << std::endl; + } + return oss.str(); +}