From 867b8ef63054497249cc3a0138107383d60351dc Mon Sep 17 00:00:00 2001 From: malaterre Date: Mon, 18 Oct 2004 02:17:06 +0000 Subject: [PATCH] ENH: A few minor cosmetic cleanups, mostly some const correctness on gdcmDict* classes, also remove a printf in jpeg parsing --- src/gdcmDict.cxx | 24 ++++++++++++------------ src/gdcmDict.h | 27 +++++++++++++++------------ src/gdcmDictEntry.cxx | 10 +++++----- src/gdcmDictEntry.h | 30 +++++++++++++++--------------- src/gdcmDictSet.cxx | 22 +++++++++++----------- src/gdcmDictSet.h | 21 +++++++++++---------- src/gdcmJpeg.cxx | 5 +++-- 7 files changed, 72 insertions(+), 67 deletions(-) diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index bb6bd72e..8662d151 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/10/12 04:35:45 $ - Version: $Revision: 1.45 $ + Date: $Date: 2004/10/18 02:17:06 $ + Version: $Revision: 1.46 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -23,6 +23,7 @@ #include #include #include + namespace gdcm { @@ -47,15 +48,14 @@ Dict::Dict(std::string const & filename) while (!from.eof()) { from >> std::hex; - from >> group; /// MEMORY LEAK in std::istream::operator>> + from >> group; from >> element; from >> vr; from >> fourth; - from >> std::ws; // used to be eatwhite(from); - std::getline(from, name); /// MEMORY LEAK in std::getline<> + from >> std::ws; //remove white space + std::getline(from, name); - DictEntry * newEntry = new DictEntry(group, element, - vr, fourth, name); + DictEntry * newEntry = new DictEntry(group, element, vr, fourth, name); AddNewEntry(newEntry); } from.close(); @@ -233,7 +233,7 @@ bool Dict::RemoveEntry (uint16_t group, uint16_t element) * the name MAY CHANGE between two versions ! * @return the corresponding dictionnary entry when existing, NULL otherwise */ -DictEntry* Dict::GetDictEntryByName(TagName name) +DictEntry* Dict::GetDictEntryByName(TagName const & name) { if ( !NameHt.count(name)) { @@ -264,9 +264,9 @@ DictEntry* Dict::GetDictEntryByNumber(uint16_t group, uint16_t element) * \sa DictSet::GetPubDictTagNamesByCategory * @return A list of all entries of the public dicom dictionnary. */ -std::list* Dict::GetDictEntryNames() +EntryNamesList* Dict::GetDictEntryNames() { - std::list *result = new std::list; + EntryNamesList *result = new EntryNamesList; for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) { result->push_back( tag->second->GetName() ); @@ -298,9 +298,9 @@ std::list* Dict::GetDictEntryNames() * corresponding values are lists of all the dictionnary entries * among that group. */ -std::map > *Dict::GetDictEntryNamesByCategory(void) +EntryNamesByCatMap *Dict::GetDictEntryNamesByCategory() { - std::map > *result = new std::map >; + EntryNamesByCatMap *result = new EntryNamesByCatMap; for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) { diff --git a/src/gdcmDict.h b/src/gdcmDict.h index 6fcfd93a..b6152da2 100644 --- a/src/gdcmDict.h +++ b/src/gdcmDict.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDict.h,v $ Language: C++ - Date: $Date: 2004/10/12 04:35:45 $ - Version: $Revision: 1.19 $ + Date: $Date: 2004/10/18 02:17:06 $ + Version: $Revision: 1.20 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -25,13 +25,15 @@ #include #include #include + namespace gdcm { //----------------------------------------------------------------------------- typedef std::map TagKeyHT; typedef std::map TagNameHT; - +typedef std::list EntryNamesList; +typedef std::map > EntryNamesByCatMap; //----------------------------------------------------------------------------- /* * \defgroup Dict @@ -46,7 +48,7 @@ typedef std::map TagNameHT; class GDCM_EXPORT Dict { public: - Dict(std::string const & FileName); + Dict(std::string const & filename); ~Dict(); // Print @@ -55,32 +57,33 @@ public: void PrintByName(std::ostream &os = std::cout); // Entries - bool AddNewEntry (DictEntry *NewEntry); - bool ReplaceEntry(DictEntry *NewEntry); + bool AddNewEntry (DictEntry *newEntry); + bool ReplaceEntry(DictEntry *newEntry); bool RemoveEntry (TagKey key); bool RemoveEntry (uint16_t group, uint16_t element); // Tag - DictEntry *GetDictEntryByName(TagName name); + DictEntry *GetDictEntryByName(TagName const & name); DictEntry *GetDictEntryByNumber(uint16_t group, uint16_t element); - std::list *GetDictEntryNames(); - std::map > * - GetDictEntryNamesByCategory(); + EntryNamesList *GetDictEntryNames(); + EntryNamesByCatMap *GetDictEntryNamesByCategory(); /// \brief Returns a ref to the Dicom Dictionary H table (map) /// @return the Dicom Dictionary H table - TagKeyHT & GetEntriesByKey() { return KeyHt; } + const TagKeyHT & GetEntriesByKey() const { return KeyHt; } /// \brief Returns a ref to the Dicom Dictionary H table (map) /// @return the Dicom Dictionary H table - TagNameHT & GetEntriesByName() { return NameHt; } + const TagNameHT & GetEntriesByName() const { return NameHt; } private: /// ASCII file holding the Dictionnary std::string Filename; + /// Access through TagKey (see alternate access with NameHt) TagKeyHT KeyHt; + /// Access through TagName (see alternate access with KeyHt) TagNameHT NameHt; }; diff --git a/src/gdcmDictEntry.cxx b/src/gdcmDictEntry.cxx index d3bb9197..8411e2ed 100644 --- a/src/gdcmDictEntry.cxx +++ b/src/gdcmDictEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictEntry.cxx,v $ Language: C++ - Date: $Date: 2004/10/12 04:35:45 $ - Version: $Revision: 1.26 $ + Date: $Date: 2004/10/18 02:17:06 $ + 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 @@ -36,8 +36,8 @@ namespace gdcm */ DictEntry::DictEntry(uint16_t group, uint16_t element, - std::string vr, std::string fourth, - std::string name) + TagName vr, TagName fourth, + TagName name) { Group = group; Element = element; @@ -72,7 +72,7 @@ TagKey DictEntry::TranslateToKey(uint16_t group, uint16_t element) * \ is unset then overwrite it. * @param vr New V(alue) R(epresentation) to be set. */ -void DictEntry::SetVR(std::string const & vr) +void DictEntry::SetVR(TagName const & vr) { if ( IsVRUnknown() ) { diff --git a/src/gdcmDictEntry.h b/src/gdcmDictEntry.h index dce04530..1e11a6ad 100644 --- a/src/gdcmDictEntry.h +++ b/src/gdcmDictEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictEntry.h,v $ Language: C++ - Date: $Date: 2004/10/12 04:35:45 $ - Version: $Revision: 1.18 $ + Date: $Date: 2004/10/18 02:17:06 $ + Version: $Revision: 1.19 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -39,14 +39,14 @@ class GDCM_EXPORT DictEntry { public: DictEntry(uint16_t group, - uint16_t element, - std::string vr = "Unknown", - std::string fourth = "Unknown", - std::string name = "Unknown"); + uint16_t element, + TagName vr = "Unknown", + TagName fourth = "Unknown", + TagName name = "Unknown"); static TagKey TranslateToKey(uint16_t group, uint16_t element); - void SetVR(std::string const & vr); + void SetVR(TagName const & vr); /// \brief tells if the V(alue) R(epresentation) is known (?!) /// @return @@ -63,26 +63,26 @@ public: /// \brief Returns the Dicom Value Representation of the current /// DictEntry /// @return the Dicom Value Representation - std::string GetVR() { return VR; } + const TagName & GetVR() const { return VR; } /// \brief sets the key of the current DictEntry /// @param k New key to be set. - void SetKey(std::string const & k) { Key = k; } + void SetKey(TagName const & k) { Key = k; } /// \brief returns the Fourth field of the current DictEntry /// \warning NOT part of the Dicom Standard. /// May be REMOVED an any time. NEVER use it. /// @return The Fourth field - std::string GetFourth() { return Fourth; } + const TagName & GetFourth() const { return Fourth; } /// \brief Returns the Dicom Name of the current DictEntry /// e.g. "Patient Name" for Dicom Tag (0x0010, 0x0010) /// @return the Dicom Name - std::string GetName() { return Name; } + const TagName & GetName() const { return Name; } /// \brief Gets the key of the current DictEntry /// @return the key. - std::string GetKey() { return Key; } + const TagName & GetKey() const { return Key; } private: /// \todo FIXME @@ -102,7 +102,7 @@ private: /// \brief Value Representation i.e. some clue about the nature /// of the data represented e.g. "FD" short for /// "Floating Point Double" (see \ref VR) - std::string VR; + TagName VR; /** * \brief AVOID using the following fourth field at all costs. @@ -161,10 +161,10 @@ private: * - LLO = Left Lateral Oblique * . */ - std::string Fourth; + TagName Fourth; /// e.g. "Patient's Name" - std::string Name; + TagName Name; /// Redundant with (group, element) but we add it for efficiency purpose. TagKey Key; diff --git a/src/gdcmDictSet.cxx b/src/gdcmDictSet.cxx index a18a25fa..53c1ff3c 100644 --- a/src/gdcmDictSet.cxx +++ b/src/gdcmDictSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictSet.cxx,v $ Language: C++ - Date: $Date: 2004/10/12 04:35:45 $ - Version: $Revision: 1.38 $ + Date: $Date: 2004/10/18 02:17:07 $ + Version: $Revision: 1.39 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,6 +20,7 @@ #include "gdcmDebug.h" #include #include // For getenv + namespace gdcm { @@ -95,7 +96,7 @@ void DictSet::Print(std::ostream& os) * \sa DictSet::GetPubDictTagNamesByCategory * @return A list of all entries of the public dicom dictionnary. */ -std::list *DictSet::GetPubDictEntryNames() +EntryNamesList * DictSet::GetPubDictEntryNames() { return GetDefaultPubDict()->GetDictEntryNames(); } @@ -126,8 +127,7 @@ std::list *DictSet::GetPubDictEntryNames() * corresponding values are lists of all the dictionnary entries * among that group. */ -std::map > * - DictSet::GetPubDictEntryNamesByCategory() +EntryNamesByCatMap * DictSet::GetPubDictEntryNamesByCategory() { return GetDefaultPubDict()->GetDictEntryNamesByCategory(); } @@ -142,7 +142,7 @@ std::map > * * created dictionary. */ Dict *DictSet::LoadDictFromFile(std::string const & fileName, - DictKey const & name) + DictKey const & name) { Dict *newDict = new Dict(fileName); AppendDict(newDict, name); @@ -172,11 +172,11 @@ Dict *DictSet::GetDict(DictKey const & dictName) * in no dictionnary * @return virtual entry */ -DictEntry *DictSet::NewVirtualDictEntry(uint16_t group, - uint16_t element, - std::string vr, - std::string fourth, - std::string name) +DictEntry *DictSet::NewVirtualDictEntry( uint16_t group, + uint16_t element, + TagName vr, + TagName fourth, + TagName name) { DictEntry* entry; const std::string tag = DictEntry::TranslateToKey(group,element) diff --git a/src/gdcmDictSet.h b/src/gdcmDictSet.h index 68130b4f..895459d0 100644 --- a/src/gdcmDictSet.h +++ b/src/gdcmDictSet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictSet.h,v $ Language: C++ - Date: $Date: 2004/10/12 04:35:45 $ - Version: $Revision: 1.27 $ + Date: $Date: 2004/10/18 02:17:07 $ + Version: $Revision: 1.28 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -22,9 +22,9 @@ #include "gdcmDict.h" #include #include + namespace gdcm { - typedef std::string DictKey; typedef std::map DictSetHT; @@ -45,12 +45,11 @@ public: void Print(std::ostream& os); - std::list* GetPubDictEntryNames(); - std::map > * - GetPubDictEntryNamesByCategory(); + EntryNamesList * GetPubDictEntryNames(); + EntryNamesByCatMap * GetPubDictEntryNamesByCategory(); Dict* LoadDictFromFile( std::string const & fileName, - DictKey const & name ); + DictKey const & name ); Dict* GetDict( DictKey const & DictName ); @@ -62,9 +61,9 @@ public: // Dict* GetVirtualDict() { return &VirtualEntry; }; DictEntry* NewVirtualDictEntry(uint16_t group, uint16_t element, - std::string vr = "Unknown", - std::string fourth = "Unknown", - std::string name = "Unknown"); + TagName vr = "Unknown", + TagName fourth = "Unknown", + TagName name = "Unknown"); static std::string BuildDictPath(); @@ -74,8 +73,10 @@ protected: private: /// Hash table of all dictionaries contained in this DictSet DictSetHT Dicts; + /// Directory path to dictionaries std::string DictPath; + /// H table for the on the fly created DictEntries TagKeyHT VirtualEntry; }; diff --git a/src/gdcmJpeg.cxx b/src/gdcmJpeg.cxx index c13b1860..00cf4b0a 100644 --- a/src/gdcmJpeg.cxx +++ b/src/gdcmJpeg.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmJpeg.cxx,v $ Language: C++ - Date: $Date: 2004/10/15 15:44:42 $ - Version: $Revision: 1.26 $ + Date: $Date: 2004/10/18 02:17:07 $ + 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 @@ -538,6 +538,7 @@ bool gdcm_read_JPEG_file ( FILE* fp, void* image_buffer ) * more than one scanline at a time if that's more convenient. */ + //printf( "scanlines: %d\n",cinfo.output_scanline); (void) jpeg_read_scanlines(&cinfo, buffer, 1); memcpy( pimage, *buffer,rowsize); pimage+=rowsize; -- 2.48.1