X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingRefCountObject.cxx;h=e2b93ea4ec628d6d9f284297bf535d9d6c69b8c4;hb=0c9d48870957c4a9f6f82fc8e2c569780a5f886b;hp=ab245084ef27624e3b15d4a6b72bcbf05f640412;hpb=94d102d362379da8b0dc676e72a7af0a0a0af49a;p=modules%2Fmed.git diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.cxx b/src/MEDCoupling/MEDCouplingRefCountObject.cxx index ab245084e..e2b93ea4e 100644 --- a/src/MEDCoupling/MEDCouplingRefCountObject.cxx +++ b/src/MEDCoupling/MEDCouplingRefCountObject.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2007-2013 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 @@ -16,20 +16,166 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// Author : Anthony Geay (CEA/DEN) #include "MEDCouplingRefCountObject.hxx" +#include "MED_version.h" + +#include using namespace ParaMEDMEM; -RefCountObject::RefCountObject():_cnt(1) +const char *ParaMEDMEM::MEDCouplingVersionStr() +{ + return SALOMEMED_VERSION_STR; +} + +int ParaMEDMEM::MEDCouplingVersion() +{ + return SALOMEMED_VERSION; +} + +void ParaMEDMEM::MEDCouplingVersionMajMinRel(int& maj, int& minor, int& releas) { + int ver=SALOMEMED_VERSION; + maj=(ver & 0xFF0000) >> 16; + minor=(ver & 0xFF00) >> 8; + releas=(ver & 0xFF); +} + +int ParaMEDMEM::MEDCouplingSizeOfVoidStar() +{ + return 8*sizeof(std::size_t); +} + +/*! + * If true is returned it is a LittleEndian machine. + * If false it is a BigEndian machine. + * \return the coding mode of integers of the machine. + */ +bool ParaMEDMEM::MEDCouplingByteOrder() +{ + unsigned int x(1); + unsigned char *xc(reinterpret_cast(&x)); + return xc[0]==1; +} + +const char *ParaMEDMEM::MEDCouplingByteOrderStr() +{ + static const char LITTLEENDIAN_STR[]="LittleEndian"; + static const char BIGENDIAN_STR[]="BigEndian"; + if(MEDCouplingByteOrder()) + return LITTLEENDIAN_STR; + else + return BIGENDIAN_STR; +} + +//= + +std::size_t BigMemoryObject::getHeapMemorySize() const +{ + std::size_t ret(getHeapMemorySizeWithoutChildren()); + std::vector v(getDirectChildren()); + std::set s1,s2(v.begin(),v.end()); + return ret+GetHeapMemoryOfSet(s1,s2); +} + +std::size_t BigMemoryObject::GetHeapMemorySizeOfObjs(const std::vector& objs) +{ + std::size_t ret(0); + std::set s1,s2; + for(std::vector::const_iterator it0=objs.begin();it0!=objs.end();it0++) + { + if(*it0) + if(s1.find(*it0)==s1.end()) + { + std::vector vTmp((*it0)->getDirectChildren()); + s2.insert(vTmp.begin(),vTmp.end()); + ret+=(*it0)->getHeapMemorySizeWithoutChildren(); + s1.insert(*it0); + } + } + return ret+GetHeapMemoryOfSet(s1,s2); +} + +std::size_t BigMemoryObject::GetHeapMemoryOfSet(std::set& s1, std::set& s2) +{ + std::size_t ret(0); + while(!s2.empty()) + { + std::set s3; + for(std::set::const_iterator it=s2.begin();it!=s2.end();it++) + { + if(s1.find(*it)==s1.end()) + { + ret+=(*it)->getHeapMemorySizeWithoutChildren(); + s1.insert(*it); + std::vector v2((*it)->getDirectChildren()); + for(std::vector::const_iterator it2=v2.begin();it2!=v2.end();it2++) + if(s1.find(*it2)==s1.end()) + s3.insert(*it2); + } + } + s2=s3; + } + return ret; } -RefCountObject::RefCountObject(const RefCountObject& other):_cnt(1) +std::string BigMemoryObject::getHeapMemorySizeStr() const { + static const char *UNITS[4]={"B","kB","MB","GB"}; + std::size_t m(getHeapMemorySize()); + std::ostringstream oss; oss.precision(3); + std::size_t remain(0); + int i(0); + for(;i<4;i++) + { + if(m<1024) + { + oss << m; + if(remain!=0) + { + std::ostringstream oss2; oss2 << std::fixed << ((double)remain)/1024.; + std::string s(oss2.str()); + s=s.substr(1,4); + std::size_t pos(s.find_last_not_of('0')); + if(pos==4) + oss << s; + else + oss << s.substr(0,pos+1); + } + oss << " " << UNITS[i]; + break; + } + else + { + if(i!=3) + { + remain=(m%1024); + m/=1024; + } + } + } + if(i==4) + oss << m << " " << UNITS[3]; + 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) @@ -37,11 +183,39 @@ bool RefCountObject::decrRef() const return ret; } -void RefCountObject::incrRef() const +void RefCountObjectOnly::incrRef() const { _cnt++; } +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() { }