gdcmParser.h
Go to the documentation of this file.
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef GDCMPARSER_H
#define GDCMPARSER_H
#include "gdcmTag.h"
#error do not use
#include "gdcmByteBuffer.h"
#include <fstream> // std::ifstream
namespace gdcm
{
class GDCM_EXPORT Parser /*: private IStream*/
{
public:
typedef enum {
NoError,
NoMemoryError,
SyntaxError,
NoElementsError,
TagMismatchError,
DuplicateAttributeError,
JunkAfterDocElementError,
UndefinedEntityError,
UnexpectedStateError
} ErrorType;
Parser() : UserData(0),Buffer(),ErrorCode(NoError) {}
~Parser() {}
// Parse some more of the document. The string s is a buffer containing
// part (or perhaps all) of the document. The number of bytes of s that
// are part of the document is indicated by len. This means that s
// doesn't have to be null terminated. It also means that if len is
// larger than the number of bytes in the block of memory that s points
// at, then a memory fault is likely. The isFinal parameter informs the
// parser that this is the last piece of the document. Frequently, the
// last piece is empty (i.e. len is zero.) If a parse error occurred,
// it returns 0. Otherwise it returns a non-zero value.
bool Parse(const char* s, int len, bool isFinal);
// Set handlers for start and end tags. Attributes are passed to the
// start handler as a pointer to a vector of char pointers. Each
// attribute seen in a start (or empty) tag occupies 2 consecutive places
// in this vector: the attribute name followed by the attribute value.
// These pairs are terminated by a null pointer.
typedef void (*StartElementHandler) (void *userData,
const Tag &tag,
const char *atts[]);
typedef void (*EndElementHandler) (void *userData, const Tag &name);
void SetElementHandler(StartElementHandler start, EndElementHandler end);
// Return what type of error has occurred.
ErrorType GetErrorCode() const;
// Return a string describing the error corresponding to code.
// The code should be one of the enums that can be returned from
// GetErrorCode.
static const char *GetErrorString(ErrorType const &err);
// Return the byte offset of the position.
unsigned long GetCurrentByteIndex() const;
// Miscellaneous functions
// The functions in this section either obtain state information from
// the parser or can be used to dynamically set parser options.
// This sets the user data pointer that gets passed to handlers.
void SetUserData(void *userData);
// This returns the user data pointer that gets passed to handlers.
void * GetUserData() const;
protected:
// This is just like Parse, except in this case expat provides the buffer.
// By obtaining the buffer from expat with the GetBuffer function,
// the application can avoid double copying of the input.
bool ParseBuffer(int len, bool isFinal);
// Obtain a buffer of size len to read a piece of the document into.
// A NULL value is returned if expat can't allocate enough memory for
// this buffer. This has to be called prior to every call to ParseBuffer.
char *GetBuffer(int len);
ErrorType Process();
private:
std::ifstream Stream;
void* UserData;
ByteBuffer Buffer;
ErrorType ErrorCode;
StartElementHandler StartElement;
EndElementHandler EndElement;
};
} // end namespace gdcm
#endif //GDCMPARSER_H
gdcm::ByteBuffer
ByteBuffer.
Definition gdcmByteBuffer.h:35
gdcm::Parser::Parser
Parser()
Definition gdcmParser.h:47
gdcm::Parser::Process
ErrorType Process()
gdcm::Parser::ErrorType
ErrorType
Definition gdcmParser.h:35
gdcm::Parser::NoElementsError
@ NoElementsError
Definition gdcmParser.h:39
gdcm::Parser::TagMismatchError
@ TagMismatchError
Definition gdcmParser.h:40
gdcm::Parser::JunkAfterDocElementError
@ JunkAfterDocElementError
Definition gdcmParser.h:42
gdcm::Parser::SyntaxError
@ SyntaxError
Definition gdcmParser.h:38
gdcm::Parser::DuplicateAttributeError
@ DuplicateAttributeError
Definition gdcmParser.h:41
gdcm::Parser::NoError
@ NoError
Definition gdcmParser.h:36
gdcm::Parser::UndefinedEntityError
@ UndefinedEntityError
Definition gdcmParser.h:43
gdcm::Parser::NoMemoryError
@ NoMemoryError
Definition gdcmParser.h:37
gdcm::Parser::UnexpectedStateError
@ UnexpectedStateError
Definition gdcmParser.h:44
gdcm::Parser::SetUserData
void SetUserData(void *userData)
gdcm::Parser::GetCurrentByteIndex
unsigned long GetCurrentByteIndex() const
gdcm::Parser::SetElementHandler
void SetElementHandler(StartElementHandler start, EndElementHandler end)
gdcm::Parser::ParseBuffer
bool ParseBuffer(int len, bool isFinal)
gdcm::Parser::GetUserData
void * GetUserData() const
gdcm::Parser::GetErrorString
static const char * GetErrorString(ErrorType const &err)
gdcm::Parser::StartElementHandler
void(* StartElementHandler)(void *userData, const Tag &tag, const char *atts[])
Definition gdcmParser.h:66
gdcm::Parser::GetErrorCode
ErrorType GetErrorCode() const
gdcm::Parser::GetBuffer
char * GetBuffer(int len)
gdcm::Parser::EndElementHandler
void(* EndElementHandler)(void *userData, const Tag &name)
Definition gdcmParser.h:69
gdcm::Parser::Parse
bool Parse(const char *s, int len, bool isFinal)
gdcm::Parser::~Parser
~Parser()
Definition gdcmParser.h:48
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcmByteBuffer.h
gdcmTag.h
GDCM_EXPORT
#define GDCM_EXPORT
Definition gdcmWin32.h:34
gdcm
Definition gdcmASN1.h:21