The XB alias and const_alias abstract base classes are used by .parse () and .serialize () member functions of xb::element, xb::node and xb::document classes. These member functions and parser functions use classes derived from these classes to read data from sources (raw memory, files, ...) and serialize to.
namespace xb {
class const_alias {
public:
virtual xb::size_type length () = 0;
virtual unsigned char operator * () = 0;
virtual void operator ++ () = 0;
public:
inline void operator++ (int) { this->operator ++ (); };
};
class alias : virtual public const_alias {
public:
virtual void operator = (unsigned char) = 0;
public:
inline void operator |= (unsigned char c) { *this = **this | c; };
inline void operator &= (unsigned char c) { *this = **this & c; };
inline void operator ^= (unsigned char c) { *this = **this ^ c; };
};
};
The xb::const_alias interface is used to implement reading data from sources that can be abstracted into finite sequential access. The alias then acts similary to pointer to the data, but it is required to implement only very restricted set of available operation. The final const_alias object (class derived from xb::const_alias class) is required to implement at least following member functions:
This member function should return number of bytes immediately available for access or zero if the end of the source (or read-write buffer in case of xb::alias) has been reached.
This member function should return current byte. This is the byte to which this virtual pointer points. Initialy this is the first byte of the data. Note that this function may be called multiple times before advancing to next byte, thus should return the same value in such case. When the .length () member function return zero, this member function is no longer called.
This member function is called whenever an advance to next byte is required. The virtual pointer should perform whatever neccessary to return next byte of the data in subsequent call to .operator * () member function.
The xb::alias interface is used to implement read-write access to a data source. When used in .serialize () member function, it is actualy accessed for write only.
This member function is called to update the value of current byte the alias points to. Calling this member function must not change the pointer position.
Two small and simple classes to access memory buffers through aliases are already implemented:
namespace xb {
class buffer_alias : virtual public alias {
public:
buffer_alias (unsigned char *, xb::size_type);
public:
virtual xb::size_type length ();
virtual unsigned char operator * ();
virtual void operator ++ ();
virtual void operator = (unsigned char);
};
class const_buffer_alias : virtual public const_alias {
public:
const_buffer_alias (const unsigned char *, xb::size_type);
const_buffer_alias (const buffer_alias &, xb::size_type);
public:
virtual xb::size_type length ();
virtual unsigned char operator * ();
virtual void operator ++ ();
};
};
You can use these classes to read from or write to raw memory buffers instead of writting your own. Check out the xb_file.hpp file to see how are member functions of these classes implemented.
None.
No range checking is required to be implemented. All the parse and serialize member functions will handle the access correctly and will not try to access data beyond its end.
[index]