/* * 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/list.h" #include "gats-qt/string.h" #include "gats-qt/integer.h" #include "gats-qt/float.h" #include "gats-qt/boolean.h" #include "gats-qt/dictionary.h" Gats::List::List() { } Gats::List::~List() { for( iterator i = begin(); i != end(); i++ ) { delete *i; } } 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 ); for( const_iterator i = begin(); i != end(); i++ ) { (*i)->write( rOut ); } rOut.write("e", 1 ); } void Gats::List::read( QIODevice &rIn, char cType ) { for(;;) { Gats::Object *pObj = Gats::Object::read( rIn ); if( pObj == NULL ) break; append( pObj ); } } void Gats::List::append( const char *s ) { QList::append( new Gats::String( s ) ); } void Gats::List::append( const QByteArray &s ) { QList::append( new Gats::String( s ) ); } void Gats::List::append( int32_t i ) { QList::append( new Gats::Integer( i ) ); } void Gats::List::append( int64_t i ) { QList::append( new Gats::Integer( i ) ); } void Gats::List::append( double d ) { QList::append( new Gats::Float( d ) ); } void Gats::List::appendStr( const QByteArray &s ) { QList::append( new Gats::String( s ) ); } void Gats::List::appendInt( int64_t i ) { QList::append( new Gats::Integer( i ) ); } void Gats::List::appendFloat( double d ) { QList::append( new Gats::Float( d ) ); } void Gats::List::appendBool( bool b ) { QList::append( new Gats::Boolean( b ) ); } void Gats::List::appendList( Gats::List *pL ) { QList::append( pL ); } void Gats::List::appendDict( Gats::Dictionary *pD ) { QList::append( pD ); } Gats::List *Gats::List::appendList() { Gats::List *pLst = new Gats::List(); appendList( pLst ); return pLst; } Gats::Dictionary *Gats::List::appendDict() { Gats::Dictionary *pDict = new Gats::Dictionary(); appendDict( pDict ); return pDict; } void Gats::List::prepend( const char *s ) { QList::prepend( new Gats::String( s ) ); } void Gats::List::prepend( const QByteArray &s ) { QList::prepend( new Gats::String( s ) ); } void Gats::List::prepend( int32_t i ) { QList::prepend( new Gats::Integer( i ) ); } void Gats::List::prepend( int64_t i ) { QList::prepend( new Gats::Integer( i ) ); } void Gats::List::prepend( double d ) { QList::prepend( new Gats::Float( d ) ); } void Gats::List::prependStr( const QByteArray &s ) { QList::prepend( new Gats::String( s ) ); } void Gats::List::prependInt( int64_t i ) { QList::prepend( new Gats::Integer( i ) ); } void Gats::List::prependFloat( double d ) { QList::prepend( new Gats::Float( d ) ); } void Gats::List::prependBool( bool b ) { QList::prepend( new Gats::Boolean( b ) ); } void Gats::List::prependList( Gats::List *pL ) { QList::prepend( pL ); } void Gats::List::prependDict( Gats::Dictionary *pD ) { QList::prepend( pD ); } Gats::List *Gats::List::prependList() { Gats::List *pLst = new Gats::List(); prependList( pLst ); return pLst; } Gats::Dictionary *Gats::List::prependDict() { Gats::Dictionary *pDict = new Gats::Dictionary(); prependDict( pDict ); return pDict; } /* Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ) { f << "(list) ["; f.incIndent(); for( Gats::List::const_iterator i = l.begin(); i; i++ ) { f << f.nl << **i; } f.decIndent(); f << f.nl << "]"; return f; } */