From: frog Date: Wed, 21 May 2003 14:42:45 +0000 (+0000) Subject: * src/*.[h] all occurences of stl classes are now prefixed with X-Git-Tag: Version0.3~46 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=05abd393cf82392c894dd1d852e2273b0648671d;p=gdcm.git * src/*.[h] all occurences of stl classes are now prefixed with std::, and all occurences of "using namespace std;" where removed. This is to avoid pollution of global namespace in included files. Apparently vtk does not avoid this pitfall: when using both gdcm and vtk (as in vtk/vtkGdcmReader.cxx) this ended up in a collision of various stl members (principally cout...). --- diff --git a/ChangeLog b/ChangeLog index 1093ecc2..1c75af2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,12 @@ - gdcmPython/demo/vtkGdcmReader.py added. This demo illustrates the usage of the python wrapper of vtkGdcmReader vtk class. * vtk/vtkGdcmReader.cxx: bug fixed (thanks to Benoit Regrain). + * src/*.[h] all occurences of stl classes are now prefixed with + std::, and all occurences of "using namespace std;" where removed. + This is to avoid pollution of global namespace in included files. + Apparently vtk does not avoid this pitfall: when using both + gdcm and vtk (as in vtk/vtkGdcmReader.cxx) this ended up in a + collision of various stl members (principally cout...). 2003-05-12 Eric Boix with JPR * src/gdcmHeader>[h/cxx] added gdcmHeader::GetPixelSize() diff --git a/Makefile.am b/Makefile.am index aa38126c..ca2a009e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = src gdcmPython Test Dicts Doc vtk +SUBDIRS = src vtk gdcmPython Test Dicts Doc EXTRA_DIST = \ diff --git a/gdcmPython/gdcm.i b/gdcmPython/gdcm.i index 41d5ee20..02ddf0ac 100644 --- a/gdcmPython/gdcm.i +++ b/gdcmPython/gdcm.i @@ -8,6 +8,7 @@ #include "gdcmElValSet.h" #include "gdcmHeader.h" #include "gdcmFile.h" +using namespace std; // Utility functions on strings for removing leading and trailing spaces void EatLeadingAndTrailingSpaces(string & s) { diff --git a/src/gdcmCommon.h b/src/gdcmCommon.h index 5c2b3805..131fceba 100644 --- a/src/gdcmCommon.h +++ b/src/gdcmCommon.h @@ -26,12 +26,9 @@ typedef int gint32; #endif #include -#ifdef _MSC_VER -using namespace std; // string type lives in the std namespace on VC++ -#endif -typedef string TagKey; -typedef string TagName; +typedef std::string TagKey; +typedef std::string TagName; enum FileType { Unknown = 0, diff --git a/src/gdcmDict.h b/src/gdcmDict.h index 77d837c9..dfab30c3 100644 --- a/src/gdcmDict.h +++ b/src/gdcmDict.h @@ -7,8 +7,8 @@ #include "gdcmCommon.h" #include "gdcmDictEntry.h" -typedef map TagKeyHT; -typedef map TagNameHT; +typedef std::map TagKeyHT; +typedef std::map TagNameHT; /* * \defgroup gdcmDict @@ -21,14 +21,14 @@ typedef map TagNameHT; * \see gdcmDictSet */ class GDCM_EXPORT gdcmDict { - string name; - string filename; + std::string name; + std::string filename; /// Access through TagKey (see alternate access with NameHt) TagKeyHT KeyHt; /// Access through TagName (see alternate access with KeyHt) TagNameHT NameHt; public: - gdcmDict(string & FileName); + gdcmDict(std::string & FileName); ~gdcmDict(); int AddNewEntry (gdcmDictEntry* NewEntry); int ReplaceEntry(gdcmDictEntry* NewEntry); diff --git a/src/gdcmDictEntry.h b/src/gdcmDictEntry.h index 93cf8efc..abb7aa0e 100644 --- a/src/gdcmDictEntry.h +++ b/src/gdcmDictEntry.h @@ -7,16 +7,20 @@ class GDCM_EXPORT gdcmDictEntry { private: - guint16 group; // e.g. 0x0010 // FIXME : s'en sert-on qq part - guint16 element; // e.g. 0x0103 // si ce n'est pour fabriquer la TagKey ? - string vr; // Value Representation i.e. some clue about the nature - // of the data represented e.g. "FD" short for - // "Floating Point Double" + // FIXME : were are the group and element used except from building up + // a TagKey. If the answer is nowhere then there is no need + // to store the group and element independently. + guint16 group; // e.g. 0x0010 + guint16 element; // e.g. 0x0103 + std::string vr; // Value Representation i.e. some clue about the nature + // of the data represented e.g. "FD" short for + // "Floating Point Double" // CLEANME: find the official dicom name for this field ! - string fourth; // Fourth field containing some semantics. (Group Name abbr.) - string name; // e.g. "Patient_Name" - TagKey key; // Redundant with (group, element) but we add it - // on efficiency purposes. + std::string fourth; // Fourth field containing some semantics. + //(Group Name abbr.) + std::string name; // e.g. "Patient_Name" + TagKey key; // Redundant with (group, element) but we add it + // on efficiency purposes. // DCMTK has many fields for handling a DictEntry (see below). What are the // relevant ones for gdcmlib ? // struct DBI_SimpleEntry { @@ -33,22 +37,22 @@ private: public: gdcmDictEntry(guint16 group, guint16 element, - string vr = "Unknown", - string fourth = "Unknown", - string name = "Unknown"); + std::string vr = "Unknown", + std::string fourth = "Unknown", + std::string name = "Unknown"); // fabrique une 'clé' par concaténation du numGroupe et du numElement static TagKey TranslateToKey(guint16 group, guint16 element); - guint16 GetGroup(void) { return group; }; - guint16 GetElement(void){return element;}; - string GetVR(void) {return vr; }; - void SetVR(string); - void SetKey(string k){ key = k; } - bool IsVrUnknown(void); - string GetFourth(void) {return fourth;}; - string GetName(void) {return name; }; - string GetKey(void) {return key; }; + guint16 GetGroup(void) { return group; }; + guint16 GetElement(void){return element;}; + std::string GetVR(void) {return vr; }; + void SetVR(std::string); + void SetKey(std::string k){ key = k; }; + bool IsVrUnknown(void); + std::string GetFourth(void) {return fourth;}; + std::string GetName(void) {return name; }; + std::string GetKey(void) {return key; }; }; #endif diff --git a/src/gdcmDictSet.h b/src/gdcmDictSet.h index 751be5f8..f2f50634 100644 --- a/src/gdcmDictSet.h +++ b/src/gdcmDictSet.h @@ -7,8 +7,8 @@ #include #include "gdcmDict.h" -typedef string DictKey; -typedef map DictSetHT; +typedef std::string DictKey; +typedef std::map DictSetHT; /* * \defgroup gdcmDictSet @@ -23,21 +23,22 @@ private: /// Hash table of all dictionaries contained in this gdcmDictSet DictSetHT Dicts; /// Directory path to dictionaries - string DictPath; + std::string DictPath; int AppendDict(gdcmDict* NewDict); - void LoadDictFromFile(string filename, DictKey); - string BuildDictPath(void); + void LoadDictFromFile(std::string filename, DictKey); + std::string BuildDictPath(void); public: - list * GetPubDictTagNames(void); - map >* GetPubDictTagNamesByCategory(void); + std::list * GetPubDictTagNames(void); + std::map >* + GetPubDictTagNamesByCategory(void); - // TODO Swig int LoadDictFromFile(string filename); + // TODO Swig int LoadDictFromFile(std::string filename); // QUESTION: the following function might not be thread safe !? Maybe // we need some mutex here, to avoid concurent creation of // the same dictionary !?!?! - // TODO Swig int LoadDictFromName(string filename); - // TODO Swig int LoadAllDictFromDirectory(string DirectoryName); - // TODO Swig string* GetAllDictNames(); + // TODO Swig int LoadDictFromName(std::string filename); + // TODO Swig int LoadAllDictFromDirectory(std::string DirectoryName); + // TODO Swig std::string* GetAllDictNames(); gdcmDictSet(void); ~gdcmDictSet(void); void Print(ostream&); diff --git a/src/gdcmElValSet.h b/src/gdcmElValSet.h index ae30bc55..5def2edc 100644 --- a/src/gdcmElValSet.h +++ b/src/gdcmElValSet.h @@ -1,4 +1,4 @@ -// $Header: /cvs/public/gdcm/src/Attic/gdcmElValSet.h,v 1.11 2003/04/16 08:03:27 frog Exp $ +// $Header: /cvs/public/gdcm/src/Attic/gdcmElValSet.h,v 1.12 2003/05/21 14:42:46 frog Exp $ #ifndef GDCMELVALSET_H #define GDCMELVALSET_H @@ -10,15 +10,15 @@ //////////////////////////////////////////////////////////////////////////// // Container for a set of successfully parsed ElValues. -typedef map TagElValueHT; -typedef map TagElValueNameHT; +typedef std::map TagElValueHT; +typedef std::map TagElValueNameHT; class GDCM_EXPORT gdcmElValSet { TagElValueHT tagHt; // Both accesses with a TagKey or with a TagElValueNameHT NameHt; // the DictEntry.Name are required. - typedef string GroupKey; - typedef map GroupHT; + typedef std::string GroupKey; + typedef std::map GroupHT; public: ~gdcmElValSet(); @@ -29,17 +29,17 @@ public: int Write(FILE *fp, FileType type); gdcmElValue* GetElementByNumber(guint16 group, guint16 element); - gdcmElValue* GetElementByName (string); - string GetElValueByNumber(guint16 group, guint16 element); - string GetElValueByName (string); + gdcmElValue* GetElementByName (std::string); + std::string GetElValueByNumber(guint16 group, guint16 element); + std::string GetElValueByName (std::string); TagElValueHT & GetTagHt(void); - int SetElValueByNumber(string content, guint16 group, guint16 element); - int SetElValueByName (string content, string TagName); + int SetElValueByNumber(std::string content, guint16 group, guint16 element); + int SetElValueByName (std::string content, std::string TagName); int SetElValueLengthByNumber(guint32 l, guint16 group, guint16 element); - int SetElValueLengthByName (guint32 l, string TagName); + int SetElValueLengthByName (guint32 l, std::string TagName); guint32 GenerateFreeTagKeyInGroup(guint16 group); diff --git a/src/gdcmElValue.h b/src/gdcmElValue.h index 1365d8bc..9dec12ca 100644 --- a/src/gdcmElValue.h +++ b/src/gdcmElValue.h @@ -1,4 +1,4 @@ -// $Header: /cvs/public/gdcm/src/Attic/gdcmElValue.h,v 1.4 2003/04/09 14:04:53 jpr Exp $ +// $Header: /cvs/public/gdcm/src/Attic/gdcmElValue.h,v 1.5 2003/05/21 14:42:46 frog Exp $ #ifndef GDCMELVALUE_H #define GDCMELVALUE_H @@ -24,7 +24,7 @@ private: //friend gdcmElValue * gdcmHeader::ReadNextElement(void); friend class gdcmHeader; public: - string value; + std::string value; size_t Offset; // Offset from the begining of file for direct user access gdcmElValue(gdcmDictEntry*); @@ -34,17 +34,17 @@ public: bool IsImplicitVr(void) { return ImplicitVr; }; gdcmDictEntry * GetDictEntry(void) { return entry; }; - guint16 GetGroup(void) { return entry->GetGroup(); }; - guint16 GetElement(void) { return entry->GetElement();}; - string GetKey(void) { return entry->GetKey(); }; - string GetName(void) { return entry->GetName(); }; - string GetVR(void) { return entry->GetVR(); }; - void SetVR(string v) { entry->SetVR(v); }; - void SetLength(guint32 l){ LgrElem = l; }; - guint32 GetLength(void) { return LgrElem; }; + guint16 GetGroup(void) { return entry->GetGroup(); }; + guint16 GetElement(void) { return entry->GetElement();}; + std::string GetKey(void) { return entry->GetKey(); }; + std::string GetName(void) { return entry->GetName(); }; + std::string GetVR(void) { return entry->GetVR(); }; + void SetVR(std::string v) { entry->SetVR(v); }; + void SetLength(guint32 l){ LgrElem = l; }; + guint32 GetLength(void) { return LgrElem; }; - void SetValue(string val){ value = val; }; - string GetValue(void) { return value;}; + void SetValue(std::string val){ value = val; }; + std::string GetValue(void) { return value;}; size_t GetOffset(void) { return Offset;}; }; diff --git a/src/gdcmException.h b/src/gdcmException.h index 1d0192c3..f347b6af 100644 --- a/src/gdcmException.h +++ b/src/gdcmException.h @@ -16,19 +16,9 @@ #define GDCM_EXCEPTION_H #include -#ifdef _MSC_VER -using namespace std; // string type lives in the std namespace on VC++ -#endif - #include #include -using namespace std; - -#ifdef _MSC_VER -#define GDCM_EXPORT __declspec( dllexport ) -#else -#define GDCM_EXPORT -#endif +#include "gdcmCommon.h" /** * Any exception thrown in the gdcm library @@ -36,9 +26,9 @@ using namespace std; class GDCM_EXPORT gdcmException : public exception { protected: /// error message - string from; + std::string from; /// error message - string error; + std::string error; public: /** @@ -48,7 +38,7 @@ class GDCM_EXPORT gdcmException : public exception { * @param from name of the thrower * @param error error description string */ - explicit gdcmException(const string &from, const string &error = "") + explicit gdcmException(const std::string &from, const std::string &error = "") throw(); @@ -59,7 +49,7 @@ class GDCM_EXPORT gdcmException : public exception { } /// returns error message - const string &getError(void) const throw() { + const std::string &getError(void) const throw() { return error; } @@ -76,9 +66,9 @@ class GDCM_EXPORT gdcmException : public exception { static void fatal(const char *from) throw(); /// try to discover this (dynamic) class name - virtual string getName() const throw(); + virtual std::string getName() const throw(); - friend ostream& operator<<(ostream &os, const gdcmException &e); + friend std::ostream& operator<<(std::ostream &os, const gdcmException &e); }; @@ -103,15 +93,13 @@ class GDCM_EXPORT gdcmFileError : public gdcmException { * @param from name of the thrower * @param error error description string */ - explicit gdcmFileError(const string &from, - const string &error = "File error") + explicit gdcmFileError(const std::string &from, + const std::string &error = "File error") throw() : gdcmException(from, error) { } }; - - /** * Invalid file format exception */ @@ -124,8 +112,8 @@ class GDCM_EXPORT gdcmFormatError : public gdcmException { * @param from name of the thrower * @param error error description string */ - explicit gdcmFormatError(const string &from, - const string &error = "Invalid file format error") + explicit gdcmFormatError(const std::string &from, + const std::string &error = "Invalid file format error") throw() : gdcmException(from, error) { } }; diff --git a/src/gdcmFile.h b/src/gdcmFile.h index 89d038ee..6bcd2067 100644 --- a/src/gdcmFile.h +++ b/src/gdcmFile.h @@ -17,13 +17,13 @@ private: void* PixelData; size_t lgrTotale; int Parsed; // weather allready parsed - string OrigFileName; // To avoid file overwrite + std::string OrigFileName; // To avoid file overwrite void SwapZone(void* im, int swap, int lgr, int nb); bool ReadPixelData(void * destination); protected: - int WriteBase(string FileName, FileType type); + int WriteBase(std::string FileName, FileType type); public: - gdcmFile(string & filename); + gdcmFile(std::string & filename); gdcmFile(const char * filename); // For promotion (performs a deepcopy of pointed header object) @@ -31,9 +31,9 @@ public: // TODO Swig ~gdcmFile(); // On writing purposes. When instance was created through - // gdcmFile(string filename) then the filename argument MUST be different - // from the constructor's one (no overwriting allowed). - // TODO Swig int SetFileName(string filename); + // gdcmFile(std::string filename) then the filename argument MUST be + // different from the constructor's one (no overwriting allowed). + // TODO Swig int SetFileName(std::string filename); void SetPixelDataSizeFromHeader(void); size_t GetImageDataSize(); @@ -59,11 +59,11 @@ public: // Aucun test n'est fait sur l'"Endiannerie" du processeur. // Ca sera à l'utilisateur d'appeler son Reader correctement - int WriteRawData (string nomFichier); - int WriteDcmImplVR(string nomFichier); + int WriteRawData (std::string nomFichier); + int WriteDcmImplVR(std::string nomFichier); int WriteDcmImplVR(const char * nomFichier); - int WriteDcmExplVR(string nomFichier); - int WriteAcr (string nomFichier); + int WriteDcmExplVR(std::string nomFichier); + int WriteAcr (std::string nomFichier); }; #endif diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 002aed72..48ebc838 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -1,4 +1,4 @@ -// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.65 2003/05/12 14:32:43 frog Exp $ +// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.66 2003/05/21 14:42:46 frog Exp $ #include #include @@ -12,6 +12,7 @@ #include #include "gdcmUtil.h" #include "gdcmHeader.h" +using namespace std; // Refer to gdcmHeader::CheckSwap() #define HEADER_LENGTH_TO_READ 256 diff --git a/src/gdcmHeader.h b/src/gdcmHeader.h index ae885cf8..a634e1f5 100644 --- a/src/gdcmHeader.h +++ b/src/gdcmHeader.h @@ -1,4 +1,4 @@ -// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.h,v 1.23 2003/05/12 14:32:43 frog Exp $ +// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.h,v 1.24 2003/05/21 14:42:46 frog Exp $ #ifndef GDCMHEADER_H #define GDCMHEADER_H @@ -11,9 +11,9 @@ #include "gdcmElValue.h" #include "gdcmElValSet.h" -typedef string VRKey; -typedef string VRAtr; -typedef map VRHT; // Value Representation Hash Table +typedef std::string VRKey; +typedef std::string VRAtr; +typedef std::map VRHT; // Value Representation Hash Table /// The purpose of an instance of gdcmHeader is to act as a container of /// all the DICOM elements and their corresponding values (and @@ -51,7 +51,7 @@ private: /// ELement VALueS parsed with the SHAdow dictionary. gdcmElValSet ShaElValSet; /// Refering underlying filename. - string filename; + std::string filename; // FIXME sw should be an enum e.g. //enum EndianType { @@ -76,16 +76,17 @@ private: void CheckSwap(void); void SwitchSwapToBigEndian(void); // CLEAN ME: NewManualElValToPubDict is NOT called any more. - gdcmElValue* NewManualElValToPubDict(string NewTagName, string VR); + gdcmElValue* NewManualElValToPubDict(std::string NewTagName, + std::string VR); void SetMaxSizeLoadElementValue(long); gdcmDictEntry * GetDictEntryByNumber(guint16, guint16); - gdcmDictEntry * GetDictEntryByName(string name); + gdcmDictEntry * GetDictEntryByName(std::string name); // ElValue related utilities gdcmElValue * ReadNextElement(void); gdcmElValue * NewElValueByNumber(guint16 group, guint16 element); - gdcmElValue * NewElValueByName(string name); + gdcmElValue * NewElValueByName(std::string name); void FindLength(gdcmElValue *); void FindVR(gdcmElValue *); @@ -130,43 +131,43 @@ public: size_t GetPixelOffset(void); int GetSwapCode(void) { return sw; } - // TODO Swig int SetPubDict(string filename); + // TODO Swig int SetPubDict(std::string filename); // When some proprietary shadow groups are disclosed, we can set up // an additional specific dictionary to access extra information. - // TODO Swig int SetShaDict(string filename); + // TODO Swig int SetShaDict(std::string filename); - string GetPubElValByName(string TagName); - string GetPubElValByNumber(guint16 group, guint16 element); - string GetPubElValRepByName(string TagName); - string GetPubElValRepByNumber(guint16 group, guint16 element); + std::string GetPubElValByName(std::string TagName); + std::string GetPubElValByNumber(guint16 group, guint16 element); + std::string GetPubElValRepByName(std::string TagName); + std::string GetPubElValRepByNumber(guint16 group, guint16 element); TagElValueHT & GetPubElVal(void) { return PubElValSet.GetTagHt(); }; void PrintPubElVal(ostream & os = cout); void PrintPubDict (ostream & os = cout); - // TODO Swig string* GetShaTagNames(); - string GetShaElValByName(string TagName); - string GetShaElValByNumber(guint16 group, guint16 element); - string GetShaElValRepByName(string TagName); - string GetShaElValRepByNumber(guint16 group, guint16 element); - - string GetElValByName(string TagName); - string GetElValByNumber(guint16 group, guint16 element); - string GetElValRepByName(string TagName); - string GetElValRepByNumber(guint16 group, guint16 element); - - int SetPubElValByName(string content, string TagName); - int SetPubElValByNumber(string content, guint16 group, guint16 element); - int SetShaElValByName(string content, string ShadowTagName); - int SetShaElValByNumber(string content, guint16 group, guint16 element); + // TODO Swig std::string* GetShaTagNames(); + std::string GetShaElValByName(std::string TagName); + std::string GetShaElValByNumber(guint16 group, guint16 element); + std::string GetShaElValRepByName(std::string TagName); + std::string GetShaElValRepByNumber(guint16 group, guint16 element); + + std::string GetElValByName(std::string TagName); + std::string GetElValByNumber(guint16 group, guint16 element); + std::string GetElValRepByName(std::string TagName); + std::string GetElValRepByNumber(guint16 group, guint16 element); + + int SetPubElValByName(std::string content, std::string TagName); + int SetPubElValByNumber(std::string content, guint16 group, guint16 element); + int SetShaElValByName(std::string content, std::string ShadowTagName); + int SetShaElValByNumber(std::string content, guint16 group, guint16 element); int SetPubElValLengthByNumber(guint32 lgr, guint16 group, guint16 element); - int ReplaceOrCreateByNumber(string Value, guint16 Group, guint16 Elem); + int ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem); int GetXSize(void); int GetYSize(void); int GetZSize(void); int GetPixelSize(void); - string GetPixelType(void); + std::string GetPixelType(void); int Write(FILE *, FileType); }; diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 207b66f1..54c2a476 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -1,4 +1,4 @@ -// gdcmUtil.cxx +// $Header: /cvs/public/gdcm/src/gdcmUtil.cxx,v 1.10 2003/05/21 14:42:46 frog Exp $ #include // For isspace #include "gdcmUtil.h" diff --git a/src/gdcmUtil.h b/src/gdcmUtil.h index cb9dcbd3..e00e8934 100644 --- a/src/gdcmUtil.h +++ b/src/gdcmUtil.h @@ -1,4 +1,4 @@ -// gdcmUtil.h +// $Header: /cvs/public/gdcm/src/gdcmUtil.h,v 1.9 2003/05/21 14:42:46 frog Exp $ #ifndef GDCMUTIL_H #define GDCMUTIL_H @@ -8,7 +8,6 @@ #include #include "gdcmVR.h" #include "gdcmDictSet.h" -using namespace std; class gdcmDebug { private: @@ -35,9 +34,9 @@ public: istream & eatwhite(istream & is); -void Tokenize (const string& str, - vector& tokens, - const string& delimiters = " "); +void Tokenize (const std::string& str, + std::vector& tokens, + const std::string& delimiters = " "); extern gdcmDebug dbg; diff --git a/src/gdcmVR.h b/src/gdcmVR.h index db5869a0..68d7fee3 100644 --- a/src/gdcmVR.h +++ b/src/gdcmVR.h @@ -7,9 +7,9 @@ #include #include "gdcmCommon.h" -typedef string VRKey; -typedef string VRAtr; -typedef map VRHT; // Value Representation Hash Table +typedef std::string VRKey; +typedef std::string VRAtr; +typedef std::map VRHT; // Value Representation Hash Table /// Container for dicom Value Representation Hash Table /// \note This is a singleton