1 /*=========================================================================
4 Module: $RCSfile: gdcmContentEntry.cxx,v $
6 Date: $Date: 2005/01/26 10:29:16 $
7 Version: $Revision: 1.4 $
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"
31 //-----------------------------------------------------------------------------
32 // Constructor / Destructor
34 * \brief Constructor for a given DictEntry
35 * @param e Pointer to existing dictionary entry
37 ContentEntry::ContentEntry(DictEntry *e) : DocEntry(e)
43 * \brief Constructor for a given DocEntry
44 * @param e Pointer to existing Doc entry
46 ContentEntry::ContentEntry(DocEntry *e)
47 : DocEntry(e->GetDictEntry())
53 * \brief Canonical destructor.
55 ContentEntry::~ContentEntry ()
59 //-----------------------------------------------------------------------------
63 * \brief Writes the 'std::string representable' value of a ContentEntry
64 * @param fp already open ofstream pointer
65 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
67 void ContentEntry::WriteContent(std::ofstream *fp, FileType filetype)
69 DocEntry::WriteContent(fp, filetype);
71 if ( GetGroup() == 0xfffe )
73 return; //delimitors have NO value
76 const VRKey &vr = GetVR();
77 unsigned int lgr = GetLength();
78 if (vr == "US" || vr == "SS")
80 // some 'Short integer' fields may be multivaluated
81 // each single value is separated from the next one by '\'
82 // we split the string and write each value as a short int
83 std::vector<std::string> tokens;
84 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
85 Util::Tokenize (GetValue(), tokens, "\\");
86 for (unsigned int i=0; i<tokens.size();i++)
88 uint16_t val_uint16 = atoi(tokens[i].c_str());
89 binary_write( *fp, val_uint16);
94 if (vr == "UL" || vr == "SL")
96 // Some 'Integer' fields may be multivaluated (multiple instances
97 // of integer). But each single integer value is separated from the
98 // next one by '\' (backslash character). Hence we split the string
99 // along the '\' and write each value as an int:
100 std::vector<std::string> tokens;
101 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
102 Util::Tokenize (GetValue(), tokens, "\\");
103 for (unsigned int i=0; i<tokens.size();i++)
105 uint32_t val_uint32 = atoi(tokens[i].c_str());
106 binary_write( *fp, val_uint32);
112 gdcmAssertMacro( lgr == GetValue().length() );
113 binary_write(*fp, GetValue());
116 //-----------------------------------------------------------------------------
119 //-----------------------------------------------------------------------------
122 //-----------------------------------------------------------------------------
123 } // end namespace gdcm