Source: OmByteArrayNode.h
|
|
|
|
#ifndef OM_BYTE_ARRAY_NODE_H
#define OM_BYTE_ARRAY_NODE_H
/**
* The byte array final node structure.
*
* This class provides a specialization of OmFinalNode to implement the ByteArray node construction.
* This corresponds to a sequence of characters that is a base 64 encoding of the data.
* This is encoded as <OMB> representation </OMB>
* The list of children must always be empty.
*/
class OmByteArrayNode : public OmFinalNode
{
public:
/**
* Default constructor.
*/
OmByteArrayNode()
: buffer_(new char[0]), length_(0) {}
/**
* Constructor (can be used as default).
* @li Precondition: ~ NullPointer(buffer_in)
*/
OmByteArrayNode(const char * buffer_in, unsigned int length_in) {
OmException::checkNullPointer(buffer_in);
buffer_ = (char *)memcpy(new char[length_in], buffer_in, length_in);
length_ = length_in; }
/**
* Get the buffer with its length.
*/
virtual void getBuffer(const char *& buffer_out, unsigned int & length_out) const {
buffer_out = buffer_;
length_out = length_; }
/**
* Set the buffer with its length.
* @li Precondition: ~ NullPointer(buffer_in)
*/
virtual void setBufferLength(const char * buffer_in, unsigned int length_in) {
OmException::checkNullPointer(buffer_in);
delete[] buffer_;
buffer_= (char *)memcpy(new char[length_in], buffer_in, length_in);
length_ = length_in; }
protected:
/**
* Copy constructor.
*/
OmByteArrayNode(const OmByteArrayNode & other_in)
: OmFinalNode(other_in),
buffer_((char *)memcpy(new char[other_in.length_], other_in.buffer_, other_in.length_)),
length_(other_in.length_) {}
/**
* Destructor.
*/
virtual ~OmByteArrayNode() {
delete[] buffer_; }
/**
* Implement access to the concrete type.
*/
virtual OmType typeImp() const {
return OmByteArrayType; }
/**
* Implement the deep cloning.
*/
virtual OmNode * cloneImp() const {
return new OmByteArrayNode(*this); }
/**
* Implement the writing to an output device.
*/
virtual void writeImp(OmOutputDevice & output_in) const {
output_in.writeByteArray(buffer_, length_); }
/**
* Implement the reading from an input device.
*/
virtual void readImp(OmInputDevice & input_in) {
input_in.readLength(length_);
delete[] buffer_;
buffer_ = new char[length_];
input_in.readByteArray(buffer_, length_); }
private:
char * buffer_;
unsigned int length_;
};
#endif // OM_BYTE_ARRAY_NODE_H
Generated by: root@localhost.localdomain on Tue Oct 12 21:02:30 199. |