Xerces-C++: MemBufInputSource Class Reference

Xerces-C++ 3.3.0

List of all members
MemBufInputSource Class Reference

This class is a derivative of the standard InputSource class. More...

`#include <xercesc/framework/MemBufInputSource.hpp>`

Inheritance diagram for MemBufInputSource:

## Public Member Functions
Constructors
| MemBufInputSource (const XMLByte *const srcDocBytes, const XMLSize_t byteCount, const XMLCh *const bufId, const bool adoptBuffer=false, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
| A memory buffer input source is constructed from a buffer of byte data, and the count of bytes in that buffer.
| MemBufInputSource (const XMLByte *const srcDocBytes, const XMLSize_t byteCount, const char *const bufId, const bool adoptBuffer=false, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
| This constructor is identical to the previous one, except that it takes the fake system id in local code page form and transcodes it internally.
Destructor
| ~MemBufInputSource ()
| If the buffer was adopted, the copy made during construction is deleted at this point.
Virtual methods
BinInputStream * | makeStream () const
| This method will return a binary input stream derivative that will parse from the memory buffer.
Public Member Functions inherited from InputSource
virtual | ~InputSource ()
| Destructor.
virtual const XMLCh * | getEncoding () const
| An input source can be set to force the parser to assume a particular encoding for the data that input source represents, via the setEncoding() method.
virtual const XMLCh * | getPublicId () const
| Get the public identifier for this input source.
virtual const XMLCh * | getSystemId () const
| Get the system identifier for this input source.
virtual bool | getIssueFatalErrorIfNotFound () const
| Get the flag that indicates if the parser should issue fatal error if this input source is not found.
MemoryManager * | getMemoryManager () const
virtual void | setEncoding (const XMLCh *const encodingStr)
| Set the encoding which will be required for use with the XML text read via a stream opened by this input source.
virtual void | setPublicId (const XMLCh *const publicId)
| Set the public identifier for this input source.
virtual void | setSystemId (const XMLCh *const systemId)
| Set the system identifier for this input source.
virtual void | setIssueFatalErrorIfNotFound (const bool flag)
| Indicates if the parser should issue fatal error if this input source is not found.
Public Member Functions inherited from XMemory
void * | operator new (size_t size)
| This method overrides operator new.
void * | operator new (size_t size, MemoryManager *memMgr)
| This method defines a custom operator new, that will use the provided memory manager to perform the allocation.
void * | operator new (size_t size, void *ptr)
| This method overrides placement operator new.
void | operator delete (void *p)
| This method overrides operator delete.
void | operator delete (void *p, MemoryManager *memMgr)
| This method provides a matching delete for the custom operator new.
void | operator delete (void *p, void *ptr)
| This method provides a matching delete for the placement new.

## Setter methods
void | setCopyBufToStream (const bool newState)
| By default, for safety's sake, each newly created stream from this input source will make its own copy of the buffer to stream from.
void | resetMemBufInputSource (const XMLByte *const srcDocBytes, const XMLSize_t byteCount)
| This methods allows the MemBufInputSource to be used for more than one input source, instead of destructing/constructing another MemBufInputSource.

## Additional Inherited Members
Protected Member Functions inherited from InputSource
| InputSource (MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
| Default constructor.
| InputSource (const XMLCh *const systemId, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
| Constructor with a system identifier as XMLCh type.
| InputSource (const XMLCh *const systemId, const XMLCh *const publicId, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
| Constructor with a system and public identifiers.
| InputSource (const char *const systemId, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
| Constructor witha system identifier as string.
| InputSource (const char *const systemId, const char *const publicId, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
| Constructor witha system and public identifiers.
Protected Member Functions inherited from XMemory
| XMemory ()
| Protected default constructor.

## Detailed Description

This class is a derivative of the standard InputSource class.

It provides for the parser access to data stored in a memory buffer. The type of buffer and its host specific attributes are of little concern here. The only real requirement is that the memory be readable by the current process.

Note that the memory buffer size is expressed in bytes, not in characters. If you pass it text data, you must account for the bytes per character when indicating the buffer size.

As with all InputSource derivatives. The primary objective of an input source is to create an input stream via which the parser can spool in data from the referenced source. In this case, there are two options available.

The passed buffer can be adopted or merely referenced. If it is adopted, then it must be dynamically allocated and will be destroyed when the input source is destroyed (no reference counting!.) Note that the deallocation assumes that array deletion should be performed, so do not pass a non-array-allocated buffer if asking for adoption. If not adopted, the caller must insure that it remains valid until the input source object is destroyed.

The other option indicates whether each stream created for this input source should get its own copy of the data, or whether it should just stream the data directly from this object's copy of the data. The same rules apply here, in that the buffer must either be copied by the stream or it must remain valid until the stream is destroyed.

## Constructor & Destructor Documentation

## ◆ MemBufInputSource() [1/2]

MemBufInputSource::MemBufInputSource | ( | const XMLByte *const | srcDocBytes,
|  | const XMLSize_t | byteCount,
|  | const XMLCh *const | bufId,
|  | const bool | adoptBuffer = false,
|  | MemoryManager *const | manager = XMLPlatformUtils::fgMemoryManager )

A memory buffer input source is constructed from a buffer of byte data, and the count of bytes in that buffer.

The parser will parse from this memory buffer until it has eaten the indicated number of bytes.

Note that the system id provided serves two purposes. Firstly it is going to be displayed in error messages as the source of the error. And secondly, any entities which are referred to from this entity via relative paths/URLs will be relative to this fake system id.

Parameters

  srcDocBytes | The actual data buffer to be parsed from.
  byteCount | The count of bytes (not characters, bytes!) in the buffer.
  bufId | A fake system id for the buffer.
  adoptBuffer | Indicates whether this object should adopt the buffer (i.e. become responsible for deletion) or just use it in place.
  manager | Pointer to the memory manager to be used to allocate objects.

## ◆ MemBufInputSource() [2/2]

MemBufInputSource::MemBufInputSource | ( | const XMLByte *const | srcDocBytes,
|  | const XMLSize_t | byteCount,
|  | const char *const | bufId,
|  | const bool | adoptBuffer = false,
|  | MemoryManager *const | manager = XMLPlatformUtils::fgMemoryManager )

This constructor is identical to the previous one, except that it takes the fake system id in local code page form and transcodes it internally.

## ◆ ~MemBufInputSource()

MemBufInputSource::~MemBufInputSource | ( |  | ) |

If the buffer was adopted, the copy made during construction is deleted at this point.

## Member Function Documentation

## ◆ makeStream()

BinInputStream * MemBufInputSource::makeStream | ( |  | ) | const
| virtual

This method will return a binary input stream derivative that will parse from the memory buffer.

If setCopyBufToStream() has been set, then the stream will make its own copy. Otherwise, it will use the buffer as is (in which case it must remain valid until the stream is no longer in use, i.e. the parse completes.)

Returns
  A dynamically allocated binary input stream derivative that can parse from the memory buffer.

Implements InputSource.

## ◆ resetMemBufInputSource()

void MemBufInputSource::resetMemBufInputSource | ( | const XMLByte *const | srcDocBytes,
|  | const XMLSize_t | byteCount )

This methods allows the MemBufInputSource to be used for more than one input source, instead of destructing/constructing another MemBufInputSource.

Parameters

  srcDocBytes | The actual data buffer to be parsed from.
  byteCount | The count of bytes (not characters, bytes!) in the buffer.

## ◆ setCopyBufToStream()

void MemBufInputSource::setCopyBufToStream | ( | const bool | newState | ) |

By default, for safety's sake, each newly created stream from this input source will make its own copy of the buffer to stream from.

This avoids having to deal with aliasing of the buffer for simple work. But, for higher performance applications or for large buffers, this is obviously not optimal.

In such cases, you can call this method to turn off that default action. Once turned off, the streams will just get a pointer to the buffer and parse directly from that. In this case, you must insure that the buffer remains valid for as long as any parse events are still using it.

Parameters

  newState | The new boolean flag state to set.

The documentation for this class was generated from the following file:

- MemBufInputSource.hpp