-// 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
#include "MEDCouplingRefCountObject.hxx"
#include "MEDCoupling_version.h"
+#include "InterpKernelException.hxx"
+
#include <sstream>
#include <algorithm>
-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;
releas=(ver & 0xFF);
}
-int ParaMEDMEM::MEDCouplingSizeOfVoidStar()
+int MEDCoupling::MEDCouplingSizeOfVoidStar()
{
return 8*sizeof(std::size_t);
}
* 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<unsigned char *>(&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";
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<std::string, std::string>::const_iterator it(_my_map.find(key));
+ return it!=_my_map.end();
+}
+
+std::string GlobalDict::value(const std::string& key) const
+{
+ std::map<std::string, std::string>::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<std::string> GlobalDict::keys() const
+{
+ std::vector<std::string> ret;
+ for(std::map<std::string, std::string>::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<std::string, std::string>::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& value)
+{
+ std::map<std::string, std::string>::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]=value;
+}
+
+void GlobalDict::setKeyValueForce(const std::string& key, const std::string& value)
+{
+ _my_map[key]=value;
+}
+
+std::string GlobalDict::printSelf() const
+{
+ std::ostringstream oss;
+ for(std::map<std::string, std::string>::const_iterator it=_my_map.begin();it!=_my_map.end();it++)
+ {
+ oss << "(" << (*it).first << "," << (*it).second << ")" << std::endl;
+ }
+ return oss.str();
+}