X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingRefCountObject.cxx;h=725c1cf19a17212cac7b6c5e2827276e4f4debef;hb=ac1df6b0ba8b337555fb39610c89f678d889580d;hp=03b31cec33bba85ce23ff5c7ad721d6927a7d540;hpb=242bed6361d2165733aa20dab027c4b637c732f3;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.cxx b/src/MEDCoupling/MEDCouplingRefCountObject.cxx index 03b31cec3..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,22 +21,26 @@ #include "MEDCouplingRefCountObject.hxx" #include "MEDCoupling_version.h" +#include "InterpKernelException.hxx" + #include #include -using namespace ParaMEDMEM; +using namespace MEDCoupling; + +GlobalDict *GlobalDict::UNIQUE_INSTANCE=0; -const char *ParaMEDMEM::MEDCouplingVersionStr() +const char *MEDCoupling::MEDCouplingVersionStr() { return MEDCOUPLING_VERSION_STR; } -int ParaMEDMEM::MEDCouplingVersion() +int MEDCoupling::MEDCouplingVersion() { return MEDCOUPLING_VERSION; } -void ParaMEDMEM::MEDCouplingVersionMajMinRel(int& maj, int& minor, int& releas) +void MEDCoupling::MEDCouplingVersionMajMinRel(int& maj, int& minor, int& releas) { int ver=MEDCOUPLING_VERSION; maj=(ver & 0xFF0000) >> 16; @@ -44,7 +48,7 @@ void ParaMEDMEM::MEDCouplingVersionMajMinRel(int& maj, int& minor, int& releas) releas=(ver & 0xFF); } -int ParaMEDMEM::MEDCouplingSizeOfVoidStar() +int MEDCoupling::MEDCouplingSizeOfVoidStar() { return 8*sizeof(std::size_t); } @@ -54,14 +58,14 @@ int ParaMEDMEM::MEDCouplingSizeOfVoidStar() * If false it is a BigEndian machine. * \return the coding mode of integers of the machine. */ -bool ParaMEDMEM::MEDCouplingByteOrder() +bool MEDCoupling::MEDCouplingByteOrder() { unsigned int x(1); unsigned char *xc(reinterpret_cast(&x)); return xc[0]==1; } -const char *ParaMEDMEM::MEDCouplingByteOrderStr() +const char *MEDCoupling::MEDCouplingByteOrderStr() { static const char LITTLEENDIAN_STR[]="LittleEndian"; static const char BIGENDIAN_STR[]="BigEndian"; @@ -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(); +}