From cef3d22297265304e81abf442fe218a6cba7fc10 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 7 Apr 2022 22:52:09 -0700 Subject: Dictionaries delete old objects to replace new. There may be a better way to manage this. --- c++-qt/gats-qt/dictionary.h | 3 ++- c++-qt/src/dictionary.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/c++-qt/gats-qt/dictionary.h b/c++-qt/gats-qt/dictionary.h index 6f9e82a..6b13868 100644 --- a/c++-qt/gats-qt/dictionary.h +++ b/c++-qt/gats-qt/dictionary.h @@ -49,7 +49,8 @@ namespace Gats //void insert( const QByteArray &sKey, bool b ); void insert( const QByteArray &sKey, float d ); void insert( const QByteArray &sKey, double d ); - using QHash::insert; + void insert( const QByteArray &sKey, Gats::Object *pObj ); + //using QHash::insert; void insertBool( const QByteArray &sKey, bool b ); void insertInt( const QByteArray &sKey, int64_t i ); void insertFloat( const QByteArray &sKey, double d ); diff --git a/c++-qt/src/dictionary.cpp b/c++-qt/src/dictionary.cpp index 1d666ac..6793268 100644 --- a/c++-qt/src/dictionary.cpp +++ b/c++-qt/src/dictionary.cpp @@ -121,6 +121,7 @@ QString Gats::Dictionary::toString( int iIndent ) const void Gats::Dictionary::insert( const QByteArray &sKey, char i ) { + delete value( sKey ); ((QHash *)this)->insert( sKey, new Gats::Integer( i ) ); @@ -128,6 +129,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, char i ) void Gats::Dictionary::insert( const QByteArray &sKey, unsigned char i ) { + delete value( sKey ); ((QHash *)this)->insert( sKey, new Gats::Integer( i ) ); @@ -135,6 +137,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, unsigned char i ) void Gats::Dictionary::insert( const QByteArray &sKey, signed char i ) { + delete value( sKey ); ((QHash *)this)->insert( sKey, new Gats::Integer( i ) ); @@ -142,6 +145,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, signed char i ) void Gats::Dictionary::insert( const QByteArray &sKey, unsigned short i ) { + delete value( sKey ); ((QHash *)this)->insert( sKey, new Gats::Integer( i ) ); @@ -149,6 +153,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, unsigned short i ) void Gats::Dictionary::insert( const QByteArray &sKey, signed short i ) { + delete value( sKey ); ((QHash *)this)->insert( sKey, new Gats::Integer( i ) ); @@ -156,6 +161,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, signed short i ) void Gats::Dictionary::insert( const QByteArray &sKey, unsigned int i ) { + delete value( sKey ); ((QHash *)this)->insert( sKey, new Gats::Integer( i ) ); @@ -163,6 +169,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, unsigned int i ) void Gats::Dictionary::insert( const QByteArray &sKey, signed int i ) { + delete value( sKey ); ((QHash *)this)->insert( sKey, new Gats::Integer( i ) ); @@ -170,6 +177,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, signed int i ) void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long i ) { + delete value( sKey ); ((QHash *)this)->insert( sKey, new Gats::Integer( i ) ); @@ -177,6 +185,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long i ) void Gats::Dictionary::insert( const QByteArray &sKey, signed long i ) { + delete value( sKey ); ((QHash *)this)->insert( sKey, new Gats::Integer( i ) ); @@ -184,6 +193,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, signed long i ) void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long long i ) { + delete value( sKey ); ((QHash *)this)->insert( sKey, new Gats::Integer( i ) ); @@ -191,6 +201,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long long i ) void Gats::Dictionary::insert( const QByteArray &sKey, signed long long i ) { + delete value( sKey ); ((QHash *)this)->insert( sKey, new Gats::Integer( i ) ); @@ -198,6 +209,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, signed long long i ) /* void Gats::Dictionary::insert( const QByteArray &sKey, bool b ) { + delete value( sKey ); QHash::insert( sKey, new Gats::Boolean( b ) ); @@ -205,6 +217,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, bool b ) void Gats::Dictionary::insert( const QByteArray &sKey, float d ) { + delete value( sKey ); QHash::insert( sKey, new Gats::Float( d ) ); @@ -212,6 +225,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, float d ) void Gats::Dictionary::insert( const QByteArray &sKey, double d ) { + delete value( sKey ); QHash::insert( sKey, new Gats::Float( d ) ); @@ -219,6 +233,7 @@ void Gats::Dictionary::insert( const QByteArray &sKey, double d ) void Gats::Dictionary::insert( const QByteArray &sKey, const char *s ) { + delete value( sKey ); QHash::insert( sKey, new Gats::String( s ) ); @@ -226,13 +241,23 @@ void Gats::Dictionary::insert( const QByteArray &sKey, const char *s ) void Gats::Dictionary::insert( const QByteArray &sKey, const QByteArray &s ) { + delete value( sKey ); QHash::insert( sKey, new Gats::String( s ) ); } +void Gats::Dictionary::insert( const QByteArray &sKey, Gats::Object *pObj ) +{ + delete value( sKey ); + QHash::insert( + sKey, pObj + ); +} + void Gats::Dictionary::insertBool( const QByteArray &sKey, bool b ) { + delete value( sKey ); QHash::insert( sKey, new Gats::Boolean( b ) ); @@ -240,6 +265,7 @@ void Gats::Dictionary::insertBool( const QByteArray &sKey, bool b ) void Gats::Dictionary::insertInt( const QByteArray &sKey, int64_t i ) { + delete value( sKey ); QHash::insert( sKey, new Gats::Integer( i ) ); @@ -247,6 +273,7 @@ void Gats::Dictionary::insertInt( const QByteArray &sKey, int64_t i ) void Gats::Dictionary::insertFloat( const QByteArray &sKey, double d ) { + delete value( sKey ); QHash::insert( sKey, new Gats::Float( d ) ); @@ -254,6 +281,7 @@ void Gats::Dictionary::insertFloat( const QByteArray &sKey, double d ) void Gats::Dictionary::insertStr( const QByteArray &sKey, const QByteArray &s ) { + delete value( sKey ); QHash::insert( sKey, new Gats::String( s ) ); @@ -261,6 +289,7 @@ void Gats::Dictionary::insertStr( const QByteArray &sKey, const QByteArray &s ) void Gats::Dictionary::insertList( const QByteArray &sKey, Gats::List *pL ) { + delete value( sKey ); QHash::insert( sKey, pL ); @@ -269,6 +298,7 @@ void Gats::Dictionary::insertList( const QByteArray &sKey, Gats::List *pL ) void Gats::Dictionary::insertDict( const QByteArray &sKey, Gats::Dictionary *pD ) { + delete value( sKey ); QHash::insert( sKey, pD ); -- cgit v1.2.3