From d534a56d95bca7bdd812be024d9eacba4734e2b7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 9 Nov 2012 17:20:11 +0000 Subject: Many changes: tabconv'd the C++ code, added a license, BSD, and docs. --- c++-qt/src/dictionary.cpp | 351 +++++++++++++++++++++++----------------------- 1 file changed, 179 insertions(+), 172 deletions(-) (limited to 'c++-qt/src/dictionary.cpp') diff --git a/c++-qt/src/dictionary.cpp b/c++-qt/src/dictionary.cpp index edcbdb1..b2ef35e 100644 --- a/c++-qt/src/dictionary.cpp +++ b/c++-qt/src/dictionary.cpp @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "gats-qt/dictionary.h" #include "gats-qt/boolean.h" @@ -12,352 +19,352 @@ Gats::Dictionary::Dictionary() Gats::Dictionary::~Dictionary() { - for( iterator i = begin(); i != end(); i++ ) - { - delete *i; - } + for( iterator i = begin(); i != end(); i++ ) + { + delete *i; + } } Gats::Object *Gats::Dictionary::clone() const { - Gats::Dictionary *pClone = new Gats::Dictionary; + 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() ); - } + for( const_iterator i = begin(); i != end(); i++ ) + { + QByteArray bKey = i.key(); + bKey.detach(); + pClone->insert( bKey, (*i)->clone() ); + } - return pClone; + return pClone; } void Gats::Dictionary::write( QIODevice &rOut ) const { - rOut.write("d", 1 ); - for( const_iterator i= begin(); i != end(); i++ ) - { - Gats::String s( i.key() ); - s.write( rOut ); - (*i)->write( rOut ); - } - rOut.write("e", 1 ); + rOut.write("d", 1 ); + for( const_iterator i= begin(); i != end(); i++ ) + { + Gats::String s( i.key() ); + s.write( rOut ); + (*i)->write( rOut ); + } + rOut.write("e", 1 ); } void Gats::Dictionary::read( QIODevice &rIn, char cType ) { - for(;;) - { - char cNext; - rIn.read( &cNext, 1 ); - if( cNext == 'e' ) - break; - if( cNext != 's' ) - throw "PUT GOOD EXCEPTION HERE"; - Gats::String sKey; - sKey.read( rIn, cNext ); + for(;;) + { + char cNext; + rIn.read( &cNext, 1 ); + if( cNext == 'e' ) + break; + if( cNext != 's' ) + throw "PUT GOOD EXCEPTION HERE"; + Gats::String sKey; + sKey.read( rIn, cNext ); - ((QHash *)this)->insert( - sKey, Gats::Object::read( rIn ) - ); - } + ((QHash *)this)->insert( + sKey, Gats::Object::read( rIn ) + ); + } } void Gats::Dictionary::insert( const QByteArray &sKey, char i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, unsigned char i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, signed char i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, unsigned short i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, signed short i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, unsigned int i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, signed int i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, signed long i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long long i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, signed long long i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } /* void Gats::Dictionary::insert( const QByteArray &sKey, bool b ) { - QHash::insert( - sKey, new Gats::Boolean( b ) - ); + QHash::insert( + sKey, new Gats::Boolean( b ) + ); }*/ void Gats::Dictionary::insert( const QByteArray &sKey, float d ) { - QHash::insert( - sKey, new Gats::Float( d ) - ); + QHash::insert( + sKey, new Gats::Float( d ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, double d ) { - QHash::insert( - sKey, new Gats::Float( d ) - ); + QHash::insert( + sKey, new Gats::Float( d ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, const char *s ) { - QHash::insert( - sKey, new Gats::String( s ) - ); + QHash::insert( + sKey, new Gats::String( s ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, const QByteArray &s ) { - QHash::insert( - sKey, new Gats::String( s ) - ); + QHash::insert( + sKey, new Gats::String( s ) + ); } void Gats::Dictionary::insertBool( const QByteArray &sKey, bool b ) { - QHash::insert( - sKey, new Gats::Boolean( b ) - ); + QHash::insert( + sKey, new Gats::Boolean( b ) + ); } void Gats::Dictionary::insertInt( const QByteArray &sKey, int64_t i ) { - QHash::insert( - sKey, new Gats::Integer( i ) - ); + QHash::insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insertFloat( const QByteArray &sKey, double d ) { - QHash::insert( - sKey, new Gats::Float( d ) - ); + QHash::insert( + sKey, new Gats::Float( d ) + ); } void Gats::Dictionary::insertStr( const QByteArray &sKey, const QByteArray &s ) { - QHash::insert( - sKey, new Gats::String( s ) - ); + QHash::insert( + sKey, new Gats::String( s ) + ); } void Gats::Dictionary::insertList( const QByteArray &sKey, Gats::List *pL ) { - QHash::insert( - sKey, pL - ); + QHash::insert( + sKey, pL + ); } void Gats::Dictionary::insertDict( const QByteArray &sKey, - Gats::Dictionary *pD ) + Gats::Dictionary *pD ) { - QHash::insert( - sKey, pD - ); + QHash::insert( + sKey, pD + ); } Gats::List *Gats::Dictionary::insertList( const QByteArray &sKey ) { - Gats::List *pLst = new Gats::List(); - insertList( sKey, pLst ); - return pLst; + Gats::List *pLst = new Gats::List(); + insertList( sKey, pLst ); + return pLst; } Gats::Dictionary *Gats::Dictionary::insertDict( const QByteArray &sKey ) { - Gats::Dictionary *pDict = new Gats::Dictionary(); - insertDict( sKey, pDict ); - return pDict; + Gats::Dictionary *pDict = new Gats::Dictionary(); + insertDict( sKey, pDict ); + return pDict; } bool Gats::Dictionary::valueBool( const QByteArray &sKey ) { - Gats::Boolean *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Boolean *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } int64_t Gats::Dictionary::valueInt( const QByteArray &sKey ) { - Gats::Integer *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Integer *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } double Gats::Dictionary::valueFloat( const QByteArray &sKey ) { - Gats::Float *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Float *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } QByteArray Gats::Dictionary::valueStr( const QByteArray &sKey ) { - Gats::String *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::String *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return *pOb; + return *pOb; } Gats::List *Gats::Dictionary::valueList( const QByteArray &sKey ) { - Gats::List *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::List *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb; + return pOb; } Gats::Dictionary *Gats::Dictionary::valueDict( const QByteArray &sKey ) { - Gats::Dictionary *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Dictionary *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb; + return pOb; } bool Gats::Dictionary::valueBool( const QByteArray &sKey ) const { - Gats::Boolean *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Boolean *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } int64_t Gats::Dictionary::valueInt( const QByteArray &sKey ) const { - Gats::Integer *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Integer *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } double Gats::Dictionary::valueFloat( const QByteArray &sKey ) const { - Gats::Float *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Float *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } QByteArray Gats::Dictionary::valueStr( const QByteArray &sKey ) const { - Gats::String *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::String *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return *pOb; + return *pOb; } Gats::List *Gats::Dictionary::valueList( const QByteArray &sKey ) const { - Gats::List *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::List *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb; + return pOb; } Gats::Dictionary *Gats::Dictionary::valueDict( const QByteArray &sKey ) const { - Gats::Dictionary *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Dictionary *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb; + return pOb; } /* Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ) { - f << "(dict) {"; - f.incIndent(); - int iMax = 0; - for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) - { - if( i.valueKey().valueSize() > iMax ) - iMax = i.valueKey().valueSize(); - } - iMax += 2; - for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) - { - f << f.nl << Bu::Fmt( iMax ) << i.valueKey() + ": " << *i.getValue(); - } - f.decIndent(); - f << f.nl << "}"; - - return f; + f << "(dict) {"; + f.incIndent(); + int iMax = 0; + for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) + { + if( i.valueKey().valueSize() > iMax ) + iMax = i.valueKey().valueSize(); + } + iMax += 2; + for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) + { + f << f.nl << Bu::Fmt( iMax ) << i.valueKey() + ": " << *i.getValue(); + } + f.decIndent(); + f << f.nl << "}"; + + return f; } */ -- cgit v1.2.3