]> Creatis software - gdcm.git/commitdiff
ENH: Minor cleanup in arg passing to be const ref, instead of bycopy
authormalaterre <malaterre>
Wed, 27 Oct 2004 01:32:15 +0000 (01:32 +0000)
committermalaterre <malaterre>
Wed, 27 Oct 2004 01:32:15 +0000 (01:32 +0000)
src/gdcmTS.cxx
src/gdcmTS.h

index 4f87ab6c947e227336c747c8b05d9b47fd0363a3..15645c5f4b8b5bde2e61db8ca065c5999b83fe2f 100644 (file)
@@ -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
 
 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 : "<<it->first<<" = "<<it->second<<std::endl;
+      s << "TS : " << it->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;
 }
 
 //-----------------------------------------------------------------------------
index cbf78f1d85ebcee544642a2b6691fc0b6fcede43..1d9b84b2bb20ceb016a9f2321a9839f89e629952 100644 (file)
@@ -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 <map>
 #include <string>
 #include <iostream>
+
 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