GDCM 3.0.24
gdcmParser.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: GDCM (Grassroots DICOM). A DICOM library
4
5 Copyright (c) 2006-2011 Mathieu Malaterre
6 All rights reserved.
7 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13=========================================================================*/
14
15#ifndef GDCMPARSER_H
16#define GDCMPARSER_H
17
18#include "gdcmTag.h"
19#error do not use
20#include "gdcmByteBuffer.h"
21
22#include <fstream> // std::ifstream
23
24namespace gdcm
25{
32class GDCM_EXPORT Parser /*: private IStream*/
33{
34public:
46
47 Parser() : UserData(0),Buffer(),ErrorCode(NoError) {}
49
50 // Parse some more of the document. The string s is a buffer containing
51 // part (or perhaps all) of the document. The number of bytes of s that
52 // are part of the document is indicated by len. This means that s
53 // doesn't have to be null terminated. It also means that if len is
54 // larger than the number of bytes in the block of memory that s points
55 // at, then a memory fault is likely. The isFinal parameter informs the
56 // parser that this is the last piece of the document. Frequently, the
57 // last piece is empty (i.e. len is zero.) If a parse error occurred,
58 // it returns 0. Otherwise it returns a non-zero value.
59 bool Parse(const char* s, int len, bool isFinal);
60
61 // Set handlers for start and end tags. Attributes are passed to the
62 // start handler as a pointer to a vector of char pointers. Each
63 // attribute seen in a start (or empty) tag occupies 2 consecutive places
64 // in this vector: the attribute name followed by the attribute value.
65 // These pairs are terminated by a null pointer.
66 typedef void (*StartElementHandler) (void *userData,
67 const Tag &tag,
68 const char *atts[]);
69 typedef void (*EndElementHandler) (void *userData, const Tag &name);
70 void SetElementHandler(StartElementHandler start, EndElementHandler end);
71
72 // Return what type of error has occurred.
74
75 // Return a string describing the error corresponding to code.
76 // The code should be one of the enums that can be returned from
77 // GetErrorCode.
78 static const char *GetErrorString(ErrorType const &err);
79
80 // Return the byte offset of the position.
81 unsigned long GetCurrentByteIndex() const;
82
83 // Miscellaneous functions
84
85 // The functions in this section either obtain state information from
86 // the parser or can be used to dynamically set parser options.
87
88 // This sets the user data pointer that gets passed to handlers.
89 void SetUserData(void *userData);
90
91 // This returns the user data pointer that gets passed to handlers.
92 void * GetUserData() const;
93
94protected:
95
96 // This is just like Parse, except in this case expat provides the buffer.
97 // By obtaining the buffer from expat with the GetBuffer function,
98 // the application can avoid double copying of the input.
99 bool ParseBuffer(int len, bool isFinal);
100
101 // Obtain a buffer of size len to read a piece of the document into.
102 // A NULL value is returned if expat can't allocate enough memory for
103 // this buffer. This has to be called prior to every call to ParseBuffer.
104 char *GetBuffer(int len);
105
107
108private:
109 std::ifstream Stream;
110 void* UserData;
111 ByteBuffer Buffer;
112 ErrorType ErrorCode;
113
114 StartElementHandler StartElement;
115 EndElementHandler EndElement;
116};
117
118} // end namespace gdcm
119
120#endif //GDCMPARSER_H
ByteBuffer.
Definition gdcmByteBuffer.h:35
Parser ala XML_Parser from expat (SAX)
Definition gdcmParser.h:33
Parser()
Definition gdcmParser.h:47
ErrorType Process()
ErrorType
Definition gdcmParser.h:35
@ NoElementsError
Definition gdcmParser.h:39
@ TagMismatchError
Definition gdcmParser.h:40
@ JunkAfterDocElementError
Definition gdcmParser.h:42
@ SyntaxError
Definition gdcmParser.h:38
@ DuplicateAttributeError
Definition gdcmParser.h:41
@ NoError
Definition gdcmParser.h:36
@ UndefinedEntityError
Definition gdcmParser.h:43
@ NoMemoryError
Definition gdcmParser.h:37
void SetUserData(void *userData)
unsigned long GetCurrentByteIndex() const
void SetElementHandler(StartElementHandler start, EndElementHandler end)
bool ParseBuffer(int len, bool isFinal)
void * GetUserData() const
static const char * GetErrorString(ErrorType const &err)
ErrorType GetErrorCode() const
char * GetBuffer(int len)
bool Parse(const char *s, int len, bool isFinal)
~Parser()
Definition gdcmParser.h:48
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
#define GDCM_EXPORT
Definition gdcmWin32.h:34
Definition gdcmASN1.h:21