2 #ifndef GAUDIKERNEL_STREAMBUFFER_H
3 #define GAUDIKERNEL_STREAMBUFFER_H 1
53 throw(
"Not acceptable stream mode!");
192 refpObject =
dynamic_cast<TYPE*
>(pObj);
202 refpObject =
dynamic_cast<TYPE*
>(pObj);
235 m_length = (len < 16384) ? 16384 : len;
245 if (
m_length < len ) new_len += len;
336 #ifdef USE_STREAM_ANALYSER
337 #define STREAM_ANALYSE(data, len) if ( 0 != m_analyzer ) m_analyzer(&data, len, typeid(data))
339 #define STREAM_ANALYSE(data, len)
343 #define IMPLEMENT_STREAMER(TYPE) \
345 StreamBuffer& operator<<(TYPE data) { \
346 swapToBuffer(&data, sizeof(data)); \
347 STREAM_ANALYSE(data, sizeof(data)); \
351 StreamBuffer& operator>>(TYPE & data) { \
352 swapFromBuffer(&data, sizeof(data)); \
357 #undef IMPLEMENT_STREAMER
484 for ( i = 0, data[0]=0; i < len; i++ ) {
491 const char* ptr = 0 == data ?
"" :
data;
492 int len = strlen(ptr)+1;
504 for ( i = 0, data =
""; i < len; i++ ) {
512 const char* ptr = data.c_str();
513 long len = data.length();
567 #undef STREAM_ANALYSE
575 #if defined(__alpha) && !defined(__VMS)
578 #elif defined(__sun) && defined(__SVR4) && defined(__i386)
581 #elif defined(__APPLE__)
584 #elif defined(__linux) && !defined(__powerpc)
587 #elif defined(BORLAND) || defined(_WIN32) || defined(WIN32)
599 char buff[8], *tar, *src = (
char*)source;
608 for(
int i = 0,j = siz-1;
i<siz;
i++,j--) tar[j] = src[
i];
615 memcpy(tar, src, siz);
623 char* tar = (
char*)target;
631 for(
int i = 0,j = siz-1;
i<siz;
i++,j--) tar[j] = src[
i];
637 ::memcpy(tar, src, siz);
644 template <
class T>
inline
647 for (
typename std::vector<T>::const_iterator
i = v.begin();
i != v.end();
i++ ) {
654 template <
class T>
inline
659 for ( i = 0; i < len; i++ ) {
668 template <
class T>
inline
671 for (
typename std::list<T>::const_iterator
i =
l.begin();
i !=
l.end();
i++ ) {
678 template <
class T>
inline
683 for ( i = 0; i < len; i++ ) {
690 #endif // GAUDIKERNEL_STREAMBUFFER_H
virtual void load(StreamBuffer &)
Template function to load stream data.
Definition of the contained link set.
Writer for standard output streams.
StreamBuffer(bool do_swap=true)
Standard constructor.
virtual ~DataIO()
Standard destructor.
virtual void serialize(StreamBuffer &stream)
Serialization method: loads/dumps streambuffer content.
StreamBuffer & operator<<(const char *data)
Streamer to write strings in (char*) format.
long buffPointer() const
Retrieve current buffer pointer.
StreamBuffer & operator>>(long &data)
Input Streamer.
StreamBuffer & operator>>(unsigned short &data)
Input Streamer.
Ostream(std::ostream &str)
Standard constructor: pass reference to stream object.
StreamBuffer & operator<<(double data)
Output Streamer.
std::istream * m_stream
Reference to input stream.
StreamBuffer & operator<<(float data)
Output Streamer.
StreamBuffer & operator<<(const DataObject *pObject)
Streamer to write links to identified objects.
The stream buffer is a small object collecting object data.
StreamBuffer & operator>>(float &data)
Input Streamer.
SwapAction
Data Sawp actions.
ContainedLinks m_containedLinks
Container with links to contained objects.
ContainedLink(const ContainedLink ©)
virtual ~Istream()
Destructor.
Istream(std::istream &str)
Constructor.
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
virtual void dump(StreamBuffer &)
Template function to save stream data.
long m_length
Total buffer length.
IdentifiedLinks & identifiedLinks()
Access to identified links.
char * m_buffer
Pointer to heap buffer.
void extend(long len)
Extend the buffer.
StreamBuffer & operator<<(const ContainedObject *pObject)
Streamer to write links to contained objects.
StreamBuffer & operator>>(char *data)
Streamer to read strings in (char*) format.
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
bool isReading() const
Get stream buffer state.
std::vector< ContainedLink > ContainedLinks
virtual void load(StreamBuffer &stream)
Data load method.
StreamBuffer & operator<<(unsigned long data)
Output Streamer.
StreamBuffer & operator<<(unsigned short data)
Output Streamer.
Reader for standard input streams.
const char * data() const
Read access to data buffer.
void(* AnalyzeFunction)(const void *data, int siz, const std::type_info &type)
Definition of the buffer analyzer.
char * data()
write access to data buffer
void setBuffPointer(long ptr)
Retrieve current buffer pointer.
StreamBuffer & operator>>(unsigned char &data)
Input Streamer.
virtual ~Ostream()
Standard Destructor.
StreamBuffer & operator<<(int data)
Output Streamer.
StreamBuffer & operator>>(longlong &data)
Input Streamer.
void reserve(long len)
Reserve buffer space; Default: 16 k buffer size.
StreamBuffer & operator>>(StreamBuffer &s, std::vector< T > &v)
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
#define STREAM_ANALYSE(data, len)
const IdentifiedLinks & identifiedLinks() const
CONST Access to identified links.
ContainedLinks & containedLinks()
Access to contained links.
StreamBuffer & operator<<(long data)
Output Streamer.
StreamBuffer & operator<<(unsigned char data)
Output Streamer.
StreamBuffer & operator<<(longlong data)
Output Streamer.
StreamBuffer & operator<<(short data)
Output Streamer.
StreamBuffer & getObjectPointer(const ContainedObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
ContainedLink(ContainedObject *pObj, long hint, long link)
StreamBuffer & operator<<(const std::string &data)
Streamer to write strings in (std::string) format.
IdentifiedLink(const IdentifiedLink ©)
void badStreamMode()
Throw Exception.
void setAnalyzer(AnalyzeFunction fun=0)
Enable user analysis function.
StreamBuffer & operator>>(char &data)
Input Streamer.
StreamBuffer & operator>>(unsigned long &data)
Input Streamer.
#define _swab(source, target, radix)
void addIdentifiedLink(const DataObject *pObject, long hint)
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
bool isWriting() const
Get stream buffer state.
long m_pointer
Current buffer pointer.
A small base class to handle generic data streaming.
double fun(const std::vector< double > &x)
State
Link state defintions.
DataIO()
Standard constructor.
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
virtual ~StreamBuffer()
Standard destructor.
virtual void dump(StreamBuffer &stream)
Output dumper.
void erase()
Reset the buffer.
StreamBuffer & operator<<(unsigned int data)
Output Streamer.
StreamBuffer & operator>>(std::string &data)
Streamer to read strings in (std::string) format.
Definition of the contained link set.
StreamBuffer & operator<<(char data)
Output Streamer.
void setMode(Mode m)
Set mode of the stream and allocate buffer.
StreamBuffer & getObjectPointer(const DataObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
StreamBuffer & operator>>(unsigned int &data)
Input Streamer.
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
A DataObject is the base class of any identifiable object on any data store.
SwapAction swapBuffer(int siz) const
Check for byte swapping.
StreamBuffer & operator>>(double &data)
Input Streamer.
void addContainedLink(const ContainedObject *pObject, long hint, long link)
void getContainedLink(ContainedObject *&pObject, long &hint, long &link)
long size() const
Total buffer size.
StreamBuffer & operator>>(int &data)
Input Streamer.
std::vector< IdentifiedLink > IdentifiedLinks
Definition of the identifiable link set.
void serialize(DataIO &ioObject)
Serialize the buffer using an IO object.
const ContainedLinks & containedLinks() const
CONST Access to contained links.
bool m_swapEnabled
Flag indicating swapping.
StreamBuffer & operator>>(short &data)
Input Streamer.
void getIdentifiedLink(DataObject *&pObject, long &hint)
StreamBuffer & operator>>(TYPE *&refpObject)
Streamer to read links to contained or identified objects.
IdentifiedLink(DataObject *pObj, long hint)
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.