]> Creatis software - gdcm.git/blob - src/gdcmContentEntry.cxx
* src/gdcmDocEntrySet.cxx : Bug fix when getting the value
[gdcm.git] / src / gdcmContentEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmContentEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/25 16:32:45 $
7   Version:   $Revision: 1.2 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmContentEntry.h"
20 #include "gdcmVR.h"
21 #include "gdcmTS.h"
22 #include "gdcmGlobal.h"
23 #include "gdcmUtil.h"
24 #include "gdcmDebug.h"
25
26 #include <fstream>
27
28 namespace gdcm 
29 {
30
31 // CLEAN ME
32 #define MAX_SIZE_PRINT_ELEMENT_VALUE 128
33
34 //-----------------------------------------------------------------------------
35 // Constructor / Destructor
36 /**
37  * \brief   Constructor from a given DictEntry
38  * @param   e Pointer to existing dictionary entry
39  */
40 ContentEntry::ContentEntry(DictEntry *e) : DocEntry(e)
41 {
42    Value = GDCM_UNFOUND;
43 }
44
45 /**
46  * \brief   Constructor from a given DocEntry
47  * @param   e Pointer to existing Doc entry
48  */
49 ContentEntry::ContentEntry(DocEntry *e)
50              : DocEntry(e->GetDictEntry())
51 {
52    Copy(e);
53 }
54
55
56 /**
57  * \brief   Canonical destructor.
58  */
59 ContentEntry::~ContentEntry ()
60 {
61 }
62
63 //-----------------------------------------------------------------------------
64 // Public
65
66 /**
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, ...)
70  */
71 void ContentEntry::WriteContent(std::ofstream *fp, FileType filetype)
72 {
73    DocEntry::WriteContent(fp, filetype);
74
75    if ( GetGroup() == 0xfffe )
76    {
77       return; //delimitors have NO value
78    }
79
80    const VRKey &vr = GetVR();
81    unsigned int lgr = GetLength();
82    if (vr == "US" || vr == "SS")
83    {
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++)
91       {
92          uint16_t val_uint16 = atoi(tokens[i].c_str());
93          binary_write( *fp, val_uint16);
94       }
95       tokens.clear();
96       return;
97    }
98    if (vr == "UL" || vr == "SL")
99    {
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++)
108       {
109          uint32_t val_uint32 = atoi(tokens[i].c_str());
110          binary_write( *fp, val_uint32);
111       }
112       tokens.clear();
113       return;
114    } 
115
116    gdcmAssertMacro( lgr == GetValue().length() );
117    binary_write(*fp, GetValue());
118
119
120 //-----------------------------------------------------------------------------
121 // Protected
122
123 //-----------------------------------------------------------------------------
124 // Private
125
126 //-----------------------------------------------------------------------------
127 } // end namespace gdcm
128