]> Creatis software - gdcm.git/blob - src/gdcmContentEntry.cxx
2e4530c3b4e7b2d5bd98d5ec16e272fcd3a3447a
[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 15:21:20 $
7   Version:   $Revision: 1.1 $
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 }
43
44 /**
45  * \brief   Constructor from a given DocEntry
46  * @param   e Pointer to existing Doc entry
47  */
48 ContentEntry::ContentEntry(DocEntry *e)
49              : DocEntry(e->GetDictEntry())
50 {
51    Copy(e);
52 }
53
54
55 /**
56  * \brief   Canonical destructor.
57  */
58 ContentEntry::~ContentEntry ()
59 {
60 }
61
62 //-----------------------------------------------------------------------------
63 // Public
64
65 /**
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, ...)
69  */
70 void ContentEntry::WriteContent(std::ofstream *fp, FileType filetype)
71 {
72    DocEntry::WriteContent(fp, filetype);
73
74    if ( GetGroup() == 0xfffe )
75    {
76       return; //delimitors have NO value
77    }
78
79    const VRKey &vr = GetVR();
80    unsigned int lgr = GetLength();
81    if (vr == "US" || vr == "SS")
82    {
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++)
90       {
91          uint16_t val_uint16 = atoi(tokens[i].c_str());
92          binary_write( *fp, val_uint16);
93       }
94       tokens.clear();
95       return;
96    }
97    if (vr == "UL" || vr == "SL")
98    {
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++)
107       {
108          uint32_t val_uint32 = atoi(tokens[i].c_str());
109          binary_write( *fp, val_uint32);
110       }
111       tokens.clear();
112       return;
113    } 
114
115    gdcmAssertMacro( lgr == GetValue().length() );
116    binary_write(*fp, GetValue());
117
118
119 //-----------------------------------------------------------------------------
120 // Protected
121
122 //-----------------------------------------------------------------------------
123 // Private
124
125 //-----------------------------------------------------------------------------
126 } // end namespace gdcm
127