From f55b26080c85ea0432a468aa793886d019e1e8c2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 6 Apr 2012 15:24:11 +0000 Subject: The Qt API now supports cloning. --- c++-qt/src/boolean.cpp | 5 +++++ c++-qt/src/boolean.h | 2 ++ c++-qt/src/dictionary.cpp | 14 ++++++++++++++ c++-qt/src/dictionary.h | 2 ++ c++-qt/src/float.cpp | 5 +++++ c++-qt/src/float.h | 2 ++ c++-qt/src/integer.cpp | 5 +++++ c++-qt/src/integer.h | 2 ++ c++-qt/src/list.cpp | 12 ++++++++++++ c++-qt/src/list.h | 2 ++ c++-qt/src/object.h | 2 ++ c++-qt/src/string.cpp | 7 +++++++ c++-qt/src/string.h | 2 ++ c++-qt/src/version.h | 3 --- c++-qt/tests/echo/mainwnd.cpp | 6 ++++++ 15 files changed, 68 insertions(+), 3 deletions(-) delete mode 100644 c++-qt/src/version.h (limited to 'c++-qt') diff --git a/c++-qt/src/boolean.cpp b/c++-qt/src/boolean.cpp index 9610f50..3973607 100644 --- a/c++-qt/src/boolean.cpp +++ b/c++-qt/src/boolean.cpp @@ -16,6 +16,11 @@ Gats::Boolean::~Boolean() { } +Gats::Object *Gats::Boolean::clone() const +{ + return new Gats::Boolean( bVal ); +} + void Gats::Boolean::write( QIODevice &rOut ) const { if( bVal ) diff --git a/c++-qt/src/boolean.h b/c++-qt/src/boolean.h index 4eec690..d707e4d 100644 --- a/c++-qt/src/boolean.h +++ b/c++-qt/src/boolean.h @@ -15,6 +15,8 @@ namespace Gats Boolean( bool bVal ); virtual ~Boolean(); + virtual Object *clone() const; + virtual Type getType() const { return typeBoolean; } bool getValue() const { return bVal; } void setValue( bool b ) { bVal = b; } diff --git a/c++-qt/src/dictionary.cpp b/c++-qt/src/dictionary.cpp index ad4759a..edcbdb1 100644 --- a/c++-qt/src/dictionary.cpp +++ b/c++-qt/src/dictionary.cpp @@ -18,6 +18,20 @@ Gats::Dictionary::~Dictionary() } } +Gats::Object *Gats::Dictionary::clone() const +{ + Gats::Dictionary *pClone = new Gats::Dictionary; + + for( const_iterator i = begin(); i != end(); i++ ) + { + QByteArray bKey = i.key(); + bKey.detach(); + pClone->insert( bKey, (*i)->clone() ); + } + + return pClone; +} + void Gats::Dictionary::write( QIODevice &rOut ) const { rOut.write("d", 1 ); diff --git a/c++-qt/src/dictionary.h b/c++-qt/src/dictionary.h index 6db94b2..7f95cf1 100644 --- a/c++-qt/src/dictionary.h +++ b/c++-qt/src/dictionary.h @@ -17,6 +17,8 @@ namespace Gats Dictionary(); virtual ~Dictionary(); + virtual Object *clone() const; + virtual Type getType() const { return typeDictionary; } virtual void write( QIODevice &rOut ) const; virtual void read( QIODevice &rIn, char cType ); diff --git a/c++-qt/src/float.cpp b/c++-qt/src/float.cpp index a82edec..fedecf3 100644 --- a/c++-qt/src/float.cpp +++ b/c++-qt/src/float.cpp @@ -17,6 +17,11 @@ Gats::Float::~Float() { } +Gats::Object *Gats::Float::clone() const +{ + return new Gats::Float( fVal ); +} + void Gats::Float::write( QIODevice &rOut ) const { if( fVal == 0.0 ) diff --git a/c++-qt/src/float.h b/c++-qt/src/float.h index 74225aa..93bfe18 100644 --- a/c++-qt/src/float.h +++ b/c++-qt/src/float.h @@ -13,6 +13,8 @@ namespace Gats Float( double f ); virtual ~Float(); + virtual Object *clone() const; + virtual Type getType() const { return typeFloat; } double getValue() const { return fVal; } diff --git a/c++-qt/src/integer.cpp b/c++-qt/src/integer.cpp index bb6da80..82727f3 100644 --- a/c++-qt/src/integer.cpp +++ b/c++-qt/src/integer.cpp @@ -14,6 +14,11 @@ Gats::Integer::~Integer() { } +Gats::Object *Gats::Integer::clone() const +{ + return new Gats::Integer( iVal ); +} + void Gats::Integer::write( QIODevice &rOut ) const { rOut.write("i", 1 ); diff --git a/c++-qt/src/integer.h b/c++-qt/src/integer.h index 8695a12..2dbae94 100644 --- a/c++-qt/src/integer.h +++ b/c++-qt/src/integer.h @@ -17,6 +17,8 @@ namespace Gats Integer( int64_t iVal ); virtual ~Integer(); + virtual Object *clone() const; + virtual Type getType() const { return typeInteger; } int64_t getValue() const { return iVal; } diff --git a/c++-qt/src/list.cpp b/c++-qt/src/list.cpp index 59e1770..8a648e9 100644 --- a/c++-qt/src/list.cpp +++ b/c++-qt/src/list.cpp @@ -18,6 +18,18 @@ Gats::List::~List() } } +Gats::Object *Gats::List::clone() const +{ + Gats::List *pClone = new Gats::List; + + for( const_iterator i = begin(); i != end(); i++ ) + { + pClone->append( (*i)->clone() ); + } + + return pClone; +} + void Gats::List::write( QIODevice &rOut ) const { rOut.write("l", 1 ); diff --git a/c++-qt/src/list.h b/c++-qt/src/list.h index f712fa5..6e5ac56 100644 --- a/c++-qt/src/list.h +++ b/c++-qt/src/list.h @@ -15,6 +15,8 @@ namespace Gats List(); virtual ~List(); + virtual Object *clone() const; + virtual Type getType() const { return typeList; } virtual void write( QIODevice &rOut ) const; diff --git a/c++-qt/src/object.h b/c++-qt/src/object.h index 0c08d41..10501e4 100644 --- a/c++-qt/src/object.h +++ b/c++-qt/src/object.h @@ -28,6 +28,8 @@ namespace Gats Object(); virtual ~Object(); + virtual Object *clone() const=0; + virtual Type getType() const =0; virtual void write( QIODevice &rOut ) const=0; diff --git a/c++-qt/src/string.cpp b/c++-qt/src/string.cpp index 0b9e4d8..ef23829 100644 --- a/c++-qt/src/string.cpp +++ b/c++-qt/src/string.cpp @@ -35,6 +35,13 @@ Gats::String::~String() { } +Gats::Object *Gats::String::clone() const +{ + QByteArray baClone = *this; + baClone.detach(); + return new Gats::String( baClone ); +} + void Gats::String::write( QIODevice &rOut ) const { rOut.write("s", 1 ); diff --git a/c++-qt/src/string.h b/c++-qt/src/string.h index 2acd946..9bf6ce3 100644 --- a/c++-qt/src/string.h +++ b/c++-qt/src/string.h @@ -18,6 +18,8 @@ namespace Gats String( const QByteArray &s ); virtual ~String(); + virtual Object *clone() const; + virtual Type getType() const { return typeString; } virtual void write( QIODevice &rOut ) const; diff --git a/c++-qt/src/version.h b/c++-qt/src/version.h deleted file mode 100644 index 544dd00..0000000 --- a/c++-qt/src/version.h +++ /dev/null @@ -1,3 +0,0 @@ -#ifndef LIBGATS_VC_ID -#define LIBGATS_VC_ID "68:71" -#endif diff --git a/c++-qt/tests/echo/mainwnd.cpp b/c++-qt/tests/echo/mainwnd.cpp index 4b90421..13c93a1 100644 --- a/c++-qt/tests/echo/mainwnd.cpp +++ b/c++-qt/tests/echo/mainwnd.cpp @@ -26,5 +26,11 @@ void MainWnd::newConnection() void MainWnd::objectRead( Gats::Object *pObj ) { ((Gats::GatsStream *)sender())->writeObject( pObj ); + + Gats::Object *pCopy = pObj->clone(); delete pObj; + + ((Gats::GatsStream *)sender())->writeObject( pCopy ); + + delete pCopy; } -- cgit v1.2.3