1 /*=========================================================================
4 Module: $RCSfile: gdcmContentEntry.cxx,v $
6 Date: $Date: 2005/01/25 15:21:20 $
7 Version: $Revision: 1.1 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmContentEntry.h"
22 #include "gdcmGlobal.h"
24 #include "gdcmDebug.h"
32 #define MAX_SIZE_PRINT_ELEMENT_VALUE 128
34 //-----------------------------------------------------------------------------
35 // Constructor / Destructor
37 * \brief Constructor from a given DictEntry
38 * @param e Pointer to existing dictionary entry
40 ContentEntry::ContentEntry(DictEntry *e) : DocEntry(e)
45 * \brief Constructor from a given DocEntry
46 * @param e Pointer to existing Doc entry
48 ContentEntry::ContentEntry(DocEntry *e)
49 : DocEntry(e->GetDictEntry())
56 * \brief Canonical destructor.
58 ContentEntry::~ContentEntry ()
62 //-----------------------------------------------------------------------------
66 * \brief Writes the std::string representable' value of a ContentEntry
67 * @param fp already open ofstream pointer
68 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
70 void ContentEntry::WriteContent(std::ofstream *fp, FileType filetype)
72 DocEntry::WriteContent(fp, filetype);
74 if ( GetGroup() == 0xfffe )
76 return; //delimitors have NO value
79 const VRKey &vr = GetVR();
80 unsigned int lgr = GetLength();
81 if (vr == "US" || vr == "SS")
83 // some 'Short integer' fields may be multivaluated
84 // each single value is separated from the next one by '\'
85 // we split the string and write each value as a short int
86 std::vector<std::string> tokens;
87 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
88 Util::Tokenize (GetValue(), tokens, "\\");
89 for (unsigned int i=0; i<tokens.size();i++)
91 uint16_t val_uint16 = atoi(tokens[i].c_str());
92 binary_write( *fp, val_uint16);
97 if (vr == "UL" || vr == "SL")
99 // Some 'Integer' fields may be multivaluated (multiple instances
100 // of integer). But each single integer value is separated from the
101 // next one by '\' (backslash character). Hence we split the string
102 // along the '\' and write each value as an int:
103 std::vector<std::string> tokens;
104 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
105 Util::Tokenize (GetValue(), tokens, "\\");
106 for (unsigned int i=0; i<tokens.size();i++)
108 uint32_t val_uint32 = atoi(tokens[i].c_str());
109 binary_write( *fp, val_uint32);
115 gdcmAssertMacro( lgr == GetValue().length() );
116 binary_write(*fp, GetValue());
119 //-----------------------------------------------------------------------------
122 //-----------------------------------------------------------------------------
125 //-----------------------------------------------------------------------------
126 } // end namespace gdcm