From f5575c1671810f3eeecae9967861dff3f1f75f05 Mon Sep 17 00:00:00 2001 From: malaterre Date: Fri, 8 Oct 2004 04:43:37 +0000 Subject: [PATCH] ENH: If possible move the stl include after the gdcm ones, to avoid vc warnings deprecated eatwhite I wasn't able to find the ref in any c++ refs, only microsoft implement it, thus fallback to a more standart c++ approach. This is mainly to get rid of any 'c' like include header - and some minor cleanups --- src/gdcmDicomDirElement.cxx | 17 ++++--- src/gdcmDict.cxx | 6 +-- src/gdcmTS.cxx | 26 +++++----- src/gdcmUtil.cxx | 94 +++++++++++++++++++------------------ src/gdcmUtil.h | 6 +-- src/gdcmVR.cxx | 25 +++++----- 6 files changed, 89 insertions(+), 85 deletions(-) diff --git a/src/gdcmDicomDirElement.cxx b/src/gdcmDicomDirElement.cxx index 84039168..88df039a 100644 --- a/src/gdcmDicomDirElement.cxx +++ b/src/gdcmDicomDirElement.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirElement.cxx,v $ Language: C++ - Date: $Date: 2004/09/27 08:39:06 $ - Version: $Revision: 1.16 $ + Date: $Date: 2004/10/08 04:43:37 $ + Version: $Revision: 1.17 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -16,15 +16,14 @@ =========================================================================*/ -#include -#include // For sprintf -#include - #include "gdcmDicomDirElement.h" #include "gdcmUtil.h" #include "gdcmDebug.h" #include "gdcmDictSet.h" +#include +#include // For sprintf +#include //----------------------------------------------------------------------------- // Constructor / Destructor @@ -46,7 +45,7 @@ gdcmDicomDirElement::gdcmDicomDirElement() while (!from.eof()) { - eatwhite(from); + from >> std::ws; // used to be eatwhite(from); from.getline(buff, 1024, ' '); type = buff; @@ -56,9 +55,9 @@ gdcmDicomDirElement::gdcmDicomDirElement() { from >> std::hex >> elem.group >> elem.elem; - eatwhite(from); + from >> std::ws; // used to be eatwhite(from); from.getline(buff, 1024, '"'); - eatwhite(from); + from >> std::ws; // Used to be eatwhite(from); from.getline(buff, 1024, '"'); elem.value = buff; diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index 925451a3..c72dd48b 100644 --- a/src/gdcmDict.cxx +++ b/src/gdcmDict.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDict.cxx,v $ Language: C++ - Date: $Date: 2004/09/27 08:39:06 $ - Version: $Revision: 1.43 $ + Date: $Date: 2004/10/08 04:43:38 $ + Version: $Revision: 1.44 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -49,7 +49,7 @@ gdcmDict::gdcmDict(std::string const & filename) from >> element; from >> vr; from >> fourth; - eatwhite(from); + from >> std::ws; // used to be eatwhite(from); std::getline(from, name); /// MEMORY LEAK in std::getline<> gdcmDictEntry * newEntry = new gdcmDictEntry(group, element, diff --git a/src/gdcmTS.cxx b/src/gdcmTS.cxx index 152aaebb..82a25780 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/09/27 08:39:07 $ - Version: $Revision: 1.24 $ + Date: $Date: 2004/10/08 04:43:38 $ + Version: $Revision: 1.25 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -16,20 +16,18 @@ =========================================================================*/ -#include -#include -#include - #include "gdcmTS.h" #include "gdcmDebug.h" #include "gdcmUtil.h" #include "gdcmDictSet.h" - +#include +#include +#include //----------------------------------------------------------------------------- // Constructor / Destructor -gdcmTS::gdcmTS(void) +gdcmTS::gdcmTS() { std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_TS); std::ifstream from(filename.c_str()); @@ -38,13 +36,14 @@ gdcmTS::gdcmTS(void) std::string key; std::string name; - while (!from.eof()) { + while (!from.eof()) + { from >> key; - eatwhite(from); + from >> std::ws; // used to be eatwhite(from); std::getline(from, name); /// MEMORY LEAK - if(key!="") + if(key!="") { ts[key]=name; } @@ -52,6 +51,7 @@ gdcmTS::gdcmTS(void) from.close(); } +//----------------------------------------------------------------------------- gdcmTS::~gdcmTS() { ts.clear(); @@ -84,8 +84,10 @@ int gdcmTS::Count(TSKey key) std::string gdcmTS::GetValue(TSKey key) { - if (ts.count(key) == 0) + if (ts.count(key) == 0) + { return GDCM_UNFOUND; + } return ts[key]; } diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 2b59ead1..0b1b14a8 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2004/09/27 08:39:08 $ - Version: $Revision: 1.50 $ + Date: $Date: 2004/10/08 04:43:38 $ + Version: $Revision: 1.51 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,25 +18,6 @@ #include "gdcmUtil.h" #include "gdcmDebug.h" -#include -#include // For isspace -#include // CLEANME: could this be only string ? Related to Win32 ? -#include - -/** - * \ingroup Globals - * \brief Because is not yet available in g++2.96 - */ -std::istream& eatwhite(std::istream& is) { - char c; - while (is.get(c)) { - if (!isspace(c)) { - is.putback(c); - break; - } - } - return is; -} /** * \ingroup Globals @@ -44,10 +25,12 @@ std::istream& eatwhite(std::istream& is) { */ void Tokenize (const std::string& str, std::vector& tokens, - const std::string& delimiters) { + const std::string& delimiters) +{ std::string::size_type lastPos = str.find_first_not_of(delimiters,0); std::string::size_type pos = str.find_first_of (delimiters,lastPos); - while (std::string::npos != pos || std::string::npos != lastPos) { + while (std::string::npos != pos || std::string::npos != lastPos) + { tokens.push_back(str.substr(lastPos, pos - lastPos)); lastPos = str.find_first_not_of(delimiters, pos); pos = str.find_first_of (delimiters, lastPos); @@ -60,18 +43,21 @@ void Tokenize (const std::string& str, * Counts the number of occurences of a substring within a string */ - int CountSubstring (const std::string& str, - const std::string& subStr) { +int CountSubstring (const std::string& str, + const std::string& subStr) +{ int count = 0; // counts how many times it appears unsigned int x = 0; // The index position in the string do - { x = str.find(subStr,x); // Find the substring + { + x = str.find(subStr,x); // Find the substring if (x != std::string::npos) // If present - { count++; // increase the count - x += subStr.length(); // Skip this word - } - } + { + count++; // increase the count + x += subStr.length(); // Skip this word + } + } while (x != std::string::npos); // Carry on until not present return count; @@ -83,19 +69,28 @@ void Tokenize (const std::string& str, * to avoid corrupting the terminal of invocation when printing) * @param s string to remove non printable characters from */ -std::string CreateCleanString(std::string s) { - std::string str=s; +std::string CreateCleanString(std::string s) +{ + std::string str = s; for(unsigned int i=0;i0) + { if(!isprint(s[str.size()-1])) + { if(s[str.size()-1]==0) + { str[str.size()-1]=' '; + } + } + } return str; } @@ -110,7 +105,7 @@ void NormalizePath(std::string &name) const char SEPARATOR_X = '/'; const char SEPARATOR_WIN = '\\'; const std::string SEPARATOR = "/"; - int size=name.size(); + int size = name.size(); if((name[size-1]!=SEPARATOR_X)&&(name[size-1]!=SEPARATOR_WIN)) { @@ -135,6 +130,7 @@ std::string GetPath(std::string &fullName) { fullName.resize(pos2); } + return fullName; } @@ -145,21 +141,27 @@ std::string GetPath(std::string &fullName) */ std::string GetName(std::string &fullName) { - int fin=fullName.length()-1; - char a =fullName.c_str()[fin]; - if (a == '/' || a == '\\') { - fin--; - } - int deb = 0; - for (int i=fin;i!=0;i--) { - if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\') - break; + int fin = fullName.length()-1; + char a =fullName.c_str()[fin]; + if (a == '/' || a == '\\') + { + fin--; + } + int deb = 0; + for (int i=fin;i!=0;i--) + { + if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\') + { + break; + } deb = i; - } + } - std::string lastName; - for (int j=deb;j& tokens, const std::string& delimiters = " "); diff --git a/src/gdcmVR.cxx b/src/gdcmVR.cxx index 596ac9ee..4cc07ea9 100644 --- a/src/gdcmVR.cxx +++ b/src/gdcmVR.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmVR.cxx,v $ Language: C++ - Date: $Date: 2004/09/27 08:39:08 $ - Version: $Revision: 1.17 $ + Date: $Date: 2004/10/08 04:43:38 $ + Version: $Revision: 1.18 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -16,20 +16,19 @@ =========================================================================*/ -#include - -#include - #include "gdcmVR.h" #include "gdcmUtil.h" #include "gdcmDictSet.h" #include "gdcmDebug.h" +#include +#include + //----------------------------------------------------------------------------- /** * \brief Constructor */ -gdcmVR::gdcmVR(void) +gdcmVR::gdcmVR() { std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_VR); std::ifstream from(filename.c_str()); @@ -41,14 +40,14 @@ gdcmVR::gdcmVR(void) while (!from.eof()) { - eatwhite(from); + from >> std::ws; // used to be eatwhite(from); from.getline(buff, 1024, ' '); key = buff; - eatwhite(from); + from >> std::ws; // used to be eatwhite(from); from.getline(buff, 1024, ';'); name = buff; - eatwhite(from); + from >> std::ws; // used to be eatwhite(from); from.getline(buff, 1024, '\n'); if(key!="") @@ -59,10 +58,12 @@ gdcmVR::gdcmVR(void) from.close(); } +//----------------------------------------------------------------------------- /** * \brief Destructor */ -gdcmVR::~gdcmVR() { +gdcmVR::~gdcmVR() +{ vr.clear(); } @@ -94,6 +95,7 @@ int gdcmVR::Count(gdcmVRKey key) return vr.count(key); } +//----------------------------------------------------------------------------- /** * \brief Simple predicate that checks wether the given argument * corresponds to the Value Representation of a \ref gdcmBinEntry . @@ -124,6 +126,7 @@ bool gdcmVR::IsVROfGdcmBinaryRepresentable(gdcmVRKey tested) return true; } +//----------------------------------------------------------------------------- /** * \brief Simple predicate that checks wether the given argument * corresponds to the Value Representation of a \ref gdcmValEntry -- 2.46.1