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