#include "MEDCouplingRefCountObject.hxx"
#include "MEDCoupling_version.h"
+#include "InterpKernelException.hxx"
+
#include <sstream>
#include <algorithm>
using namespace MEDCoupling;
+GlobalDict *GlobalDict::UNIQUE_INSTANCE=0;
+
const char *MEDCoupling::MEDCouplingVersionStr()
{
return MEDCOUPLING_VERSION_STR;
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();
+}
#include "MEDCoupling.hxx"
#include <set>
+#include <map>
#include <vector>
#include <string>
#include <cstddef>
MEDCOUPLING_EXPORT RefCountObject(const RefCountObject& other);
MEDCOUPLING_EXPORT virtual ~RefCountObject();
};
+
+ class GlobalDict
+ {
+ public:
+ MEDCOUPLING_EXPORT static GlobalDict *GetInstance();
+ MEDCOUPLING_EXPORT bool hasKey(const std::string& key) const;
+ MEDCOUPLING_EXPORT std::string value(const std::string& key) const;
+ MEDCOUPLING_EXPORT std::vector<std::string> keys() const;
+ MEDCOUPLING_EXPORT void erase(const std::string& key);
+ MEDCOUPLING_EXPORT void clear();
+ MEDCOUPLING_EXPORT void setKeyValue(const std::string& key, const std::string& value);
+ MEDCOUPLING_EXPORT void setKeyValueForce(const std::string& key, const std::string& value);
+ MEDCOUPLING_EXPORT std::string printSelf() const;
+ private:
+ GlobalDict() { }
+ private:
+ static GlobalDict *UNIQUE_INSTANCE;
+ private:
+ std::map<std::string, std::string> _my_map;
+ };
}
#endif
protected:
~RefCountObject();
};
+
+ class GlobalDict
+ {
+ public:
+ static GlobalDict *GetInstance() throw(INTERP_KERNEL::Exception);
+ bool hasKey(const std::string& key) const throw(INTERP_KERNEL::Exception);
+ std::string value(const std::string& key) const throw(INTERP_KERNEL::Exception);
+ std::vector<std::string> keys() const throw(INTERP_KERNEL::Exception);
+ void erase(const std::string& key) throw(INTERP_KERNEL::Exception);
+ void clear() throw(INTERP_KERNEL::Exception);
+ void setKeyValue(const std::string& key, const std::string& value) throw(INTERP_KERNEL::Exception);
+ void setKeyValueForce(const std::string& key, const std::string& value) throw(INTERP_KERNEL::Exception);
+ private:
+ GlobalDict();
+ public:
+ %extend
+ {
+ std::string __str__() const
+ {
+ return self->printSelf();
+ }
+ }
+ };
}
%inline