Go to the documentation of this file.
11 #ifndef GAUDIKERNEL_STREAMBUFFER_H
12 #define GAUDIKERNEL_STREAMBUFFER_H 1
67 else if (
stream.isWriting() )
110 ( *m_stream ) <<
stream.buffPointer();
183 template <
class TYPE>
188 refpObject =
dynamic_cast<TYPE*
>( pObj );
194 template <
class TYPE>
199 refpObject =
dynamic_cast<TYPE*
>( pObj );
227 m_length = ( len < 16384 ) ? 16384 : len;
237 if (
m_length < len ) new_len += len;
308 #ifdef USE_STREAM_ANALYSER
309 # define STREAM_ANALYSE( data, len ) \
310 if ( 0 != m_analyzer ) m_analyzer( &data, len, typeid( data ) )
312 # define STREAM_ANALYSE( data, len )
316 #define IMPLEMENT_STREAMER( TYPE ) \
318 StreamBuffer& operator<<( TYPE data ) { \
319 swapToBuffer( &data, sizeof( data ) ); \
320 STREAM_ANALYSE( data, sizeof( data ) ); \
324 StreamBuffer& operator>>( TYPE& data ) { \
325 swapFromBuffer( &data, sizeof( data ) ); \
330 #undef IMPLEMENT_STREAMER
462 const char* ptr = 0 ==
data ?
"" :
data;
463 size_t len = strlen( ptr ) + 1;
479 const char* ptr =
data.c_str();
480 long len =
data.length();
493 template <
class TYPE>
534 #undef STREAM_ANALYSE
542 #if defined( __alpha ) && !defined( __VMS )
545 #elif defined( __sun ) && defined( __SVR4 ) && defined( __i386 )
548 #elif defined( __APPLE__ )
551 #elif defined( __linux ) && !defined( __powerpc )
554 #elif defined( BORLAND ) || defined( _WIN32 ) || defined( WIN32 )
566 char buff[8], *tar, *src = (
char*)source;
575 for (
int i = 0,
j = siz - 1; i < siz; i++,
j-- ) tar[
j] = src[i];
592 char* tar = (
char*)
target;
600 for (
int i = 0,
j = siz - 1; i < siz; i++,
j-- ) tar[
j] = src[i];
618 for (
const auto& i :
v )
s << i;
628 for ( i = 0; i < len; i++ ) {
640 for (
const auto& i :
l )
s << i;
650 for (
long i = 0; i < len; i++ ) {
657 #endif // GAUDIKERNEL_STREAMBUFFER_H
StreamBuffer & operator<<(const char *data)
Streamer to write strings in (char*) format.
std::istream * m_stream
Reference to input stream.
IdentifiedLinks & identifiedLinks()
Access to identified links.
StreamBuffer & operator<<(const std::string &data)
Streamer to write strings in (std::string) format.
ContainedLink & operator=(const ContainedLink ©)=default
StreamBuffer & operator>>(int &data)
Input Streamer.
const ContainedLinks & containedLinks() const
CONST Access to contained links.
void setBuffPointer(long ptr)
Retrieve current buffer pointer.
char * adopt() const
Remove the data buffer and pass it to client. It's the client responsability to free the memory.
StreamBuffer & operator>>(unsigned char &data)
Input Streamer.
StreamBuffer & operator<<(float data)
Output Streamer.
Definition of the contained link set.
void addIdentifiedLink(const DataObject *pObject, long hint)
char * m_buffer
Pointer to heap buffer.
StreamBuffer(bool do_swap=true)
Standard constructor.
virtual ~DataIO()=default
Standard destructor.
StreamBuffer & operator<<(short data)
Output Streamer.
virtual ~Ostream()=default
Standard Destructor.
void serialize(DataIO &ioObject)
Serialize the buffer using an IO object.
ContainedLinks m_containedLinks
Container with links to contained objects.
SwapAction swapBuffer(int siz) const
Check for byte swapping.
void badStreamMode()
Throw Exception.
virtual void load(StreamBuffer &)
Template function to load stream data.
ContainedLink(ContainedObject *pObj, long hint, long link)
void extend(long len)
Extend the buffer.
StreamBuffer & operator<<(const DataObject *pObject)
Streamer to write links to identified objects.
StreamBuffer & operator<<(unsigned short data)
Output Streamer.
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
StreamBuffer & operator<<(unsigned long data)
Output Streamer.
SwapAction
Data Sawp actions.
long buffPointer() const
Retrieve current buffer pointer.
Definition of the contained link set.
AnalyzeFunction m_analyzer
Hook function for analysis of data to the stream.
StreamBuffer & operator<<(const ContainedObject *pObject)
Streamer to write links to contained objects.
Istream(std::istream &str)
Constructor.
StreamBuffer & operator<<(double data)
Output Streamer.
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
bool m_swapEnabled
Flag indicating swapping.
void(* AnalyzeFunction)(const void *data, int siz, const std::type_info &type)
Definition of the buffer analyzer.
Writer for standard output streams.
virtual void serialize(StreamBuffer &stream)
Serialization method: loads/dumps streambuffer content.
StreamBuffer & operator>>(unsigned short &data)
Input Streamer.
std::vector< IdentifiedLink > IdentifiedLinks
Definition of the identifiable link set.
ContainedLink(const ContainedLink ©)=default
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
IdentifiedLink & operator=(const IdentifiedLink ©)=default
State
Link state defintions.
void load(StreamBuffer &stream) override
Data load method.
StreamBuffer & writeBytes(const char *str, long len)
Write string to output stream.
StreamBuffer & getObjectPointer(const ContainedObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
StreamBuffer & operator<<(StreamBuffer &s, const std::vector< T > &v)
StreamBuffer & operator>>(unsigned long &data)
Input Streamer.
StreamBuffer & getObjectPointer(const DataObject *, TYPE *&refpObject)
Helper to distinguish between identified pointers and contained pointers.
IdentifiedLink(DataObject *pObj, long hint)
ContainedLinks & containedLinks()
Access to contained links.
bool isWriting() const
Get stream buffer state.
StreamBuffer & operator<<(char data)
Output Streamer.
const IdentifiedLinks & identifiedLinks() const
CONST Access to identified links.
void setMode(Mode m)
Set mode of the stream and allocate buffer.
StreamBuffer & operator<<(long data)
Output Streamer.
long size() const
Total buffer size.
void setAnalyzer(AnalyzeFunction fun=nullptr)
Enable user analysis function.
char * data()
write access to data buffer
const char * data() const
Read access to data buffer.
bool isReading() const
Get stream buffer state.
virtual ~StreamBuffer()
Standard destructor.
virtual void dump(StreamBuffer &)
Template function to save stream data.
void reserve(long len)
Reserve buffer space; Default: 16 k buffer size.
StreamBuffer & operator<<(int data)
Output Streamer.
StreamBuffer & operator>>(char *data)
Streamer to read strings in (char*) format.
StreamBuffer & operator>>(float &data)
Input Streamer.
StreamBuffer & operator>>(std::string &data)
Streamer to read strings in (std::string) format.
StreamBuffer & operator<<(long long data)
Output Streamer.
StreamBuffer & operator>>(long &data)
Input Streamer.
Reader for standard input streams.
void dump(StreamBuffer &stream) override
Output dumper.
StreamBuffer & operator>>(double &data)
Input Streamer.
StreamBuffer & operator>>(short &data)
Input Streamer.
long m_length
Total buffer length.
long m_pointer
Current buffer pointer.
void getIdentifiedLink(DataObject *&pObject, long &hint)
void erase()
Reset the buffer.
A small base class to handle generic data streaming.
IdentifiedLink(const IdentifiedLink ©)=default
StreamBuffer & operator>>(TYPE *&refpObject)
Streamer to read links to contained or identified objects.
StreamBuffer & operator>>(StreamBuffer &s, std::vector< T > &v)
DataIO()=default
Standard constructor.
StreamBuffer & operator<<(unsigned char data)
Output Streamer.
StreamBuffer & operator>>(unsigned int &data)
Input Streamer.
#define _swab(source, target, radix)
void addContainedLink(const ContainedObject *pObject, long hint, long link)
#define STREAM_ANALYSE(data, len)
StreamBuffer & operator>>(long long &data)
Input Streamer.
StreamBuffer & operator>>(char &data)
Input Streamer.
std::vector< ContainedLink > ContainedLinks
IdentifiedLinks m_identifiedLinks
Container with links to contained objects.
void getContainedLink(ContainedObject *&pObject, long &hint, long &link)
StreamBuffer & operator<<(unsigned int data)
Output Streamer.
Ostream(std::ostream &str)
Standard constructor: pass reference to stream object.