Salome HOME
Addition of new reference coords including degenerated cells.
[modules/med.git] / src / MEDCoupling / MEDCouplingRefCountObject.cxx
index 49d954f8e217cd25a4692976e8409cdd75b27bd0..e2b93ea4ec628d6d9f284297bf535d9d6c69b8c4 100644 (file)
@@ -22,7 +22,6 @@
 #include "MED_version.h"
 
 #include <sstream>
-#include <set>
 
 using namespace ParaMEDMEM;
 
@@ -71,39 +70,48 @@ const char *ParaMEDMEM::MEDCouplingByteOrderStr()
     return BIGENDIAN_STR;
 }
 
-RefCountObject::RefCountObject():_cnt(1)
-{
-}
+//=
 
-RefCountObject::RefCountObject(const RefCountObject& other):_cnt(1)
+std::size_t BigMemoryObject::getHeapMemorySize() const
 {
+  std::size_t ret(getHeapMemorySizeWithoutChildren());
+  std::vector<const BigMemoryObject *> v(getDirectChildren());
+  std::set<const BigMemoryObject *> s1,s2(v.begin(),v.end());
+  return ret+GetHeapMemoryOfSet(s1,s2);
 }
 
-/*!
- * Do nothing here ! It is not a bug ( I hope :) ) because all subclasses that
- * copies using operator= should not copy the ref counter of \a other !
- */
-RefCountObject& RefCountObject::operator=(const RefCountObject& other)
+std::size_t BigMemoryObject::GetHeapMemorySizeOfObjs(const std::vector<const BigMemoryObject *>& objs)
 {
-  return *this;
+  std::size_t ret(0);
+  std::set<const BigMemoryObject *> s1,s2;
+  for(std::vector<const BigMemoryObject *>::const_iterator it0=objs.begin();it0!=objs.end();it0++)
+    {
+      if(*it0)
+        if(s1.find(*it0)==s1.end())
+          {
+            std::vector<const BigMemoryObject *> vTmp((*it0)->getDirectChildren());
+            s2.insert(vTmp.begin(),vTmp.end());
+            ret+=(*it0)->getHeapMemorySizeWithoutChildren();
+            s1.insert(*it0);
+          }
+    }
+  return ret+GetHeapMemoryOfSet(s1,s2);
 }
 
-std::size_t RefCountObject::getHeapMemorySize() const
+std::size_t BigMemoryObject::GetHeapMemoryOfSet(std::set<const BigMemoryObject *>& s1, std::set<const BigMemoryObject *>& s2)
 {
-  std::size_t ret(getHeapMemorySizeWithoutChildren());
-  std::vector<RefCountObject *> v(getDirectChildren());
-  std::set<RefCountObject *> s1,s2(v.begin(),v.end());
+  std::size_t ret(0);
   while(!s2.empty())
     {
-      std::set<RefCountObject *> s3;
-      for(std::set<RefCountObject *>::const_iterator it=s2.begin();it!=s2.end();it++)
+      std::set<const BigMemoryObject *> s3;
+      for(std::set<const BigMemoryObject *>::const_iterator it=s2.begin();it!=s2.end();it++)
         {
           if(s1.find(*it)==s1.end())
             {
               ret+=(*it)->getHeapMemorySizeWithoutChildren();
               s1.insert(*it);
-              std::vector<RefCountObject *> v2((*it)->getDirectChildren());
-              for(std::vector<RefCountObject *>::const_iterator it2=v2.begin();it2!=v2.end();it2++)
+              std::vector<const BigMemoryObject *> v2((*it)->getDirectChildren());
+              for(std::vector<const BigMemoryObject *>::const_iterator it2=v2.begin();it2!=v2.end();it2++)
                 if(s1.find(*it2)==s1.end())
                   s3.insert(*it2);
             }
@@ -113,7 +121,7 @@ std::size_t RefCountObject::getHeapMemorySize() const
   return ret;
 }
 
-std::string RefCountObject::getHeapMemorySizeStr() const
+std::string BigMemoryObject::getHeapMemorySizeStr() const
 {
   static const char *UNITS[4]={"B","kB","MB","GB"};
   std::size_t m(getHeapMemorySize());
@@ -153,7 +161,21 @@ std::string RefCountObject::getHeapMemorySizeStr() const
   return oss.str();
 }
 
-bool RefCountObject::decrRef() const
+BigMemoryObject::~BigMemoryObject()
+{
+}
+
+//=
+
+RefCountObjectOnly::RefCountObjectOnly():_cnt(1)
+{
+}
+
+RefCountObjectOnly::RefCountObjectOnly(const RefCountObjectOnly& other):_cnt(1)
+{
+}
+
+bool RefCountObjectOnly::decrRef() const
 {
   bool ret=((--_cnt)==0);
   if(ret)
@@ -161,16 +183,39 @@ bool RefCountObject::decrRef() const
   return ret;
 }
 
-void RefCountObject::incrRef() const
+void RefCountObjectOnly::incrRef() const
 {
   _cnt++;
 }
 
-int RefCountObject::getRCValue() const
+int RefCountObjectOnly::getRCValue() const
 {
   return _cnt;
 }
 
+RefCountObjectOnly::~RefCountObjectOnly()
+{
+}
+
+/*!
+ * Do nothing here ! It is not a bug ( I hope :) ) because all subclasses that
+ * copies using operator= should not copy the ref counter of \a other !
+ */
+RefCountObjectOnly& RefCountObjectOnly::operator=(const RefCountObjectOnly& other)
+{
+  return *this;
+}
+
+//=
+
+RefCountObject::RefCountObject()
+{
+}
+
+RefCountObject::RefCountObject(const RefCountObject& other):RefCountObjectOnly(other)
+{
+}
+
 RefCountObject::~RefCountObject()
 {
 }