Salome HOME
Bug with FindClosestTupleIdAlg fixed (preventing the threshold to be null)
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingRefCountObject.cxx
index 7e490003817d8b3000484fdca8db76d6dfaef668..a0c28d56134e6cd9cb0c5f33c1b2db4eddde3a77 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2020  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 "MCType.hxx"
+
+#include "InterpKernelException.hxx"
 
 #include <sstream>
 #include <algorithm>
 
 using namespace MEDCoupling;
 
+GlobalDict *GlobalDict::UNIQUE_INSTANCE=0;
+
 const char *MEDCoupling::MEDCouplingVersionStr()
 {
   return MEDCOUPLING_VERSION_STR;
@@ -49,6 +54,11 @@ int MEDCoupling::MEDCouplingSizeOfVoidStar()
   return 8*sizeof(std::size_t);
 }
 
+std::size_t MEDCoupling::MEDCouplingSizeOfIDs()
+{
+  return 8*sizeof(mcIdType);
+}
+
 /*!
  * If true is returned it is a LittleEndian machine.
  * If false it is a BigEndian machine.
@@ -71,8 +81,42 @@ const char *MEDCoupling::MEDCouplingByteOrderStr()
     return BIGENDIAN_STR;
 }
 
+bool MEDCoupling::IsCXX11Compiled()
+{
+  return true;
+}
+
 //=
 
+std::string BigMemoryObject::debugHeapMemorySize() const
+{
+  std::size_t ret(getHeapMemorySizeWithoutChildren()),sum(ret);
+  std::ostringstream oss;
+  std::vector<const BigMemoryObject *> s2(getDirectChildren());
+  std::set<const BigMemoryObject *> s1;
+  oss << "this (" << this->getClassName() << ") -> " << ret << std::endl;
+  while(!s2.empty())
+    {
+      std::vector<const BigMemoryObject *> s3;
+      for(auto it : s2)
+        {
+          if(s1.find(it)==s1.end())
+            {
+             ret = it->getHeapMemorySizeWithoutChildren(); sum+=ret;
+              oss << it->getClassName() << " -> " <<  ret << std::endl;
+              s1.insert(it);
+              std::vector<const BigMemoryObject *> v2(it->getDirectChildren());
+              for(auto it2 : v2)
+                if(s1.find(it2)==s1.end())
+                  s3.push_back(it2);
+            }
+        }
+      s2=s3;
+    }
+  oss << "sum = " << sum << std::endl;
+  return oss.str();
+}
+
 std::size_t BigMemoryObject::getHeapMemorySize() const
 {
   std::size_t ret(getHeapMemorySizeWithoutChildren());
@@ -273,3 +317,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<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& val)
+{
+  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]=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<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();
+}