1 /*=========================================================================
4 Module: $RCSfile: gdcmContentEntry.cxx,v $
6 Date: $Date: 2005/01/25 16:32:45 $
7 Version: $Revision: 1.2 $
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)
46 * \brief Constructor from a given DocEntry
47 * @param e Pointer to existing Doc entry
49 ContentEntry::ContentEntry(DocEntry *e)
50 : DocEntry(e->GetDictEntry())
57 * \brief Canonical destructor.
59 ContentEntry::~ContentEntry ()
63 //-----------------------------------------------------------------------------
67 * \brief Writes the std::string representable' value of a ContentEntry
68 * @param fp already open ofstream pointer
69 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
71 void ContentEntry::WriteContent(std::ofstream *fp, FileType filetype)
73 DocEntry::WriteContent(fp, filetype);
75 if ( GetGroup() == 0xfffe )
77 return; //delimitors have NO value
80 const VRKey &vr = GetVR();
81 unsigned int lgr = GetLength();
82 if (vr == "US" || vr == "SS")
84 // some 'Short integer' fields may be multivaluated
85 // each single value is separated from the next one by '\'
86 // we split the string and write each value as a short int
87 std::vector<std::string> tokens;
88 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
89 Util::Tokenize (GetValue(), tokens, "\\");
90 for (unsigned int i=0; i<tokens.size();i++)
92 uint16_t val_uint16 = atoi(tokens[i].c_str());
93 binary_write( *fp, val_uint16);
98 if (vr == "UL" || vr == "SL")
100 // Some 'Integer' fields may be multivaluated (multiple instances
101 // of integer). But each single integer value is separated from the
102 // next one by '\' (backslash character). Hence we split the string
103 // along the '\' and write each value as an int:
104 std::vector<std::string> tokens;
105 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
106 Util::Tokenize (GetValue(), tokens, "\\");
107 for (unsigned int i=0; i<tokens.size();i++)
109 uint32_t val_uint32 = atoi(tokens[i].c_str());
110 binary_write( *fp, val_uint32);
116 gdcmAssertMacro( lgr == GetValue().length() );
117 binary_write(*fp, GetValue());
120 //-----------------------------------------------------------------------------
123 //-----------------------------------------------------------------------------
126 //-----------------------------------------------------------------------------
127 } // end namespace gdcm