From: malaterre Date: Wed, 27 Oct 2004 01:32:15 +0000 (+0000) Subject: ENH: Minor cleanup in arg passing to be const ref, instead of bycopy X-Git-Tag: Version0.6.bp~39 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=79a0d5df2d3f7ed7a295d76c3ae1048358bc019a;p=gdcm.git ENH: Minor cleanup in arg passing to be const ref, instead of bycopy --- diff --git a/src/gdcmTS.cxx b/src/gdcmTS.cxx index 4f87ab6c..15645c5f 100644 --- a/src/gdcmTS.cxx +++ b/src/gdcmTS.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmTS.cxx,v $ Language: C++ - Date: $Date: 2004/10/12 04:35:48 $ - Version: $Revision: 1.26 $ + Date: $Date: 2004/10/27 01:32:15 $ + Version: $Revision: 1.27 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -27,28 +27,26 @@ namespace gdcm { - //----------------------------------------------------------------------------- // Constructor / Destructor TS::TS() { - std::string filename=DictSet::BuildDictPath() + std::string(DICT_TS); + std::string filename = DictSet::BuildDictPath() + DICT_TS; std::ifstream from(filename.c_str()); - dbg.Error(!from, "TS::TS: can't open dictionary",filename.c_str()); + dbg.Error(!from, "TS::TS: can't open dictionary", filename.c_str()); - std::string key; - std::string name; + TSKey key; + TSAtr name; while (!from.eof()) { from >> key; + from >> std::ws; + std::getline(from, name); - from >> std::ws; // used to be eatwhite(from); - std::getline(from, name); /// MEMORY LEAK - - if(key!="") + if(key != "") { - ts[key]=name; + TsMap[key] = name; } } from.close(); @@ -57,7 +55,7 @@ TS::TS() //----------------------------------------------------------------------------- TS::~TS() { - ts.clear(); + TsMap.clear(); } //----------------------------------------------------------------------------- @@ -71,27 +69,28 @@ void TS::Print(std::ostream &os) { std::ostringstream s; - for (TSHT::iterator it = ts.begin(); it != ts.end(); ++it) + for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it) { - s << "TS : "<first<<" = "<second<first << " = " << it->second << std::endl; } os << s.str(); } //----------------------------------------------------------------------------- // Public -int TS::Count(TSKey key) +int TS::Count(TSKey const & key) { - return ts.count(key); + return TsMap.count(key); } -std::string TS::GetValue(TSKey key) +TSAtr const & TS::GetValue(TSKey const & key) { - if (ts.count(key) == 0) + TSHT::const_iterator it = TsMap.find(key); + if (it == TsMap.end()) { return GDCM_UNFOUND; } - return ts[key]; + return it->second; } //----------------------------------------------------------------------------- diff --git a/src/gdcmTS.h b/src/gdcmTS.h index cbf78f1d..1d9b84b2 100644 --- a/src/gdcmTS.h +++ b/src/gdcmTS.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmTS.h,v $ Language: C++ - Date: $Date: 2004/10/12 04:35:48 $ - Version: $Revision: 1.10 $ + Date: $Date: 2004/10/27 01:32:15 $ + Version: $Revision: 1.11 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -23,9 +23,9 @@ #include #include #include + namespace gdcm { - //----------------------------------------------------------------------------- typedef std::string TSKey; typedef std::string TSAtr; @@ -44,11 +44,11 @@ public: void Print(std::ostream &os = std::cout); - int Count(TSKey key); - std::string GetValue(TSKey key); + int Count(TSKey const & key); + TSAtr const & GetValue(TSKey const & key); private: - TSHT ts; + TSHT TsMap; }; } // end namespace gdcm