From: malaterre Date: Sat, 9 Oct 2004 02:57:11 +0000 (+0000) Subject: :ENH: carefully one at a time modify gdcm src. For now rewrite gdcmDictEntry. Modify... X-Git-Tag: Version0.6.bp~99 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=1a7deed00e1d42de85b4ad27e6978b9f2885e218;p=gdcm.git :ENH: carefully one at a time modify gdcm src. For now rewrite gdcmDictEntry. Modify gdcmUtil to have a sprintf like method called Format. We should really do a gdcmUtil class to encapsulate all those globals fonctions. --- diff --git a/src/gdcmDictEntry.cxx b/src/gdcmDictEntry.cxx index 554749ea..c37c7938 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/09/27 08:39:06 $ - Version: $Revision: 1.23 $ + Date: $Date: 2004/10/09 02:57:11 $ + Version: $Revision: 1.24 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,31 +18,31 @@ #include "gdcmDictEntry.h" #include "gdcmDebug.h" +#include "gdcmUtil.h" -#include // FIXME For sprintf //----------------------------------------------------------------------------- // Constructor / Destructor /** * \brief Constructor - * @param InGroup DICOM-Group Number - * @param InElement DICOM-Element Number - * @param InVr Value Representatiion - * @param InFourth // DO NOT use any longer; + * @param group DICOM-Group Number + * @param element DICOM-Element Number + * @param vr Value Representatiion + * @param fourth // DO NOT use any longer; * NOT part of the Dicom Standard - * @param InName description of the element + * @param name description of the element */ -gdcmDictEntry::gdcmDictEntry(uint16_t InGroup, uint16_t InElement, - std::string InVr, std::string InFourth, - std::string InName) +gdcmDictEntry::gdcmDictEntry(uint16_t group, uint16_t element, + std::string vr, std::string fourth, + std::string name) { - group = InGroup; - element = InElement; - vr = InVr; - fourth = InFourth; - name = InName; - key = TranslateToKey(group, element); /// \todo Frog MEMORY LEAK. + Group = group; + Element = element; + VR = vr; + Fourth = fourth; + Name = name; + Key = TranslateToKey(group, element); } //----------------------------------------------------------------------------- @@ -52,36 +52,34 @@ gdcmDictEntry::gdcmDictEntry(uint16_t InGroup, uint16_t InElement, // Public /** * \brief concatenates 2 uint16_t (supposed to be a Dicom group number - * and a Dicom element number) - * @param group the Dicom group number used to build the tag + * and a Dicom element number) + * @param group the Dicom group number used to build the tag * @param element the Dicom element number used to build the tag * @return the built tag */ gdcmTagKey gdcmDictEntry::TranslateToKey(uint16_t group, uint16_t element) { - char trash[10]; - gdcmTagKey key; - // CLEANME: better call the iostream<< with the hex manipulator on. - // This requires some reading of the stdlibC++ sources to make the - // proper call (or copy). - sprintf(trash, "%04x|%04x", group , element); - key = trash; // Convertion through assignement + gdcmTagKey key = Format("%04x|%04x", group , element); + return key; } +//----------------------------------------------------------------------------- /** * \brief If-and only if-the V(alue) R(epresentation) * \ is unset then overwrite it. - * @param NewVr New V(alue) R(epresentation) to be set. + * @param vr New V(alue) R(epresentation) to be set. */ -void gdcmDictEntry::SetVR(std::string NewVr) +void gdcmDictEntry::SetVR(std::string const & vr) { if ( IsVRUnknown() ) - vr = NewVr; + { + VR = vr; + } else { dbg.Error(true, "gdcmDictEntry::SetVR", - "Overwriting vr might compromise a dictionary"); + "Overwriting VR might compromise a dictionary"); } } @@ -92,4 +90,3 @@ void gdcmDictEntry::SetVR(std::string NewVr) // Private //----------------------------------------------------------------------------- - diff --git a/src/gdcmDictEntry.h b/src/gdcmDictEntry.h index 5a2e8a07..72d60602 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/09/27 08:39:06 $ - Version: $Revision: 1.16 $ + Date: $Date: 2004/10/09 02:57:11 $ + 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 @@ -43,43 +43,43 @@ public: static gdcmTagKey TranslateToKey(uint16_t group, uint16_t element); - void SetVR(std::string); + void SetVR(std::string const & vr); /// \brief tells if the V(alue) R(epresentation) is known (?!) /// @return - bool IsVRUnknown() {return vr == "??"; } + bool IsVRUnknown() { return VR == "??"; } /// \brief Returns the Dicom Group Number of the current gdcmDictEntry /// @return the Dicom Group Number - uint16_t GetGroup() { return group; } + uint16_t GetGroup() { return Group; } /// \brief Returns the Dicom Element Number of the current gdcmDictEntry /// @return the Dicom Element Number - uint16_t GetElement() { return element; } + uint16_t GetElement() { return Element; } /// \brief Returns the Dicom Value Representation of the current /// gdcmDictEntry /// @return the Dicom Value Representation - std::string GetVR() { return vr; } + std::string GetVR() { return VR; } /// \brief sets the key of the current gdcmDictEntry /// @param k New key to be set. - void SetKey(std::string k) { key = k; } + void SetKey(std::string const & k) { Key = k; } /// \brief returns the Fourth field of the current gdcmDictEntry /// \warning NOT part of the Dicom Standard. /// May be REMOVED an any time. NEVER use it. /// @return The Fourth field - std::string GetFourth(void) { return fourth; } + std::string GetFourth() { return Fourth; } /// \brief Returns the Dicom Name of the current gdcmDictEntry /// e.g. "Patient Name" for Dicom Tag (0x0010, 0x0010) /// @return the Dicom Name - std::string GetName(void) { return name; } + std::string GetName() { return Name; } /// \brief Gets the key of the current gdcmDictEntry /// @return the key. - std::string GetKey(void) { return key; } + std::string GetKey() { return Key; } private: /// \todo FIXME @@ -91,20 +91,20 @@ private: /// What's gdcmTagKey used for ? /// DicomGroup number - uint16_t group; // e.g. 0x0010 + uint16_t Group; // e.g. 0x0010 /// DicomElement number - uint16_t element; // e.g. 0x0103 + uint16_t Element; // e.g. 0x0103 /// \brief Value Representation i.e. some clue about the nature /// of the data represented e.g. "FD" short for /// "Floating Point Double" (see \ref gdcmVR) - std::string vr; + std::string VR; /** * \brief AVOID using the following fourth field at all costs. * - * They are at leat two good reasons for NOT using fourth: + * They are at least two good reasons for NOT using fourth: * - the main reason is that it is NOT part of the 'official' * Dicom Dictionnary. * - a second reason is that it is not defined for all the groups. @@ -158,13 +158,13 @@ private: * - LLO = Left Lateral Oblique * . */ - std::string fourth; + std::string Fourth; /// e.g. "Patient's Name" - std::string name; + std::string Name; - /// Redundant with (group, element) but we add it on efficiency purposes. - gdcmTagKey key; + /// Redundant with (group, element) but we add it for efficiency purpose. + gdcmTagKey Key; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 0b1b14a8..2fe6c7b0 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/10/08 04:43:38 $ - Version: $Revision: 1.51 $ + Date: $Date: 2004/10/09 02:57:12 $ + Version: $Revision: 1.52 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -19,6 +19,33 @@ #include "gdcmUtil.h" #include "gdcmDebug.h" + +/** + * \ingroup Globals + * \brief Provide a better 'c++' approach for sprintf + * For example c code is: + * sprintf(trash, "%04x|%04x", group , element); + * + * c++ is + * std::ostringstream buf; + * buf << std::right << std::setw(4) << std::setfill('0') << std::hex + * << group << "|" << std::right << std::setw(4) << std::setfill('0') + * << std::hex << element; + * buf.str(); + */ +#include //only included in implementation file +#include //only included in implementation file + +std::string Format(const char* format, ...) +{ + char buffer[2048]; + va_list args; + va_start(args, format); + vsprintf(buffer, format, args); //might be a security flaw + return buffer; +} + + /** * \ingroup Globals * \brief Because not available in C++ (?) diff --git a/src/gdcmUtil.h b/src/gdcmUtil.h index 3e8056ca..685b5c3d 100644 --- a/src/gdcmUtil.h +++ b/src/gdcmUtil.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.h,v $ Language: C++ - Date: $Date: 2004/10/08 04:43:38 $ - Version: $Revision: 1.33 $ + Date: $Date: 2004/10/09 02:57:12 $ + Version: $Revision: 1.34 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -32,11 +32,12 @@ */ //----------------------------------------------------------------------------- -GDCM_EXPORT void Tokenize (const std::string& str, - std::vector& tokens, - const std::string& delimiters = " "); -GDCM_EXPORT int CountSubstring (const std::string& str, - const std::string& subStr); +GDCM_EXPORT std::string Format(const char* format, ...); +GDCM_EXPORT void Tokenize (const std::string& str, + std::vector& tokens, + const std::string& delimiters = " "); +GDCM_EXPORT int CountSubstring (const std::string& str, + const std::string& subStr); GDCM_EXPORT std::string CreateCleanString(std::string s); GDCM_EXPORT void NormalizePath(std::string &name);