00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GDCMDOCUMENT_H
00020 #define GDCMDOCUMENT_H
00021
00022 #include "gdcmVR.h"
00023 #include "gdcmDict.h"
00024 #include "gdcmElementSet.h"
00025 #include "gdcmException.h"
00026
00027
00028 #include <map>
00029 #include <list>
00030 #include <fstream>
00031
00032 namespace gdcm
00033 {
00034 class ValEntry;
00035 class BinEntry;
00036 class SeqEntry;
00037 class Dict;
00038
00039
00043 class GDCM_EXPORT Document : public ElementSet
00044 {
00045 public:
00046
00047 typedef std::list<Element> ListElements;
00048
00049
00050 Dict *GetPubDict();
00051 Dict *GetShaDict();
00052 bool SetShaDict(Dict *dict);
00053 bool SetShaDict(DictKey const &dictName);
00054
00055
00056 virtual bool IsReadable();
00057 bool IsDicomV3();
00058 bool IsPapyrus();
00059 FileType GetFileType();
00060 std::string GetTransferSyntax();
00062 std::string GetTransferSyntaxName();
00063
00064
00066 int GetSwapCode() { return SwapCode; }
00067
00068 uint16_t SwapShort(uint16_t);
00069 uint32_t SwapLong(uint32_t);
00072 uint16_t UnswapShort(uint16_t a) { return SwapShort(a);}
00075 uint32_t UnswapLong(uint32_t a) { return SwapLong(a);}
00076
00077
00079 const std::string &GetFileName() const { return Filename; }
00081 void SetFileName(std::string const &fileName) { Filename = fileName; }
00082
00083 std::ifstream *OpenFile();
00084 bool CloseFile();
00085 void WriteContent( std::ofstream *fp, FileType type );
00086
00087
00088 virtual void LoadEntryBinArea(uint16_t group, uint16_t elem);
00089 virtual void LoadEntryBinArea(BinEntry *entry);
00090
00091 void LoadDocEntrySafe(DocEntry *entry);
00092
00093
00094 bool operator<(Document &document);
00095
00096 protected:
00097
00098
00099
00100
00101 Document();
00102 Document( std::string const &filename );
00103 virtual ~Document();
00104
00105 uint16_t ReadInt16() throw ( FormatError );
00106 uint32_t ReadInt32() throw ( FormatError );
00107 void SkipBytes(uint32_t);
00108 int ComputeGroup0002Length( FileType filetype );
00109
00110
00112 std::string Filename;
00113
00126 int SwapCode;
00127
00129 bool Group0002Parsed;
00130
00132 bool HasDCMPreamble;
00133
00135 std::ifstream *Fp;
00136
00138 FileType Filetype;
00139
00141 static const unsigned int HEADER_LENGTH_TO_READ;
00144 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
00147 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
00148
00150 ListElements AnonymizeList;
00151
00152 private:
00153
00154 void Initialize();
00155
00156
00157 void ParseDES(DocEntrySet *set,long offset, long l_max, bool delim_mode);
00158 void ParseSQ (SeqEntry *seq, long offset, long l_max, bool delim_mode);
00159
00160 void LoadDocEntry (DocEntry *e);
00161 void FindDocEntryLength (DocEntry *e) throw ( FormatError );
00162 uint32_t FindDocEntryLengthOBOrOW() throw( FormatUnexpected );
00163 std::string FindDocEntryVR();
00164 bool CheckDocEntryVR (VRKey k);
00165
00166 std::string GetDocEntryValue (DocEntry *entry);
00167 std::string GetDocEntryUnvalue(DocEntry *entry);
00168
00169 void SkipDocEntry (DocEntry *entry);
00170 void SkipToNextDocEntry (DocEntry *entry);
00171
00172 void FixDocEntryFoundLength(DocEntry *entry,uint32_t l);
00173 bool IsDocEntryAnInteger (DocEntry *entry);
00174
00175 bool CheckSwap();
00176 void SwitchByteSwapCode();
00177 void SetMaxSizeLoadEntry(long);
00178 void SetMaxSizePrintEntry(long);
00179
00180
00181 DocEntry *ReadNextDocEntry();
00182
00183 void HandleBrokenEndian (uint16_t &group, uint16_t &elem);
00184 void HandleOutOfGroup0002(uint16_t &group, uint16_t &elem);
00185
00186
00188 Dict *RefPubDict;
00191 Dict *RefShaDict;
00192
00197 uint32_t MaxSizeLoadEntry;
00198
00202 uint32_t MaxSizePrintEntry;
00203
00204
00205
00206
00207
00208
00209 };
00210
00211 }
00212
00213
00214 #endif