Update of /cvsroot/cppunit/cppunit2/include/opentest
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9787/include/opentest
Added Files:
serializer.h
Log Message:
- serialization layer on top of growing buffer for one way communication.
--- NEW FILE: serializer.h ---
#ifndef OPENTEST_SERIALIZER_H_INCLUDED
# define OPENTEST_SERIALIZER_H_INCLUDED
# include <opentest/forwards.h>
# include <opentest/properties.h>
# include <map>
# include <vector>
namespace OpenTest {
#ifndef CPPTL_NO_INT64
typedef CppTL::int64_t LargestInt;
typedef CppTL::uint64_t LargestUnsignedInt;
#else
typedef int LargestInt;
typedef unsigned int LargestUnsignedInt;
#endif
class Stream
{
public:
Stream();
virtual ~Stream();
// Call this to add buffer to be "read". Reset read cursor on the first buffer.
void addBuffer( unsigned int length, const void *data );
void startsWriteNewMessage();
Stream &operator <<( bool value );
Stream &operator <<( int value );
Stream &operator <<( unsigned int value );
#ifndef CPPTL_NO_INT64
Stream &operator <<( CppTL::int64_t value );
Stream &operator <<( CppTL::uint64_t value );
#endif
Stream &operator <<( double value );
Stream &operator <<( const String &str );
Stream &operator <<( const Properties &properties );
Stream &operator <<( const Value &value );
Stream &operator >>( bool &value );
Stream &operator >>( int &value );
Stream &operator >>( unsigned int &value );
#ifndef CPPTL_NO_INT64
Stream &operator >>( LargestInt &value );
Stream &operator >>( LargestUnsignedInt &value );
#endif
Stream &operator >>( double &value );
Stream &operator >>( String &str );
Stream &operator >>( Properties &properties );
Stream &operator >>( Value &value );
bool inError() const;
Stream &setError( const char *errorMessage );
private:
void doSerializeInteger( unsigned char kind,
LargestUnsignedInt value );
void doUnserializeInteger( LargestUnsignedInt &value );
void saveDictionnaryEntry( const String &str );
void readDictionnaryEntry( unsigned char control,
String &str );
void readString( String &str );
unsigned char readNextByte();
void ungetLastByte();
void read( void *buffer, unsigned int length );
void write( const void *buffer, unsigned int length );
void write( unsigned char byte );
static bool isNamedPropertyControl( unsigned char control );
private:
struct BufferData
{
unsigned int length_;
unsigned char *data_;
};
typedef std::vector<BufferData> Buffers;
Buffers buffers_;
Buffers::iterator current_;
unsigned char *currentData_;
unsigned char *endData_;
unsigned int writeBufferSize_;
typedef std::map<String,unsigned int> IndexesByString;
typedef std::deque<String> StringsByIndex;
IndexesByString indexesByString_;
StringsByIndex stringsByIndex_;
char stringBuffer_[4096];
const char *error_;
};
template<class SequenceType>
Stream &serializeSTLSequence( Stream &stream, const SequenceType &sequence )
{
typedef CPPTL_TYPENAME SequenceType::const_iterator it = sequence.begin();
typedef CPPTL_TYPENAME SequenceType::const_iterator itEnd = sequence.end();
unsigned int size = itEnd - it;
stream << size;
for ( ; it != itEnd; ++it )
stream << *it;
return stream;
}
template<class SequenceType>
Stream &unserializeSTLSequence( Stream &stream, const SequenceType &sequence )
{
unsigned int size;
stream >> size;
sequence.resize( size );
typedef CPPTL_TYPENAME SequenceType::const_iterator it = sequence.begin();
typedef CPPTL_TYPENAME SequenceType::const_iterator itEnd = sequence.end();
for ( ; it != itEnd; ++it )
stream >> *it;
return stream;
}
} // namespace OpenTest
#endif // OPENTEST_SERIALIZER_H_INCLUDED
|