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++-libbu++/default.bld | 100 +++--- c++-libbu++/mingw.bld | 110 +++---- c++-libbu++/src/boolean.cpp | 47 +-- c++-libbu++/src/boolean.h | 43 +-- c++-libbu++/src/dictionary.cpp | 373 +++++++++++----------- c++-libbu++/src/dictionary.h | 107 ++++--- c++-libbu++/src/float.cpp | 193 ++++++------ c++-libbu++/src/float.h | 37 ++- c++-libbu++/src/gatsc/main.cpp | 99 +++--- c++-libbu++/src/gatscon/clientthread.cpp | 43 +-- c++-libbu++/src/gatscon/clientthread.h | 29 +- c++-libbu++/src/gatscon/clientwidget.cpp | 95 +++--- c++-libbu++/src/gatscon/clientwidget.h | 23 +- c++-libbu++/src/gatscon/connectdlg.cpp | 15 +- c++-libbu++/src/gatscon/connectdlg.h | 17 +- c++-libbu++/src/gatscon/filewidget.cpp | 75 +++-- c++-libbu++/src/gatscon/filewidget.h | 23 +- c++-libbu++/src/gatscon/gatstotree.cpp | 115 +++---- c++-libbu++/src/gatscon/gatstotree.h | 21 +- c++-libbu++/src/gatscon/iobase.cpp | 7 + c++-libbu++/src/gatscon/iobase.h | 9 +- c++-libbu++/src/gatscon/main.cpp | 15 +- c++-libbu++/src/gatscon/mainwnd.cpp | 149 ++++----- c++-libbu++/src/gatscon/mainwnd.h | 31 +- c++-libbu++/src/gatscon/proxythread.cpp | 113 +++---- c++-libbu++/src/gatscon/proxythread.h | 55 ++-- c++-libbu++/src/gatscon/proxywidget.cpp | 169 +++++----- c++-libbu++/src/gatscon/proxywidget.h | 31 +- c++-libbu++/src/gatscon/setupproxydlg.cpp | 17 +- c++-libbu++/src/gatscon/setupproxydlg.h | 19 +- c++-libbu++/src/gatscon/treetogats.cpp | 89 +++--- c++-libbu++/src/gatscon/treetogats.h | 9 +- c++-libbu++/src/gatsstream.cpp | 165 +++++----- c++-libbu++/src/gatsstream.h | 97 +++--- c++-libbu++/src/integer.cpp | 21 +- c++-libbu++/src/integer.h | 147 ++++----- c++-libbu++/src/list.cpp | 139 +++++---- c++-libbu++/src/list.h | 95 +++--- c++-libbu++/src/null.cpp | 15 +- c++-libbu++/src/null.h | 27 +- c++-libbu++/src/object.cpp | 503 +++++++++++++++--------------- c++-libbu++/src/object.h | 83 ++--- c++-libbu++/src/protocolgats.cpp | 63 ++-- c++-libbu++/src/protocolgats.h | 37 ++- c++-libbu++/src/string.cpp | 47 +-- c++-libbu++/src/string.h | 45 +-- c++-libbu++/src/tests/clone.cpp | 21 +- c++-libbu++/src/tests/dump.cpp | 41 ++- c++-libbu++/src/tests/int.cpp | 65 ++-- c++-libbu++/src/types.h | 7 + 50 files changed, 2116 insertions(+), 1780 deletions(-) (limited to 'c++-libbu++') diff --git a/c++-libbu++/default.bld b/c++-libbu++/default.bld index 676c63e..5a09a55 100644 --- a/c++-libbu++/default.bld +++ b/c++-libbu++/default.bld @@ -3,87 +3,87 @@ execute("mkdir -p tmp"); action "default" { - build: [targets("header-links"), "libgats.a", "gatsc"]; + build: [targets("header-links"), "libgats.a", "gatsc"]; } action "all" { - build: [targets("header-links"), "libgats.a", targets("headers"), - targets()]; + build: [targets("header-links"), "libgats.a", targets("headers"), + targets()]; } action "gatscon" { - build: [targets("header-links"), "libgats.a", - targets("headers"), "gatscon"]; + build: [targets("header-links"), "libgats.a", + targets("headers"), "gatscon"]; } CXXFLAGS += "-ggdb -Wall"; target [files("src/*.h").replace("src/", "gats/"), "gats/version.h"] { - tag "header-links"; - display "symlink"; - input OUTPUT.replace("gats/","src/"); - profile "build" - { - execute("ln -s ../${INPUT} ${OUTPUT}"); - } + tag "header-links"; + display "symlink"; + input OUTPUT.replace("gats/","src/"); + profile "build" + { + execute("ln -s ../${INPUT} ${OUTPUT}"); + } } target "src/version.h" { - input ".svn"; - display "svnver"; - profile "build" - { - execute("echo Revision number: `svnversion`; echo \\#ifndef LIBGATS_VC_ID > ${OUTPUT}; echo \\#define LIBGATS_VC_ID \\\"`svnversion`\\\" >> ${OUTPUT}; echo \\#endif >> ${OUTPUT}"); - } + input ".svn"; + display "svnver"; + profile "build" + { + execute("echo Revision number: `svnversion`; echo \\#ifndef LIBGATS_VC_ID > ${OUTPUT}; echo \\#define LIBGATS_VC_ID \\\"`svnversion`\\\" >> ${OUTPUT}; echo \\#endif >> ${OUTPUT}"); + } } target "libgats.a" { - rule "lib"; - input files("src/*.cpp"); - CXXFLAGS += "-I. -Ilibbu++ -fPIC"; + rule "lib"; + input files("src/*.cpp"); + CXXFLAGS += "-I. -Ilibbu++ -fPIC"; } target "gatsc" { - rule "exe"; - input files("src/gatsc/*.cpp"); - CXXFLAGS += "-I. -Ilibbu++"; - LDFLAGS += "-L. -lgats -lbu++"; + rule "exe"; + input files("src/gatsc/*.cpp"); + CXXFLAGS += "-I. -Ilibbu++"; + LDFLAGS += "-L. -lgats -lbu++"; } target files("src/tests/*.cpp").replace("src/","").replace(".cpp","") { - input "src/${OUTPUT}.cpp"; - rule "exe"; - tag ["tests", "general tests"]; - CXXFLAGS += "-I. -Ilibbu++"; - LDFLAGS += "-L. -lgats -Llibbu++ -lbu++"; + input "src/${OUTPUT}.cpp"; + rule "exe"; + tag ["tests", "general tests"]; + CXXFLAGS += "-I. -Ilibbu++"; + LDFLAGS += "-L. -lgats -Llibbu++ -lbu++"; } target files("src/unit/*.unit").replace("src/","").replace(".unit","") { - input "src/${OUTPUT}.unit"; - rule "exe"; - requires "libbu++.a"; - tag ["tests", "unit tests"]; - CXXFLAGS += "-I."; - LDFLAGS += "-L. -lgats -lbu++"; + input "src/${OUTPUT}.unit"; + rule "exe"; + requires "libbu++.a"; + tag ["tests", "unit tests"]; + CXXFLAGS += "-I."; + LDFLAGS += "-L. -lgats -lbu++"; } rule "unit" { - input "*.unit"; - output INPUT.replace(".unit", ".cpp"); + input "*.unit"; + output INPUT.replace(".unit", ".cpp"); - profile "build" - { - execute("../libbu++/mkunit \"${INPUT}\" \"${OUTPUT}\""); - } + profile "build" + { + execute("../libbu++/mkunit \"${INPUT}\" \"${OUTPUT}\""); + } } include "qt4.bld"; @@ -95,15 +95,15 @@ UI_DIR = "tmp"; target "gatscon" { - input files("src/gatscon/*.h", "src/gatscon/*.cpp", "src/gatscon/*.ui"); - rule "exe"; + input files("src/gatscon/*.h", "src/gatscon/*.cpp", "src/gatscon/*.ui"); + rule "exe"; - CXXFLAGS += qt_getCXXFLAGS(); - LDFLAGS += qt_getLDFLAGS(); + CXXFLAGS += qt_getCXXFLAGS(); + LDFLAGS += qt_getLDFLAGS(); - CXXFLAGS += "-Isrc/gatscon"; - - CXXFLAGS += "-I. -Ilibbu++ -Itmp -Ilibzamui/src"; - LDFLAGS += "-L. -lgats -Llibbu++ -lbu++ -Llibzamui -lzamui"; + CXXFLAGS += "-Isrc/gatscon"; + + CXXFLAGS += "-I. -Ilibbu++ -Itmp -Ilibzamui/src"; + LDFLAGS += "-L. -lgats -Llibbu++ -lbu++ -Llibzamui -lzamui"; } diff --git a/c++-libbu++/mingw.bld b/c++-libbu++/mingw.bld index 9ed7af3..a59018f 100644 --- a/c++-libbu++/mingw.bld +++ b/c++-libbu++/mingw.bld @@ -8,99 +8,99 @@ CXXFLAGS += "-ggdb -W -Wall"; action "default" { - build: [targets("header-links"), "libgatswin.a"]; + build: [targets("header-links"), "libgatswin.a"]; } action "gatscon" { - build: ["gatscon.exe"]; + build: ["gatscon.exe"]; } target files("src/*.h").replace("src/", "gats/") { - tag "header-links"; - display "symlink"; - input OUTPUT.replace("gats/","src/"); - profile "build" - { - execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../${INPUT} ${OUTPUT}"); - } + tag "header-links"; + display "symlink"; + input OUTPUT.replace("gats/","src/"); + profile "build" + { + execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../${INPUT} ${OUTPUT}"); + } } target files("src/compat/*.h").replace("src/", "gats/") { - tag "header-links"; - display "symlink"; - input OUTPUT.replace("gats/","src/"); - profile "build" - { - execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../../${INPUT} ${OUTPUT}"); - } + tag "header-links"; + display "symlink"; + input OUTPUT.replace("gats/","src/"); + profile "build" + { + execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../../${INPUT} ${OUTPUT}"); + } } target "libgatswin.a" { - input files("src/*.cpp"); - rule "lib"; - CXXFLAGS += "-I. -Ilibbu++"; + input files("src/*.cpp"); + rule "lib"; + CXXFLAGS += "-I. -Ilibbu++"; } target "gatscon.exe" { - rule "winexe"; - tag "exe"; - input files("src/gatscon/*.cpp", "src/gatscon/*.ui", "src/gatscon/*.h", - "tmp/*.cpp"); + rule "winexe"; + tag "exe"; + input files("src/gatscon/*.cpp", "src/gatscon/*.ui", "src/gatscon/*.h", + "tmp/*.cpp"); - CXXFLAGS += "-O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -IC:/Qt/qt-4/include/QtCore -IC:/Qt/qt-4/include/QtGui -IC:/Qt/qt-4/include/QtSvg -IC:/Qt/qt-4/include -IC:/Qt/qt-4/mkspecs/default -Ilibbu++ -Isrc/gatscon -I. -Ilibzamui/src"; + CXXFLAGS += "-O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -IC:/Qt/qt-4/include/QtCore -IC:/Qt/qt-4/include/QtGui -IC:/Qt/qt-4/include/QtSvg -IC:/Qt/qt-4/include -IC:/Qt/qt-4/mkspecs/default -Ilibbu++ -Isrc/gatscon -I. -Ilibzamui/src"; - LDFLAGS += "-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -LC:/Qt/qt-4/lib -Llibbu++ -lgatswin -lbu++win -L. -Llibzamui -lzamuiwin -lmingw32 -lqtmain -lQtGui4 -lQtCore4 -lQtSvg4 -lwsock32"; + LDFLAGS += "-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -LC:/Qt/qt-4/lib -Llibbu++ -lgatswin -lbu++win -L. -Llibzamui -lzamuiwin -lmingw32 -lqtmain -lQtGui4 -lQtCore4 -lQtSvg4 -lwsock32"; - CXXFLAGS += "-ggdb -Itmp"; + CXXFLAGS += "-ggdb -Itmp"; } function cppToWinObj() { - if OBJ_DIR == null then - { - return INPUT.regex("\\.cpp$", ".win_o"); - } - else - { - return OBJ_DIR + "/" + INPUT.fileName().regex("\\.cpp$", ".win_o"); - } + if OBJ_DIR == null then + { + return INPUT.regex("\\.cpp$", ".win_o"); + } + else + { + return OBJ_DIR + "/" + INPUT.fileName().regex("\\.cpp$", ".win_o"); + } } rule "lib" { - input "*.win_o"; - profile "build" - { - execute("wine C:/MinGW/bin/ar.exe cr ${OUTPUT} ${INPUT}"); - } + input "*.win_o"; + profile "build" + { + execute("wine C:/MinGW/bin/ar.exe cr ${OUTPUT} ${INPUT}"); + } } rule "wincpp" { - input "*.cpp"; - output INPUT.cppToWinObj(); - //requires getMakeDeps("wine C:/MinGW/bin/g++.exe ${CXXFLAGS} -M ${INPUT}"); - profile "build" - { - execute("wine C:/MinGW/bin/g++.exe ${CXXFLAGS} -c -o ${OUTPUT} ${INPUT}", "g++"); - } + input "*.cpp"; + output INPUT.cppToWinObj(); + //requires getMakeDeps("wine C:/MinGW/bin/g++.exe ${CXXFLAGS} -M ${INPUT}"); + profile "build" + { + execute("wine C:/MinGW/bin/g++.exe ${CXXFLAGS} -c -o ${OUTPUT} ${INPUT}", "g++"); + } } rule "winexe" { - input "*.win_o"; - profile "build" - { - if DEBUG != "true" then - { - LDFLAGS += "-Wl,-s"; - } - execute("wine C:/MinGW/bin/mingw32-g++.exe -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); - } + input "*.win_o"; + profile "build" + { + if DEBUG != "true" then + { + LDFLAGS += "-Wl,-s"; + } + execute("wine C:/MinGW/bin/mingw32-g++.exe -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); + } } diff --git a/c++-libbu++/src/boolean.cpp b/c++-libbu++/src/boolean.cpp index 729e644..7060dab 100644 --- a/c++-libbu++/src/boolean.cpp +++ b/c++-libbu++/src/boolean.cpp @@ -1,15 +1,22 @@ +/* + * 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/boolean.h" #include #include Gats::Boolean::Boolean() : - bVal( false ) + bVal( false ) { } Gats::Boolean::Boolean( bool bVal ) : - bVal( bVal ) + bVal( bVal ) { } @@ -19,35 +26,35 @@ Gats::Boolean::~Boolean() Gats::Object *Gats::Boolean::clone() const { - return new Gats::Boolean( bVal ); + return new Gats::Boolean( bVal ); } void Gats::Boolean::write( Bu::Stream &rOut ) const { - if( bVal ) - { - rOut.write("1", 1 ); - } - else - { - rOut.write("0", 1 ); - } + if( bVal ) + { + rOut.write("1", 1 ); + } + else + { + rOut.write("0", 1 ); + } } void Gats::Boolean::read( Bu::Stream &rIn, char cType ) { - if( cType == '1' ) - { - bVal = true; - } - else - { - bVal = false; - } + if( cType == '1' ) + { + bVal = true; + } + else + { + bVal = false; + } } Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ) { - return f << "(bool) " << b.getValue(); + return f << "(bool) " << b.getValue(); } diff --git a/c++-libbu++/src/boolean.h b/c++-libbu++/src/boolean.h index 6b256c5..c83701c 100644 --- a/c++-libbu++/src/boolean.h +++ b/c++-libbu++/src/boolean.h @@ -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. + */ + #ifndef GATS_BOOLEAN_H #define GATS_BOOLEAN_H @@ -5,24 +12,24 @@ namespace Gats { - class Boolean : public Gats::Object - { - public: - Boolean(); - Boolean( bool bVal ); - virtual ~Boolean(); - - virtual Type getType() const { return typeBoolean; } - bool getValue() const { return bVal; } - void setValue( bool b ) { bVal = b; } - virtual Object *clone() const; - - virtual void write( Bu::Stream &rOut ) const; - virtual void read( Bu::Stream &rIn, char cType ); - - private: - bool bVal; - }; + class Boolean : public Gats::Object + { + public: + Boolean(); + Boolean( bool bVal ); + virtual ~Boolean(); + + virtual Type getType() const { return typeBoolean; } + bool getValue() const { return bVal; } + void setValue( bool b ) { bVal = b; } + virtual Object *clone() const; + + virtual void write( Bu::Stream &rOut ) const; + virtual void read( Bu::Stream &rIn, char cType ); + + private: + bool bVal; + }; }; Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ); diff --git a/c++-libbu++/src/dictionary.cpp b/c++-libbu++/src/dictionary.cpp index b59d652..c6b08a1 100644 --- a/c++-libbu++/src/dictionary.cpp +++ b/c++-libbu++/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/dictionary.h" #include "gats/boolean.h" @@ -11,7 +18,7 @@ template<> uint32_t Bu::__calcHashCode( const Gats::String &s ) { - return __calcHashCode( dynamic_cast(s) ); + return __calcHashCode( dynamic_cast(s) ); } Gats::Dictionary::Dictionary() @@ -20,361 +27,361 @@ Gats::Dictionary::Dictionary() Gats::Dictionary::~Dictionary() { - for( iterator i = begin(); i; i++ ) - { - delete *i; - } + for( iterator i = begin(); i; i++ ) + { + delete *i; + } } Gats::Object *Gats::Dictionary::clone() const { - Gats::Dictionary *pClone = new Gats::Dictionary; - for( const_iterator i = begin(); i; i++ ) - { - Bu::String s(i.getKey()); - pClone->insert( s.clone(), (*i)->clone() ); - } + Gats::Dictionary *pClone = new Gats::Dictionary; + for( const_iterator i = begin(); i; i++ ) + { + Bu::String s(i.getKey()); + pClone->insert( s.clone(), (*i)->clone() ); + } - return pClone; + return pClone; } void Gats::Dictionary::write( Bu::Stream &rOut ) const { - rOut.write("d", 1 ); - for( const_iterator i= begin(); i; i++ ) - { - i.getKey().write( rOut ); - (*i)->write( rOut ); - } - rOut.write("e", 1 ); + rOut.write("d", 1 ); + for( const_iterator i= begin(); i; i++ ) + { + i.getKey().write( rOut ); + (*i)->write( rOut ); + } + rOut.write("e", 1 ); } void Gats::Dictionary::read( Bu::Stream &rIn, char cType ) { - for(;;) - { - char cNext; - rIn.read( &cNext, 1 ); - if( cNext == 'e' ) - break; - if( cNext != 's' ) - throw Bu::ExceptionBase("You can only use strings as keys."); - Gats::String sKey; - sKey.read( rIn, cNext ); + for(;;) + { + char cNext; + rIn.read( &cNext, 1 ); + if( cNext == 'e' ) + break; + if( cNext != 's' ) + throw Bu::ExceptionBase("You can only use strings as keys."); + Gats::String sKey; + sKey.read( rIn, cNext ); - ((Bu::Hash *)this)->insert( - sKey, Gats::Object::read( rIn ) - ); - } + ((Bu::Hash *)this)->insert( + sKey, Gats::Object::read( rIn ) + ); + } } void Gats::Dictionary::insert( const Bu::String &sKey, char i ) { - ((Bu::Hash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((Bu::Hash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, unsigned char i ) { - ((Bu::Hash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((Bu::Hash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, signed char i ) { - ((Bu::Hash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((Bu::Hash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, unsigned short i ) { - ((Bu::Hash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((Bu::Hash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, signed short i ) { - ((Bu::Hash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((Bu::Hash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, unsigned int i ) { - ((Bu::Hash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((Bu::Hash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, signed int i ) { - ((Bu::Hash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((Bu::Hash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, unsigned long i ) { - ((Bu::Hash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((Bu::Hash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, signed long i ) { - ((Bu::Hash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((Bu::Hash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, unsigned long long i ) { - ((Bu::Hash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((Bu::Hash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, signed long long i ) { - ((Bu::Hash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((Bu::Hash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } /* void Gats::Dictionary::insert( const Bu::String &sKey, bool b ) { - Bu::Hash::insert( - sKey, new Gats::Boolean( b ) - ); + Bu::Hash::insert( + sKey, new Gats::Boolean( b ) + ); }*/ void Gats::Dictionary::insert( const Bu::String &sKey, float d ) { - Bu::Hash::insert( - sKey, new Gats::Float( d ) - ); + Bu::Hash::insert( + sKey, new Gats::Float( d ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, double d ) { - Bu::Hash::insert( - sKey, new Gats::Float( d ) - ); + Bu::Hash::insert( + sKey, new Gats::Float( d ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, const char *s ) { - Bu::Hash::insert( - sKey, new Gats::String( s ) - ); + Bu::Hash::insert( + sKey, new Gats::String( s ) + ); } void Gats::Dictionary::insert( const Bu::String &sKey, const Bu::String &s ) { - Bu::Hash::insert( - sKey, new Gats::String( s ) - ); + Bu::Hash::insert( + sKey, new Gats::String( s ) + ); } void Gats::Dictionary::insertBool( const Bu::String &sKey, bool b ) { - Bu::Hash::insert( - sKey, new Gats::Boolean( b ) - ); + Bu::Hash::insert( + sKey, new Gats::Boolean( b ) + ); } void Gats::Dictionary::insertInt( const Bu::String &sKey, int64_t i ) { - Bu::Hash::insert( - sKey, new Gats::Integer( i ) - ); + Bu::Hash::insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insertFloat( const Bu::String &sKey, double d ) { - Bu::Hash::insert( - sKey, new Gats::Float( d ) - ); + Bu::Hash::insert( + sKey, new Gats::Float( d ) + ); } void Gats::Dictionary::insertStr( const Bu::String &sKey, const Bu::String &s ) { - Bu::Hash::insert( - sKey, new Gats::String( s ) - ); + Bu::Hash::insert( + sKey, new Gats::String( s ) + ); } void Gats::Dictionary::insertList( const Bu::String &sKey, Gats::List *pL ) { - Bu::Hash::insert( - sKey, pL - ); + Bu::Hash::insert( + sKey, pL + ); } void Gats::Dictionary::insertDict( const Bu::String &sKey, - Gats::Dictionary *pD ) + Gats::Dictionary *pD ) { - Bu::Hash::insert( - sKey, pD - ); + Bu::Hash::insert( + sKey, pD + ); } Gats::List *Gats::Dictionary::insertList( const Bu::String &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 Bu::String &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::getBool( const Bu::String &sKey ) { - Gats::Boolean *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::Boolean *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - return pOb->getValue(); + return pOb->getValue(); } int64_t Gats::Dictionary::getInt( const Bu::String &sKey ) { - Gats::Integer *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::Integer *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - return pOb->getValue(); + return pOb->getValue(); } double Gats::Dictionary::getFloat( const Bu::String &sKey ) { - Gats::Float *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::Float *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - return pOb->getValue(); + return pOb->getValue(); } Bu::String Gats::Dictionary::getStr( const Bu::String &sKey ) { - Gats::String *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::String *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - return *pOb; + return *pOb; } Gats::List *Gats::Dictionary::getList( const Bu::String &sKey ) { - Gats::List *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::List *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - return pOb; + return pOb; } Gats::Dictionary *Gats::Dictionary::getDict( const Bu::String &sKey ) { - Gats::Dictionary *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::Dictionary *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - return pOb; + return pOb; } bool Gats::Dictionary::getBool( const Bu::String &sKey ) const { - Gats::Boolean *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::Boolean *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - return pOb->getValue(); + return pOb->getValue(); } int64_t Gats::Dictionary::getInt( const Bu::String &sKey ) const { - Gats::Integer *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::Integer *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - return pOb->getValue(); + return pOb->getValue(); } double Gats::Dictionary::getFloat( const Bu::String &sKey ) const { - Gats::Float *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::Float *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - return pOb->getValue(); + return pOb->getValue(); } Bu::String Gats::Dictionary::getStr( const Bu::String &sKey ) const { - Gats::String *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::String *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - return *pOb; + return *pOb; } Gats::List *Gats::Dictionary::getList( const Bu::String &sKey ) const { - Gats::List *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::List *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - return pOb; + return pOb; } Gats::Dictionary *Gats::Dictionary::getDict( const Bu::String &sKey ) const { - Gats::Dictionary *pOb = dynamic_cast( get( sKey ) ); - if( !pOb ) - throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", - typeToStr( get( sKey )->getType() ), sKey.getStr() ); + Gats::Dictionary *pOb = dynamic_cast( get( sKey ) ); + if( !pOb ) + throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", + typeToStr( get( sKey )->getType() ), sKey.getStr() ); - 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.getKey().getSize() > iMax ) - iMax = i.getKey().getSize(); - } - iMax += 2; - for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) - { - f << f.nl << Bu::Fmt( iMax ) << i.getKey() + ": " << *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.getKey().getSize() > iMax ) + iMax = i.getKey().getSize(); + } + iMax += 2; + for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) + { + f << f.nl << Bu::Fmt( iMax ) << i.getKey() + ": " << *i.getValue(); + } + f.decIndent(); + f << f.nl << "}"; + + return f; } diff --git a/c++-libbu++/src/dictionary.h b/c++-libbu++/src/dictionary.h index 3dd1000..6250eb6 100644 --- a/c++-libbu++/src/dictionary.h +++ b/c++-libbu++/src/dictionary.h @@ -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. + */ + #ifndef GATS_DICTIONARY_H #define GATS_DICTIONARY_H @@ -7,60 +14,60 @@ namespace Gats { - class List; + class List; - class Dictionary : public Gats::Object, - public Bu::Hash - { - public: - Dictionary(); - virtual ~Dictionary(); + class Dictionary : public Gats::Object, + public Bu::Hash + { + public: + Dictionary(); + virtual ~Dictionary(); - virtual Type getType() const { return typeDictionary; } - virtual Object *clone() const; - virtual void write( Bu::Stream &rOut ) const; - virtual void read( Bu::Stream &rIn, char cType ); + virtual Type getType() const { return typeDictionary; } + virtual Object *clone() const; + virtual void write( Bu::Stream &rOut ) const; + virtual void read( Bu::Stream &rIn, char cType ); - void insert( const Bu::String &sKey, const char *s ); - void insert( const Bu::String &sKey, const Bu::String &s ); - void insert( const Bu::String &sKey, char i ); - void insert( const Bu::String &sKey, unsigned char i ); - void insert( const Bu::String &sKey, signed char i ); - void insert( const Bu::String &sKey, unsigned short i ); - void insert( const Bu::String &sKey, signed short i ); - void insert( const Bu::String &sKey, unsigned int i ); - void insert( const Bu::String &sKey, signed int i ); - void insert( const Bu::String &sKey, unsigned long i ); - void insert( const Bu::String &sKey, signed long i ); - void insert( const Bu::String &sKey, unsigned long long i ); - void insert( const Bu::String &sKey, signed long long i ); - //void insert( const Bu::String &sKey, bool b ); - void insert( const Bu::String &sKey, float d ); - void insert( const Bu::String &sKey, double d ); - using Bu::Hash::insert; - void insertBool( const Bu::String &sKey, bool b ); - void insertInt( const Bu::String &sKey, int64_t i ); - void insertFloat( const Bu::String &sKey, double d ); - void insertStr( const Bu::String &sKey, const Bu::String &s ); - void insertList( const Bu::String &sKey, Gats::List *pL ); - void insertDict( const Bu::String &sKey, Gats::Dictionary *pD ); - Gats::List *insertList( const Bu::String &sKey ); - Gats::Dictionary *insertDict( const Bu::String &sKey ); + void insert( const Bu::String &sKey, const char *s ); + void insert( const Bu::String &sKey, const Bu::String &s ); + void insert( const Bu::String &sKey, char i ); + void insert( const Bu::String &sKey, unsigned char i ); + void insert( const Bu::String &sKey, signed char i ); + void insert( const Bu::String &sKey, unsigned short i ); + void insert( const Bu::String &sKey, signed short i ); + void insert( const Bu::String &sKey, unsigned int i ); + void insert( const Bu::String &sKey, signed int i ); + void insert( const Bu::String &sKey, unsigned long i ); + void insert( const Bu::String &sKey, signed long i ); + void insert( const Bu::String &sKey, unsigned long long i ); + void insert( const Bu::String &sKey, signed long long i ); + //void insert( const Bu::String &sKey, bool b ); + void insert( const Bu::String &sKey, float d ); + void insert( const Bu::String &sKey, double d ); + using Bu::Hash::insert; + void insertBool( const Bu::String &sKey, bool b ); + void insertInt( const Bu::String &sKey, int64_t i ); + void insertFloat( const Bu::String &sKey, double d ); + void insertStr( const Bu::String &sKey, const Bu::String &s ); + void insertList( const Bu::String &sKey, Gats::List *pL ); + void insertDict( const Bu::String &sKey, Gats::Dictionary *pD ); + Gats::List *insertList( const Bu::String &sKey ); + Gats::Dictionary *insertDict( const Bu::String &sKey ); - bool getBool( const Bu::String &sKey ); - int64_t getInt( const Bu::String &sKey ); - double getFloat( const Bu::String &sKey ); - Bu::String getStr( const Bu::String &sKey ); - Gats::List *getList( const Bu::String &sKey ); - Gats::Dictionary *getDict( const Bu::String &sKey ); - - bool getBool( const Bu::String &sKey ) const; - int64_t getInt( const Bu::String &sKey ) const; - double getFloat( const Bu::String &sKey ) const; - Bu::String getStr( const Bu::String &sKey ) const; - Gats::List *getList( const Bu::String &sKey ) const; - Gats::Dictionary *getDict( const Bu::String &sKey ) const; - }; + bool getBool( const Bu::String &sKey ); + int64_t getInt( const Bu::String &sKey ); + double getFloat( const Bu::String &sKey ); + Bu::String getStr( const Bu::String &sKey ); + Gats::List *getList( const Bu::String &sKey ); + Gats::Dictionary *getDict( const Bu::String &sKey ); + + bool getBool( const Bu::String &sKey ) const; + int64_t getInt( const Bu::String &sKey ) const; + double getFloat( const Bu::String &sKey ) const; + Bu::String getStr( const Bu::String &sKey ) const; + Gats::List *getList( const Bu::String &sKey ) const; + Gats::Dictionary *getDict( const Bu::String &sKey ) const; + }; }; namespace Bu diff --git a/c++-libbu++/src/float.cpp b/c++-libbu++/src/float.cpp index c01d824..f7c2737 100644 --- a/c++-libbu++/src/float.cpp +++ b/c++-libbu++/src/float.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/float.h" #include "gats/integer.h" @@ -7,12 +14,12 @@ #include using namespace Bu; Gats::Float::Float() : - fVal( 0.0 ) + fVal( 0.0 ) { } Gats::Float::Float( double f ) : - fVal( f ) + fVal( f ) { } @@ -22,109 +29,109 @@ Gats::Float::~Float() Gats::Object *Gats::Float::clone() const { - return new Gats::Float( fVal ); + return new Gats::Float( fVal ); } void Gats::Float::write( Bu::Stream &rOut ) const { - if( fVal == 0.0 ) - { - if( signbit( fVal ) ) - rOut.write("FZ", 2 ); - else - rOut.write("Fz", 2 ); - } - else if( !isfinite( fVal ) ) - { - if( isnan( fVal ) ) - { - if( signbit( fVal ) ) - rOut.write("FN", 2 ); - else - rOut.write("Fn", 2 ); - } - else - { - if( signbit( fVal ) ) - rOut.write("FI", 2 ); - else - rOut.write("Fi", 2 ); - } - } - else - { - rOut.write("f", 1 ); - double d = fVal; - bool bNeg = false; - int64_t iScale=0; - if( signbit( d ) ) - { - bNeg = true; - d = -d; - } + if( fVal == 0.0 ) + { + if( signbit( fVal ) ) + rOut.write("FZ", 2 ); + else + rOut.write("Fz", 2 ); + } + else if( !isfinite( fVal ) ) + { + if( isnan( fVal ) ) + { + if( signbit( fVal ) ) + rOut.write("FN", 2 ); + else + rOut.write("Fn", 2 ); + } + else + { + if( signbit( fVal ) ) + rOut.write("FI", 2 ); + else + rOut.write("Fi", 2 ); + } + } + else + { + rOut.write("f", 1 ); + double d = fVal; + bool bNeg = false; + int64_t iScale=0; + if( signbit( d ) ) + { + bNeg = true; + d = -d; + } - iScale = log( d ) / 0x1.62e42fefa39efp+2; // log( 256.0 ) - if( iScale < 0 ) iScale--; - d /= pow( 256.0, iScale ); - - Bu::String s; - s += (uint8_t)(d); - d -= (int)d; - for( int j = 0; j < 150 && d; j++ ) - { - d = d*256.0; - s += (uint8_t)d; - d -= (int)d; - } - Gats::Integer::writePackedInt( rOut, bNeg?-s.getSize():s.getSize() ); - rOut.write( s.getStr(), s.getSize() ); - Gats::Integer::writePackedInt( rOut, iScale ); - } + iScale = log( d ) / 0x1.62e42fefa39efp+2; // log( 256.0 ) + if( iScale < 0 ) iScale--; + d /= pow( 256.0, iScale ); + + Bu::String s; + s += (uint8_t)(d); + d -= (int)d; + for( int j = 0; j < 150 && d; j++ ) + { + d = d*256.0; + s += (uint8_t)d; + d -= (int)d; + } + Gats::Integer::writePackedInt( rOut, bNeg?-s.getSize():s.getSize() ); + rOut.write( s.getStr(), s.getSize() ); + Gats::Integer::writePackedInt( rOut, iScale ); + } } void Gats::Float::read( Bu::Stream &rIn, char cType ) { - if( cType == 'F' ) - { - char buf; - rIn.read( &buf, 1 ); - switch( buf ) - { - case 'N': fVal = -NAN; break; - case 'n': fVal = NAN; break; - case 'I': fVal = -INFINITY; break; - case 'i': fVal = INFINITY; break; - case 'Z': fVal = -0.0; break; - case 'z': fVal = 0.0; break; - } - } - else if( cType == 'f' ) - { - int64_t iStr; - Gats::Integer::readPackedInt( rIn, iStr ); - bool bNeg = false; - if( iStr < 0 ) - { - bNeg = true; - iStr = -iStr; - } - Bu::String s( iStr ); - rIn.read( s.getStr(), iStr ); - fVal = 0.0; - for( int j = iStr-1; j > 0; j-- ) - { - fVal = (fVal+(uint8_t)s[j])*0x1p-8; - } - fVal += (uint8_t)s[0]; - int64_t iScale; - Gats::Integer::readPackedInt( rIn, iScale ); - fVal *= pow( 256.0, iScale ); - if( bNeg ) fVal = -fVal; - } + if( cType == 'F' ) + { + char buf; + rIn.read( &buf, 1 ); + switch( buf ) + { + case 'N': fVal = -NAN; break; + case 'n': fVal = NAN; break; + case 'I': fVal = -INFINITY; break; + case 'i': fVal = INFINITY; break; + case 'Z': fVal = -0.0; break; + case 'z': fVal = 0.0; break; + } + } + else if( cType == 'f' ) + { + int64_t iStr; + Gats::Integer::readPackedInt( rIn, iStr ); + bool bNeg = false; + if( iStr < 0 ) + { + bNeg = true; + iStr = -iStr; + } + Bu::String s( iStr ); + rIn.read( s.getStr(), iStr ); + fVal = 0.0; + for( int j = iStr-1; j > 0; j-- ) + { + fVal = (fVal+(uint8_t)s[j])*0x1p-8; + } + fVal += (uint8_t)s[0]; + int64_t iScale; + Gats::Integer::readPackedInt( rIn, iScale ); + fVal *= pow( 256.0, iScale ); + if( bNeg ) fVal = -fVal; + } } Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ) { - return f << "(float) " << flt.getValue(); + return f << "(float) " << flt.getValue(); } diff --git a/c++-libbu++/src/float.h b/c++-libbu++/src/float.h index ba38d6c..d9a1a9a 100644 --- a/c++-libbu++/src/float.h +++ b/c++-libbu++/src/float.h @@ -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. + */ + #ifndef GATS_FLOAT_H #define GATS_FLOAT_H @@ -7,25 +14,25 @@ namespace Gats { - class Float : public Gats::Object - { - public: - Float(); - Float( double f ); - virtual ~Float(); + class Float : public Gats::Object + { + public: + Float(); + Float( double f ); + virtual ~Float(); - virtual Object *clone() const; + virtual Object *clone() const; - virtual Type getType() const { return typeFloat; } - double getValue() const { return fVal; } + virtual Type getType() const { return typeFloat; } + double getValue() const { return fVal; } - virtual void write( Bu::Stream &rOut ) const; - virtual void read( Bu::Stream &rIn, char cType ); + virtual void write( Bu::Stream &rOut ) const; + virtual void read( Bu::Stream &rIn, char cType ); - private: - double fVal; - mutable Bu::String sWriteCache; - }; + private: + double fVal; + mutable Bu::String sWriteCache; + }; } Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ); diff --git a/c++-libbu++/src/gatsc/main.cpp b/c++-libbu++/src/gatsc/main.cpp index 2bac3fd..e07fe82 100644 --- a/c++-libbu++/src/gatsc/main.cpp +++ b/c++-libbu++/src/gatsc/main.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 #include #include @@ -11,63 +18,63 @@ using namespace Bu; class Options : public OptParser { public: - Options( int argc, char *argv[] ) : - bCompile( true ) - { - addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n"); + Options( int argc, char *argv[] ) : + bCompile( true ) + { + addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n"); - addOption( sInput, 'i', "input", "Specify input file."); - addOption( sOutput, 'o', "output", "Specify output file."); + addOption( sInput, 'i', "input", "Specify input file."); + addOption( sOutput, 'o', "output", "Specify output file."); - addOption( bCompile, 'd', "decompile", - "Convert binary gats to text gats."); + addOption( bCompile, 'd', "decompile", + "Convert binary gats to text gats."); - addHelpOption('h', "help", "This Help"); + addHelpOption('h', "help", "This Help"); - setNonOption( slot( this, &Options::setInput ) ); + setNonOption( slot( this, &Options::setInput ) ); - setOverride("decompile", false ); + setOverride("decompile", false ); - parse( argc, argv ); - } + parse( argc, argv ); + } - int setInput( StrArray aParam ) - { - sInput = aParam[0]; - return 0; - } + int setInput( StrArray aParam ) + { + sInput = aParam[0]; + return 0; + } - bool bCompile; - String sInput; - String sOutput; + bool bCompile; + String sInput; + String sOutput; }; int main( int argc, char *argv[] ) { - Options opt( argc, argv ); - - if( opt.sInput.isEmpty() ) - { - sio << "You must specify an input." << sio.nl << sio.nl; - return 1; - } - - if( opt.sOutput.isEmpty() ) - { - opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') ); - opt.sOutput += ".gats"; - } - - if( opt.bCompile ) - { - File fIn( opt.sInput, File::Read ); - File fOut( opt.sOutput, File::WriteNew ); - Gats::GatsStream gs( fOut ); - Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() ); - gs.writeObject( pObj ); - delete pObj; - } - - return 0; + Options opt( argc, argv ); + + if( opt.sInput.isEmpty() ) + { + sio << "You must specify an input." << sio.nl << sio.nl; + return 1; + } + + if( opt.sOutput.isEmpty() ) + { + opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') ); + opt.sOutput += ".gats"; + } + + if( opt.bCompile ) + { + File fIn( opt.sInput, File::Read ); + File fOut( opt.sOutput, File::WriteNew ); + Gats::GatsStream gs( fOut ); + Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() ); + gs.writeObject( pObj ); + delete pObj; + } + + return 0; } diff --git a/c++-libbu++/src/gatscon/clientthread.cpp b/c++-libbu++/src/gatscon/clientthread.cpp index 4c7b72a..4032a50 100644 --- a/c++-libbu++/src/gatscon/clientthread.cpp +++ b/c++-libbu++/src/gatscon/clientthread.cpp @@ -1,13 +1,20 @@ +/* + * 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 "clientthread.h" #include ClientThread::ClientThread( QObject *pParent, const QByteArray &baHost, - int iPort ) : - QThread( pParent ), - baHost( baHost ), - iPort( iPort ), - gsCli( ssCli ) + int iPort ) : + QThread( pParent ), + baHost( baHost ), + iPort( iPort ), + gsCli( ssCli ) { } @@ -17,22 +24,22 @@ ClientThread::~ClientThread() void ClientThread::send( Gats::Object *pObj ) { - gsCli.writeObject( pObj ); + gsCli.writeObject( pObj ); } void ClientThread::run() { - ssCli.setStream( - new Bu::TcpSocket( baHost.constData(), iPort ) - ); - - while( !ssCli.isEos() ) - { - Gats::Object *pObj = gsCli.readObject(); - if( pObj == NULL ) - continue; - - emit recv( pObj ); - } + ssCli.setStream( + new Bu::TcpSocket( baHost.constData(), iPort ) + ); + + while( !ssCli.isEos() ) + { + Gats::Object *pObj = gsCli.readObject(); + if( pObj == NULL ) + continue; + + emit recv( pObj ); + } } diff --git a/c++-libbu++/src/gatscon/clientthread.h b/c++-libbu++/src/gatscon/clientthread.h index 3182d37..a4343ee 100644 --- a/c++-libbu++/src/gatscon/clientthread.h +++ b/c++-libbu++/src/gatscon/clientthread.h @@ -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. + */ + #ifndef CLIENT_THREAD_H #define CLIENT_THREAD_H @@ -9,29 +16,29 @@ namespace Gats { - class Object; + class Object; }; class ClientThread : public QThread { - Q_OBJECT; + Q_OBJECT; public: - ClientThread( QObject *pParent, const QByteArray &baHost, int iPort ); - virtual ~ClientThread(); + ClientThread( QObject *pParent, const QByteArray &baHost, int iPort ); + virtual ~ClientThread(); - void send( Gats::Object *pObj ); + void send( Gats::Object *pObj ); signals: - void recv( Gats::Object *pObj ); + void recv( Gats::Object *pObj ); protected: - virtual void run(); + virtual void run(); private: - QByteArray baHost; - int iPort; - Bu::StreamStack ssCli; - Gats::GatsStream gsCli; + QByteArray baHost; + int iPort; + Bu::StreamStack ssCli; + Gats::GatsStream gsCli; }; #endif diff --git a/c++-libbu++/src/gatscon/clientwidget.cpp b/c++-libbu++/src/gatscon/clientwidget.cpp index 941d9fa..f13e736 100644 --- a/c++-libbu++/src/gatscon/clientwidget.cpp +++ b/c++-libbu++/src/gatscon/clientwidget.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 "clientwidget.h" #include "clientthread.h" @@ -14,16 +21,16 @@ using namespace Bu; ClientWidget::ClientWidget( QWidget *pParent, const QByteArray &baHost, - int iPort ) : - QWidget( pParent ) + int iPort ) : + QWidget( pParent ) { - setupUi( this ); + setupUi( this ); - pCli = new ClientThread( this, baHost, iPort ); - connect( pCli, SIGNAL(recv( Gats::Object *)), - this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection ); - - pCli->start(); + pCli = new ClientThread( this, baHost, iPort ); + connect( pCli, SIGNAL(recv( Gats::Object *)), + this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection ); + + pCli->start(); } ClientWidget::~ClientWidget() @@ -32,51 +39,51 @@ ClientWidget::~ClientWidget() void ClientWidget::saveTo( const QString &sFile ) { - File fOut( sFile.toAscii().constData(), File::WriteNew ); - Gats::GatsStream gsOut( fOut ); - QTreeWidgetItem *pRoot = twHistory->invisibleRootItem(); - for( int j = 0; j < pRoot->childCount(); j++ ) - { - Gats::Object *pObj = treeToGats( pRoot->child( j ) ); - gsOut.writeObject( pObj ); - delete pObj; - } + File fOut( sFile.toAscii().constData(), File::WriteNew ); + Gats::GatsStream gsOut( fOut ); + QTreeWidgetItem *pRoot = twHistory->invisibleRootItem(); + for( int j = 0; j < pRoot->childCount(); j++ ) + { + Gats::Object *pObj = treeToGats( pRoot->child( j ) ); + gsOut.writeObject( pObj ); + delete pObj; + } } void ClientWidget::send() { - try - { - Gats::Object *pObj = Gats::Object::strToGats( - leGats->text().toAscii().constData() - ); - sio << "Send: " << *pObj << sio.nl; - QTreeWidgetItem *pIt = new QTreeWidgetItem( - twHistory->invisibleRootItem() - ); - pIt->setText( 0, "send" ); - gatsToTree( pIt, pObj ); - pCli->send( pObj ); - delete pObj; + try + { + Gats::Object *pObj = Gats::Object::strToGats( + leGats->text().toAscii().constData() + ); + sio << "Send: " << *pObj << sio.nl; + QTreeWidgetItem *pIt = new QTreeWidgetItem( + twHistory->invisibleRootItem() + ); + pIt->setText( 0, "send" ); + gatsToTree( pIt, pObj ); + pCli->send( pObj ); + delete pObj; - leGats->setText(""); - leGats->setFocus(); - } - catch( Bu::ExceptionBase &e ) - { - QMessageBox::critical( this, "Gats Console - Error", e.what() ); - } + leGats->setText(""); + leGats->setFocus(); + } + catch( Bu::ExceptionBase &e ) + { + QMessageBox::critical( this, "Gats Console - Error", e.what() ); + } } void ClientWidget::recv( Gats::Object *pObj ) { - sio << "Recv: " << *pObj << sio.nl; + sio << "Recv: " << *pObj << sio.nl; - QTreeWidgetItem *pIt = new QTreeWidgetItem( - twHistory->invisibleRootItem() - ); - pIt->setText( 0, "recv" ); - gatsToTree( pIt, pObj ); - delete pObj; + QTreeWidgetItem *pIt = new QTreeWidgetItem( + twHistory->invisibleRootItem() + ); + pIt->setText( 0, "recv" ); + gatsToTree( pIt, pObj ); + delete pObj; } diff --git a/c++-libbu++/src/gatscon/clientwidget.h b/c++-libbu++/src/gatscon/clientwidget.h index 06c154d..b40adf4 100644 --- a/c++-libbu++/src/gatscon/clientwidget.h +++ b/c++-libbu++/src/gatscon/clientwidget.h @@ -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. + */ + #ifndef CLIENT_WIDGET_H #define CLIENT_WIDGET_H @@ -7,24 +14,24 @@ namespace Gats { - class Object; + class Object; }; class ClientWidget : public QWidget, protected Ui::ClientWidget, public IoBase { - Q_OBJECT; + Q_OBJECT; public: - ClientWidget( QWidget *pParent, const QByteArray &baHost, int iPort ); - virtual ~ClientWidget(); + ClientWidget( QWidget *pParent, const QByteArray &baHost, int iPort ); + virtual ~ClientWidget(); - virtual void saveTo( const QString &sFile ); + virtual void saveTo( const QString &sFile ); public slots: - void send(); - void recv( Gats::Object *pObj ); + void send(); + void recv( Gats::Object *pObj ); private: - class ClientThread *pCli; + class ClientThread *pCli; }; #endif diff --git a/c++-libbu++/src/gatscon/connectdlg.cpp b/c++-libbu++/src/gatscon/connectdlg.cpp index 589ae97..0bb159b 100644 --- a/c++-libbu++/src/gatscon/connectdlg.cpp +++ b/c++-libbu++/src/gatscon/connectdlg.cpp @@ -1,9 +1,16 @@ +/* + * 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 "connectdlg.h" ConnectDlg::ConnectDlg( QWidget *pParent ) : - QDialog( pParent ) + QDialog( pParent ) { - setupUi( this ); + setupUi( this ); } ConnectDlg::~ConnectDlg() @@ -12,11 +19,11 @@ ConnectDlg::~ConnectDlg() QByteArray ConnectDlg::getHostname() const { - return leHost->text().toAscii(); + return leHost->text().toAscii(); } int ConnectDlg::getPort() const { - return sbPort->value(); + return sbPort->value(); } diff --git a/c++-libbu++/src/gatscon/connectdlg.h b/c++-libbu++/src/gatscon/connectdlg.h index 57ea6cd..7396ef6 100644 --- a/c++-libbu++/src/gatscon/connectdlg.h +++ b/c++-libbu++/src/gatscon/connectdlg.h @@ -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. + */ + #ifndef CONNECT_DLG_H #define CONNECT_DLG_H @@ -5,13 +12,13 @@ class ConnectDlg : public QDialog, protected Ui::ConnectDlg { - Q_OBJECT; + Q_OBJECT; public: - ConnectDlg( QWidget *pParent ); - virtual ~ConnectDlg(); + ConnectDlg( QWidget *pParent ); + virtual ~ConnectDlg(); - QByteArray getHostname() const; - int getPort() const; + QByteArray getHostname() const; + int getPort() const; }; #endif diff --git a/c++-libbu++/src/gatscon/filewidget.cpp b/c++-libbu++/src/gatscon/filewidget.cpp index dbd70fd..23f6839 100644 --- a/c++-libbu++/src/gatscon/filewidget.cpp +++ b/c++-libbu++/src/gatscon/filewidget.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 "filewidget.h" #include "gatstotree.h" @@ -12,28 +19,28 @@ using namespace Bu; FileWidget::FileWidget( QWidget *pParent ) : - QWidget( pParent ) + QWidget( pParent ) { - setupUi( this ); + setupUi( this ); } FileWidget::FileWidget( QWidget *pParent, QString sFile ) : - QWidget( pParent ) + QWidget( pParent ) { - setupUi( this ); + setupUi( this ); - File fIn( sFile.toAscii().constData(), File::Read ); - Gats::GatsStream gsIn( fIn ); - Gats::Object *pObj; - while( (pObj = gsIn.readObject()) ) - { - QTreeWidgetItem *pNew = new QTreeWidgetItem( - twGats->invisibleRootItem() - ); - pNew->setText( 0, "" ); - gatsToTree( pNew, pObj ); - delete pObj; - } + File fIn( sFile.toAscii().constData(), File::Read ); + Gats::GatsStream gsIn( fIn ); + Gats::Object *pObj; + while( (pObj = gsIn.readObject()) ) + { + QTreeWidgetItem *pNew = new QTreeWidgetItem( + twGats->invisibleRootItem() + ); + pNew->setText( 0, "" ); + gatsToTree( pNew, pObj ); + delete pObj; + } } FileWidget::~FileWidget() @@ -42,28 +49,28 @@ FileWidget::~FileWidget() void FileWidget::saveTo( const QString &sFile ) { - File fOut( sFile.toAscii().constData(), File::WriteNew ); - Gats::GatsStream gsOut( fOut ); - QTreeWidgetItem *pRoot = twGats->invisibleRootItem(); - for( int j = 0; j < pRoot->childCount(); j++ ) - { - Gats::Object *pObj = treeToGats( pRoot->child( j ) ); - gsOut.writeObject( pObj ); - delete pObj; - } + File fOut( sFile.toAscii().constData(), File::WriteNew ); + Gats::GatsStream gsOut( fOut ); + QTreeWidgetItem *pRoot = twGats->invisibleRootItem(); + for( int j = 0; j < pRoot->childCount(); j++ ) + { + Gats::Object *pObj = treeToGats( pRoot->child( j ) ); + gsOut.writeObject( pObj ); + delete pObj; + } } void FileWidget::addRootItem() { - QString sText = QInputDialog::getText( this, "Gats Console - Add Root Item", - "Gats:"); - Gats::Object *pObj = Gats::Object::strToGats( sText.toAscii().constData() ); - QTreeWidgetItem *pNew = new QTreeWidgetItem( - twGats->invisibleRootItem() - ); - pNew->setText( 0, "" ); - gatsToTree( pNew, pObj ); - delete pObj; + QString sText = QInputDialog::getText( this, "Gats Console - Add Root Item", + "Gats:"); + Gats::Object *pObj = Gats::Object::strToGats( sText.toAscii().constData() ); + QTreeWidgetItem *pNew = new QTreeWidgetItem( + twGats->invisibleRootItem() + ); + pNew->setText( 0, "" ); + gatsToTree( pNew, pObj ); + delete pObj; } void FileWidget::delRootItem() diff --git a/c++-libbu++/src/gatscon/filewidget.h b/c++-libbu++/src/gatscon/filewidget.h index 9993bfe..1426eae 100644 --- a/c++-libbu++/src/gatscon/filewidget.h +++ b/c++-libbu++/src/gatscon/filewidget.h @@ -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. + */ + #ifndef FILE_WIDGET_H #define FILE_WIDGET_H @@ -6,22 +13,22 @@ namespace Gats { - class Object; + class Object; }; class FileWidget : public QWidget, protected Ui::FileWidget, public IoBase { - Q_OBJECT; + Q_OBJECT; public: - FileWidget( QWidget *pParent=NULL ); - FileWidget( QWidget *pParent, QString sFile ); - virtual ~FileWidget(); + FileWidget( QWidget *pParent=NULL ); + FileWidget( QWidget *pParent, QString sFile ); + virtual ~FileWidget(); - virtual void saveTo( const QString &sFile ); + virtual void saveTo( const QString &sFile ); public slots: - void addRootItem(); - void delRootItem(); + void addRootItem(); + void delRootItem(); private: }; diff --git a/c++-libbu++/src/gatscon/gatstotree.cpp b/c++-libbu++/src/gatscon/gatstotree.cpp index e388d5e..192b395 100644 --- a/c++-libbu++/src/gatscon/gatstotree.cpp +++ b/c++-libbu++/src/gatscon/gatstotree.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 "gatstotree.h" #include @@ -6,86 +13,86 @@ void gatsToTree( QTreeWidgetItem *p, Gats::Object *pObj ) { - switch( pObj->getType() ) - { - case Gats::typeInteger: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeString: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeFloat: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeBoolean: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeList: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeDictionary: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - - case Gats::typeNull: - gatsToTree( p, dynamic_cast( pObj ) ); - break; - } + switch( pObj->getType() ) + { + case Gats::typeInteger: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeString: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeFloat: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeBoolean: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeList: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeDictionary: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeNull: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + } } void gatsToTree( QTreeWidgetItem *p, Gats::Integer *pObj ) { - p->setText( 1, "int"); - p->setText( 2, QString("%1").arg( pObj->getValue() ) ); + p->setText( 1, "int"); + p->setText( 2, QString("%1").arg( pObj->getValue() ) ); } void gatsToTree( QTreeWidgetItem *p, Gats::String *pObj ) { - p->setText( 1, "str"); - p->setText( 2, QString("%1").arg( pObj->getStr() ) ); + p->setText( 1, "str"); + p->setText( 2, QString("%1").arg( pObj->getStr() ) ); } void gatsToTree( QTreeWidgetItem *p, Gats::Float *pObj ) { - p->setText( 1, "float"); - p->setText( 2, QString("%1").arg( pObj->getValue() ) ); + p->setText( 1, "float"); + p->setText( 2, QString("%1").arg( pObj->getValue() ) ); } void gatsToTree( QTreeWidgetItem *p, Gats::Boolean *pObj ) { - p->setText( 1, "bool"); - p->setText( 2, pObj->getValue()?"true":"false" ); + p->setText( 1, "bool"); + p->setText( 2, pObj->getValue()?"true":"false" ); } void gatsToTree( QTreeWidgetItem *p, Gats::List *pObj ) { - p->setText( 1, "list"); - int j = 0; - for( Gats::List::iterator i = pObj->begin(); i; i++ ) - { - QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); - pIt->setText( 0, QString("%1").arg( j++ ) ); - gatsToTree( pIt, *i ); - } + p->setText( 1, "list"); + int j = 0; + for( Gats::List::iterator i = pObj->begin(); i; i++ ) + { + QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); + pIt->setText( 0, QString("%1").arg( j++ ) ); + gatsToTree( pIt, *i ); + } } void gatsToTree( QTreeWidgetItem *p, Gats::Dictionary *pObj ) { - p->setText( 1, "dict"); - for( Gats::Dictionary::iterator i = pObj->begin(); i; i++ ) - { - QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); - pIt->setText( 0, QString( i.getKey().getStr() ) ); - gatsToTree( pIt, *i ); - } + p->setText( 1, "dict"); + for( Gats::Dictionary::iterator i = pObj->begin(); i; i++ ) + { + QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); + pIt->setText( 0, QString( i.getKey().getStr() ) ); + gatsToTree( pIt, *i ); + } } void gatsToTree( QTreeWidgetItem *p, Gats::Null *pObj ) { - p->setText( 1, "null"); + p->setText( 1, "null"); } diff --git a/c++-libbu++/src/gatscon/gatstotree.h b/c++-libbu++/src/gatscon/gatstotree.h index a803017..dc8f451 100644 --- a/c++-libbu++/src/gatscon/gatstotree.h +++ b/c++-libbu++/src/gatscon/gatstotree.h @@ -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. + */ + #ifndef GATS_TO_TREE_H #define GATS_TO_TREE_H @@ -5,13 +12,13 @@ class QTreeWidgetItem; namespace Gats { - class Integer; - class String; - class Float; - class Boolean; - class List; - class Dictionary; - class Object; + class Integer; + class String; + class Float; + class Boolean; + class List; + class Dictionary; + class Object; }; #include diff --git a/c++-libbu++/src/gatscon/iobase.cpp b/c++-libbu++/src/gatscon/iobase.cpp index 309444c..40af455 100644 --- a/c++-libbu++/src/gatscon/iobase.cpp +++ b/c++-libbu++/src/gatscon/iobase.cpp @@ -1 +1,8 @@ +/* + * 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 "iobase.h" diff --git a/c++-libbu++/src/gatscon/iobase.h b/c++-libbu++/src/gatscon/iobase.h index 5bd3843..4475551 100644 --- a/c++-libbu++/src/gatscon/iobase.h +++ b/c++-libbu++/src/gatscon/iobase.h @@ -1,10 +1,17 @@ +/* + * 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. + */ + #ifndef IO_BASE_H #define IO_BASE_H class IoBase { public: - virtual void saveTo( const class QString &sFile )=0; + virtual void saveTo( const class QString &sFile )=0; }; #endif diff --git a/c++-libbu++/src/gatscon/main.cpp b/c++-libbu++/src/gatscon/main.cpp index b9b2327..11b6d4a 100644 --- a/c++-libbu++/src/gatscon/main.cpp +++ b/c++-libbu++/src/gatscon/main.cpp @@ -1,13 +1,20 @@ +/* + * 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 "mainwnd.h" #include int main( int argc, char *argv[] ) { - QApplication app( argc, argv ); + QApplication app( argc, argv ); - MainWnd wnd; - wnd.show(); + MainWnd wnd; + wnd.show(); - return app.exec(); + return app.exec(); } diff --git a/c++-libbu++/src/gatscon/mainwnd.cpp b/c++-libbu++/src/gatscon/mainwnd.cpp index 5d31019..7cce116 100644 --- a/c++-libbu++/src/gatscon/mainwnd.cpp +++ b/c++-libbu++/src/gatscon/mainwnd.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 "mainwnd.h" #include "clientwidget.h" @@ -12,10 +19,10 @@ MainWnd::MainWnd() { - setupUi( this ); + setupUi( this ); - pMode = new QLabel( "Idle", this ); - statusBar()->addPermanentWidget( pMode ); + pMode = new QLabel( "Idle", this ); + statusBar()->addPermanentWidget( pMode ); } MainWnd::~MainWnd() @@ -24,96 +31,96 @@ MainWnd::~MainWnd() void MainWnd::connect() { - ConnectDlg dlg( this ); - if( dlg.exec() == QDialog::Accepted ) - { - sCurFile.clear(); - setCentralWidget( - new ClientWidget( - this, dlg.getHostname(), dlg.getPort() - ) - ); - pMode->setText( - QString("Client Mode: %1:%2").arg( QString(dlg.getHostname()) ). - arg( dlg.getPort() ) - ); - } + ConnectDlg dlg( this ); + if( dlg.exec() == QDialog::Accepted ) + { + sCurFile.clear(); + setCentralWidget( + new ClientWidget( + this, dlg.getHostname(), dlg.getPort() + ) + ); + pMode->setText( + QString("Client Mode: %1:%2").arg( QString(dlg.getHostname()) ). + arg( dlg.getPort() ) + ); + } } void MainWnd::proxy() { - SetupProxyDlg dlg( this ); - - if( dlg.exec() == QDialog::Accepted ) - { - sCurFile.clear(); - setCentralWidget( - new ProxyWidget( - this, dlg.getPortIn(), dlg.getHostOut(), dlg.getPortOut() - ) - ); - pMode->setText( - QString("Proxy Mode: :%1 -> %2:%3").arg( dlg.getPortIn() ). - arg( QString(dlg.getHostOut()) ). - arg( dlg.getPortOut() ) - ); - } + SetupProxyDlg dlg( this ); + + if( dlg.exec() == QDialog::Accepted ) + { + sCurFile.clear(); + setCentralWidget( + new ProxyWidget( + this, dlg.getPortIn(), dlg.getHostOut(), dlg.getPortOut() + ) + ); + pMode->setText( + QString("Proxy Mode: :%1 -> %2:%3").arg( dlg.getPortIn() ). + arg( QString(dlg.getHostOut()) ). + arg( dlg.getPortOut() ) + ); + } } void MainWnd::open() { - QString sFile = QFileDialog::getOpenFileName( - this, "Gats Console - open gats file" - ); - if( sFile.isEmpty() ) - return; - - sCurFile = sFile; - setCentralWidget( - new FileWidget( this, sFile ) - ); - pMode->setText( QString("File mode: %1").arg( sCurFile ) ); + QString sFile = QFileDialog::getOpenFileName( + this, "Gats Console - open gats file" + ); + if( sFile.isEmpty() ) + return; + + sCurFile = sFile; + setCentralWidget( + new FileWidget( this, sFile ) + ); + pMode->setText( QString("File mode: %1").arg( sCurFile ) ); } void MainWnd::newFile() { - sCurFile.clear(); - setCentralWidget( - new FileWidget( this ) - ); - pMode->setText( QString("File mode: ") ); + sCurFile.clear(); + setCentralWidget( + new FileWidget( this ) + ); + pMode->setText( QString("File mode: ") ); } void MainWnd::save() { - if( sCurFile.isEmpty() ) - { - saveAs(); - } - else - { - IoBase *pIo = dynamic_cast(centralWidget()); - if( !pIo ) - return; - - pIo->saveTo( sCurFile ); - } + if( sCurFile.isEmpty() ) + { + saveAs(); + } + else + { + IoBase *pIo = dynamic_cast(centralWidget()); + if( !pIo ) + return; + + pIo->saveTo( sCurFile ); + } } void MainWnd::saveAs() { - IoBase *pIo = dynamic_cast(centralWidget()); - if( !pIo ) - return; + IoBase *pIo = dynamic_cast(centralWidget()); + if( !pIo ) + return; - QString sFile = QFileDialog::getSaveFileName( - this, "Gats Console - save gats file" - ); - if( sFile.isEmpty() ) - return; + QString sFile = QFileDialog::getSaveFileName( + this, "Gats Console - save gats file" + ); + if( sFile.isEmpty() ) + return; - pIo->saveTo( sFile ); + pIo->saveTo( sFile ); - sCurFile = sFile; + sCurFile = sFile; } diff --git a/c++-libbu++/src/gatscon/mainwnd.h b/c++-libbu++/src/gatscon/mainwnd.h index d1ae080..2a5c3fa 100644 --- a/c++-libbu++/src/gatscon/mainwnd.h +++ b/c++-libbu++/src/gatscon/mainwnd.h @@ -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. + */ + #ifndef MAIN_WND_H #define MAIN_WND_H @@ -5,22 +12,22 @@ class MainWnd : public QMainWindow, protected Ui::MainWnd { - Q_OBJECT; + Q_OBJECT; public: - MainWnd(); - virtual ~MainWnd(); - + MainWnd(); + virtual ~MainWnd(); + public slots: - void connect(); - void proxy(); - void open(); - void newFile(); - void save(); - void saveAs(); + void connect(); + void proxy(); + void open(); + void newFile(); + void save(); + void saveAs(); private: - QString sCurFile; - class QLabel *pMode; + QString sCurFile; + class QLabel *pMode; }; #endif diff --git a/c++-libbu++/src/gatscon/proxythread.cpp b/c++-libbu++/src/gatscon/proxythread.cpp index 574b56b..733af7f 100644 --- a/c++-libbu++/src/gatscon/proxythread.cpp +++ b/c++-libbu++/src/gatscon/proxythread.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 "proxythread.h" #include @@ -10,15 +17,15 @@ using namespace Bu; ProxyThread::ProxyThread( QObject *pParent, int iPortIn, - const QByteArray &baHostOut, int iPortOut ) : - QThread( pParent ), - pHost( NULL ), - iPortIn( iPortIn ), - baHostOut( baHostOut ), - iPortOut( iPortOut ), - gsCli( ssCli ) + const QByteArray &baHostOut, int iPortOut ) : + QThread( pParent ), + pHost( NULL ), + iPortIn( iPortIn ), + baHostOut( baHostOut ), + iPortOut( iPortOut ), + gsCli( ssCli ) { - pHost = new ProxyHostThread( pParent, this ); + pHost = new ProxyHostThread( pParent, this ); } ProxyThread::~ProxyThread() @@ -27,52 +34,52 @@ ProxyThread::~ProxyThread() void ProxyThread::send( Gats::Object *pObj ) { - MemBuf bg; - Gats::GatsStream gs( bg ); - gs.writeObject( pObj ); - ssCli.write( bg.getString().getStr(), bg.getString().getSize() ); + MemBuf bg; + Gats::GatsStream gs( bg ); + gs.writeObject( pObj ); + ssCli.write( bg.getString().getStr(), bg.getString().getSize() ); } void ProxyThread::run() { - int iSockIn; + int iSockIn; - { - TcpServerSocket tsIn( iPortIn ); - do - { - iSockIn = tsIn.accept( 5 ); - } while( iSockIn < 0 ); - } + { + TcpServerSocket tsIn( iPortIn ); + do + { + iSockIn = tsIn.accept( 5 ); + } while( iSockIn < 0 ); + } - emit gotConnection(); + emit gotConnection(); - ssCli.setStream( new TcpSocket( iSockIn ) ); - ssCli.setBlocking( true ); + ssCli.setStream( new TcpSocket( iSockIn ) ); + ssCli.setBlocking( true ); - pHost->setStream( - new TcpSocket( baHostOut.constData(), iPortOut ) - ); + pHost->setStream( + new TcpSocket( baHostOut.constData(), iPortOut ) + ); - pHost->start(); + pHost->start(); - while( !ssCli.isEos() ) - { - Gats::Object *pObj = gsCli.readObject(); - if( pObj == NULL ) - continue; + while( !ssCli.isEos() ) + { + Gats::Object *pObj = gsCli.readObject(); + if( pObj == NULL ) + continue; - pHost->send( pObj ); - emit recv( pObj ); - } + pHost->send( pObj ); + emit recv( pObj ); + } } ProxyHostThread::ProxyHostThread( QObject *pParent, ProxyThread *pClient ) : - QThread( pParent ), - pClient( pClient ), - ssHst(), - gsHst( ssHst ) + QThread( pParent ), + pClient( pClient ), + ssHst(), + gsHst( ssHst ) { } @@ -82,27 +89,27 @@ ProxyHostThread::~ProxyHostThread() void ProxyHostThread::send( Gats::Object *pObj ) { - MemBuf bg; - Gats::GatsStream gs( bg ); - gs.writeObject( pObj ); - ssHst.write( bg.getString().getStr(), bg.getString().getSize() ); + MemBuf bg; + Gats::GatsStream gs( bg ); + gs.writeObject( pObj ); + ssHst.write( bg.getString().getStr(), bg.getString().getSize() ); } void ProxyHostThread::setStream( Bu::Stream *pStr ) { - ssHst.setStream( pStr ); + ssHst.setStream( pStr ); } void ProxyHostThread::run() { - while( !ssHst.isEos() ) - { - Gats::Object *pObj = gsHst.readObject(); - if( pObj == NULL ) - continue; - - pClient->send( pObj ); - emit recv( pObj ); - } + while( !ssHst.isEos() ) + { + Gats::Object *pObj = gsHst.readObject(); + if( pObj == NULL ) + continue; + + pClient->send( pObj ); + emit recv( pObj ); + } } diff --git a/c++-libbu++/src/gatscon/proxythread.h b/c++-libbu++/src/gatscon/proxythread.h index df75046..e53ca2c 100644 --- a/c++-libbu++/src/gatscon/proxythread.h +++ b/c++-libbu++/src/gatscon/proxythread.h @@ -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. + */ + #ifndef PROXY_THREAD_H #define PROXY_THREAD_H @@ -8,53 +15,53 @@ class ProxyThread : public QThread { - Q_OBJECT; + Q_OBJECT; public: - ProxyThread( QObject *pParent, int iPortIn, const QByteArray &baHostOut, - int iPortOut ); - virtual ~ProxyThread(); + ProxyThread( QObject *pParent, int iPortIn, const QByteArray &baHostOut, + int iPortOut ); + virtual ~ProxyThread(); - class ProxyHostThread *pHost; + class ProxyHostThread *pHost; - void send( Gats::Object *pObj ); + void send( Gats::Object *pObj ); signals: - void recv( Gats::Object *pObj ); - void gotConnection(); + void recv( Gats::Object *pObj ); + void gotConnection(); protected: - virtual void run(); + virtual void run(); private: - int iPortIn; - QByteArray baHostOut; - int iPortOut; + int iPortIn; + QByteArray baHostOut; + int iPortOut; - Bu::StreamStack ssCli; - Gats::GatsStream gsCli; + Bu::StreamStack ssCli; + Gats::GatsStream gsCli; }; class ProxyHostThread : public QThread { - Q_OBJECT; + Q_OBJECT; public: - ProxyHostThread( QObject *pParent, ProxyThread *pClient ); - virtual ~ProxyHostThread(); + ProxyHostThread( QObject *pParent, ProxyThread *pClient ); + virtual ~ProxyHostThread(); - void send( Gats::Object *pObj ); + void send( Gats::Object *pObj ); - void setStream( Bu::Stream *pStr ); + void setStream( Bu::Stream *pStr ); signals: - void recv( Gats::Object *pObj ); + void recv( Gats::Object *pObj ); protected: - virtual void run(); + virtual void run(); private: - ProxyThread *pClient; - Bu::StreamStack ssHst; - Gats::GatsStream gsHst; + ProxyThread *pClient; + Bu::StreamStack ssHst; + Gats::GatsStream gsHst; }; #endif diff --git a/c++-libbu++/src/gatscon/proxywidget.cpp b/c++-libbu++/src/gatscon/proxywidget.cpp index 215f95f..c95e39a 100644 --- a/c++-libbu++/src/gatscon/proxywidget.cpp +++ b/c++-libbu++/src/gatscon/proxywidget.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 "proxywidget.h" #include "proxythread.h" @@ -14,22 +21,22 @@ using namespace Bu; ProxyWidget::ProxyWidget( QWidget *pParent, int iPortIn, - const QByteArray baHost, int iPortOut ) : - QWidget( pParent ), - pPrx( NULL ) + const QByteArray baHost, int iPortOut ) : + QWidget( pParent ), + pPrx( NULL ) { - setupUi( this ); + setupUi( this ); - pPrx = new ProxyThread( this, iPortIn, baHost, iPortOut ); + pPrx = new ProxyThread( this, iPortIn, baHost, iPortOut ); - connect( pPrx, SIGNAL(gotConnection()), - this, SLOT(gotConnection()), Qt::QueuedConnection ); - connect( pPrx, SIGNAL(recv( Gats::Object *)), - this, SLOT(clientRecv(Gats::Object *)), Qt::QueuedConnection ); - connect( pPrx->pHost, SIGNAL(recv( Gats::Object *)), - this, SLOT(hostRecv(Gats::Object *)), Qt::QueuedConnection ); + connect( pPrx, SIGNAL(gotConnection()), + this, SLOT(gotConnection()), Qt::QueuedConnection ); + connect( pPrx, SIGNAL(recv( Gats::Object *)), + this, SLOT(clientRecv(Gats::Object *)), Qt::QueuedConnection ); + connect( pPrx->pHost, SIGNAL(recv( Gats::Object *)), + this, SLOT(hostRecv(Gats::Object *)), Qt::QueuedConnection ); - pPrx->start(); + pPrx->start(); } ProxyWidget::~ProxyWidget() @@ -38,94 +45,94 @@ ProxyWidget::~ProxyWidget() void ProxyWidget::saveTo( const QString &sFile ) { - File fOut( sFile.toAscii().constData(), File::WriteNew ); - Gats::GatsStream gsOut( fOut ); - QTreeWidgetItem *pRoot = twHistory->invisibleRootItem(); - for( int j = 0; j < pRoot->childCount(); j++ ) - { - Gats::Object *pObj = treeToGats( pRoot->child( j ) ); - gsOut.writeObject( pObj ); - delete pObj; - } + File fOut( sFile.toAscii().constData(), File::WriteNew ); + Gats::GatsStream gsOut( fOut ); + QTreeWidgetItem *pRoot = twHistory->invisibleRootItem(); + for( int j = 0; j < pRoot->childCount(); j++ ) + { + Gats::Object *pObj = treeToGats( pRoot->child( j ) ); + gsOut.writeObject( pObj ); + delete pObj; + } } void ProxyWidget::sendToClient() { - try - { - Gats::Object *pObj = Gats::Object::strToGats( - leGats->text().toAscii().constData() - ); - sio << "Send: " << *pObj << sio.nl; - QTreeWidgetItem *pIt = new QTreeWidgetItem( - twHistory->invisibleRootItem() - ); - pIt->setText( 0, "proxy -> client" ); - gatsToTree( pIt, pObj ); - pPrx->send( pObj ); - delete pObj; - - leGats->setText(""); - leGats->setFocus(); - } - catch( Bu::ExceptionBase &e ) - { - QMessageBox::critical( this, "Gats Console - Error", e.what() ); - } + try + { + Gats::Object *pObj = Gats::Object::strToGats( + leGats->text().toAscii().constData() + ); + sio << "Send: " << *pObj << sio.nl; + QTreeWidgetItem *pIt = new QTreeWidgetItem( + twHistory->invisibleRootItem() + ); + pIt->setText( 0, "proxy -> client" ); + gatsToTree( pIt, pObj ); + pPrx->send( pObj ); + delete pObj; + + leGats->setText(""); + leGats->setFocus(); + } + catch( Bu::ExceptionBase &e ) + { + QMessageBox::critical( this, "Gats Console - Error", e.what() ); + } } void ProxyWidget::sendToServer() { - try - { - Gats::Object *pObj = Gats::Object::strToGats( - leGats->text().toAscii().constData() - ); - sio << "Send: " << *pObj << sio.nl; - QTreeWidgetItem *pIt = new QTreeWidgetItem( - twHistory->invisibleRootItem() - ); - pIt->setText( 0, "proxy -> host" ); - gatsToTree( pIt, pObj ); - pPrx->pHost->send( pObj ); - delete pObj; - - leGats->setText(""); - leGats->setFocus(); - } - catch( Bu::ExceptionBase &e ) - { - QMessageBox::critical( this, "Gats Console - Error", e.what() ); - } + try + { + Gats::Object *pObj = Gats::Object::strToGats( + leGats->text().toAscii().constData() + ); + sio << "Send: " << *pObj << sio.nl; + QTreeWidgetItem *pIt = new QTreeWidgetItem( + twHistory->invisibleRootItem() + ); + pIt->setText( 0, "proxy -> host" ); + gatsToTree( pIt, pObj ); + pPrx->pHost->send( pObj ); + delete pObj; + + leGats->setText(""); + leGats->setFocus(); + } + catch( Bu::ExceptionBase &e ) + { + QMessageBox::critical( this, "Gats Console - Error", e.what() ); + } } void ProxyWidget::clientRecv( Gats::Object *pObj ) { - sio << "Recv: " << *pObj << sio.nl; - - QTreeWidgetItem *pIt = new QTreeWidgetItem( - twHistory->invisibleRootItem() - ); - pIt->setText( 0, "client -> host" ); - gatsToTree( pIt, pObj ); - delete pObj; + sio << "Recv: " << *pObj << sio.nl; + + QTreeWidgetItem *pIt = new QTreeWidgetItem( + twHistory->invisibleRootItem() + ); + pIt->setText( 0, "client -> host" ); + gatsToTree( pIt, pObj ); + delete pObj; } void ProxyWidget::hostRecv( Gats::Object *pObj ) { - sio << "Recv: " << *pObj << sio.nl; - - QTreeWidgetItem *pIt = new QTreeWidgetItem( - twHistory->invisibleRootItem() - ); - pIt->setText( 0, "host -> client" ); - gatsToTree( pIt, pObj ); - delete pObj; + sio << "Recv: " << *pObj << sio.nl; + + QTreeWidgetItem *pIt = new QTreeWidgetItem( + twHistory->invisibleRootItem() + ); + pIt->setText( 0, "host -> client" ); + gatsToTree( pIt, pObj ); + delete pObj; } void ProxyWidget::gotConnection() { - lwConnect->stop(); - swRoot->setCurrentIndex( 1 ); + lwConnect->stop(); + swRoot->setCurrentIndex( 1 ); } diff --git a/c++-libbu++/src/gatscon/proxywidget.h b/c++-libbu++/src/gatscon/proxywidget.h index d6ebf4d..1674a34 100644 --- a/c++-libbu++/src/gatscon/proxywidget.h +++ b/c++-libbu++/src/gatscon/proxywidget.h @@ -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. + */ + #ifndef PROXY_WIDGET_H #define PROXY_WIDGET_H @@ -6,28 +13,28 @@ namespace Gats { - class Object; + class Object; }; class ProxyWidget : public QWidget, protected Ui::ProxyWidget, public IoBase { - Q_OBJECT; + Q_OBJECT; public: - ProxyWidget( QWidget *pParent, int iPortIn, const QByteArray baHost, - int iPortOut ); - virtual ~ProxyWidget(); + ProxyWidget( QWidget *pParent, int iPortIn, const QByteArray baHost, + int iPortOut ); + virtual ~ProxyWidget(); - virtual void saveTo( const QString &sFile ); + virtual void saveTo( const QString &sFile ); public slots: - void sendToClient(); - void sendToServer(); - void clientRecv( Gats::Object *pObj ); - void hostRecv( Gats::Object *pObj ); - void gotConnection(); + void sendToClient(); + void sendToServer(); + void clientRecv( Gats::Object *pObj ); + void hostRecv( Gats::Object *pObj ); + void gotConnection(); private: - class ProxyThread *pPrx; + class ProxyThread *pPrx; }; #endif diff --git a/c++-libbu++/src/gatscon/setupproxydlg.cpp b/c++-libbu++/src/gatscon/setupproxydlg.cpp index 7c7a873..6d80683 100644 --- a/c++-libbu++/src/gatscon/setupproxydlg.cpp +++ b/c++-libbu++/src/gatscon/setupproxydlg.cpp @@ -1,9 +1,16 @@ +/* + * 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 "setupproxydlg.h" SetupProxyDlg::SetupProxyDlg( QWidget *pParent ) : - QDialog( pParent ) + QDialog( pParent ) { - setupUi( this ); + setupUi( this ); } SetupProxyDlg::~SetupProxyDlg() @@ -12,16 +19,16 @@ SetupProxyDlg::~SetupProxyDlg() int SetupProxyDlg::getPortIn() const { - return sbPortIn->value(); + return sbPortIn->value(); } QByteArray SetupProxyDlg::getHostOut() const { - return leHostOut->text().toAscii(); + return leHostOut->text().toAscii(); } int SetupProxyDlg::getPortOut() const { - return sbPortOut->value(); + return sbPortOut->value(); } diff --git a/c++-libbu++/src/gatscon/setupproxydlg.h b/c++-libbu++/src/gatscon/setupproxydlg.h index 6cc31bd..685e893 100644 --- a/c++-libbu++/src/gatscon/setupproxydlg.h +++ b/c++-libbu++/src/gatscon/setupproxydlg.h @@ -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. + */ + #ifndef SETUP_PROXY_DLG_H #define SETUP_PROXY_DLG_H @@ -5,14 +12,14 @@ class SetupProxyDlg : public QDialog, protected Ui::SetupProxyDlg { - Q_OBJECT; + Q_OBJECT; public: - SetupProxyDlg( QWidget *pParent=NULL ); - virtual ~SetupProxyDlg(); + SetupProxyDlg( QWidget *pParent=NULL ); + virtual ~SetupProxyDlg(); - int getPortIn() const; - QByteArray getHostOut() const; - int getPortOut() const; + int getPortIn() const; + QByteArray getHostOut() const; + int getPortOut() const; }; #endif diff --git a/c++-libbu++/src/gatscon/treetogats.cpp b/c++-libbu++/src/gatscon/treetogats.cpp index a1571d1..f12a319 100644 --- a/c++-libbu++/src/gatscon/treetogats.cpp +++ b/c++-libbu++/src/gatscon/treetogats.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 "treetogats.h" #include @@ -6,47 +13,47 @@ Gats::Object *treeToGats( QTreeWidgetItem *pRoot ) { - QString sType = pRoot->text( 1 ); - QByteArray baDat = pRoot->text( 2 ).toAscii(); - if( sType == "int" ) - { - return new Gats::Integer( strtoll( baDat.constData(), NULL, 10 ) ); - } - else if( sType == "str" ) - { - return new Gats::String( baDat.constData(), baDat.size() ); - } - else if( sType == "float" ) - { - return new Gats::Float( strtod( baDat.constData(), NULL ) ); - } - else if( sType == "bool" ) - { - return new Gats::Boolean( baDat == "true" ); - } - else if( sType == "list" ) - { - Gats::List *pRet = new Gats::List(); - for( int j = 0; j < pRoot->childCount(); j++ ) - { - pRet->append( treeToGats( pRoot->child( j ) ) ); - } - return pRet; - } - else if( sType == "dict" ) - { - Gats::Dictionary *pRet = new Gats::Dictionary(); - for( int j = 0; j < pRoot->childCount(); j++ ) - { - QTreeWidgetItem *pChild = pRoot->child( j ); - pRet->insert( - pChild->text( 0 ).toAscii().constData(), - treeToGats( pChild ) - ); - } - return pRet; - } + QString sType = pRoot->text( 1 ); + QByteArray baDat = pRoot->text( 2 ).toAscii(); + if( sType == "int" ) + { + return new Gats::Integer( strtoll( baDat.constData(), NULL, 10 ) ); + } + else if( sType == "str" ) + { + return new Gats::String( baDat.constData(), baDat.size() ); + } + else if( sType == "float" ) + { + return new Gats::Float( strtod( baDat.constData(), NULL ) ); + } + else if( sType == "bool" ) + { + return new Gats::Boolean( baDat == "true" ); + } + else if( sType == "list" ) + { + Gats::List *pRet = new Gats::List(); + for( int j = 0; j < pRoot->childCount(); j++ ) + { + pRet->append( treeToGats( pRoot->child( j ) ) ); + } + return pRet; + } + else if( sType == "dict" ) + { + Gats::Dictionary *pRet = new Gats::Dictionary(); + for( int j = 0; j < pRoot->childCount(); j++ ) + { + QTreeWidgetItem *pChild = pRoot->child( j ); + pRet->insert( + pChild->text( 0 ).toAscii().constData(), + treeToGats( pChild ) + ); + } + return pRet; + } - throw Bu::ExceptionBase("Unhandled type found."); + throw Bu::ExceptionBase("Unhandled type found."); } diff --git a/c++-libbu++/src/gatscon/treetogats.h b/c++-libbu++/src/gatscon/treetogats.h index 931623d..29f7d6c 100644 --- a/c++-libbu++/src/gatscon/treetogats.h +++ b/c++-libbu++/src/gatscon/treetogats.h @@ -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. + */ + #ifndef TREE_TO_GATS_H #define TREE_TO_GATS_H @@ -5,7 +12,7 @@ class QTreeWidgetItem; namespace Gats { - class Object; + class Object; }; Gats::Object *treeToGats( QTreeWidgetItem *pRoot ); diff --git a/c++-libbu++/src/gatsstream.cpp b/c++-libbu++/src/gatsstream.cpp index d5e3f82..05fbd84 100644 --- a/c++-libbu++/src/gatsstream.cpp +++ b/c++-libbu++/src/gatsstream.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/gatsstream.h" #include "gats/object.h" @@ -6,7 +13,7 @@ // using namespace Bu; Gats::GatsStream::GatsStream( Bu::Stream &rStream ) : - rStream( rStream ) + rStream( rStream ) { } @@ -16,93 +23,93 @@ Gats::GatsStream::~GatsStream() Gats::Object *Gats::GatsStream::readObject() { - char buf[1500]; - - // sio << "Gats::GatsStream::readObject(): Scanning for object header." << sio.nl; - do - { - if( qbRead.getSize() < 5 ) - { - // sio << "Gats::GatsStream::readObject(): reading header data, need 5b, have " << qbRead.getSize() << "b." << sio.nl; - int iRead = rStream.read( buf, 5-qbRead.getSize() ); - qbRead.write( buf, iRead ); - - if( qbRead.getSize() < 5 ) - return NULL; - } - } while( !skipReadNulls() ); - - uint8_t uVer; - qbRead.peek( &uVer, 1 ); - // sio << "Gats::GatsStream::readObject(): Packet version: " << (int)uVer << sio.nl; - - int32_t iSize; - qbRead.peek( &iSize, 4, 1 ); - iSize = be32toh( iSize ); - // sio << "Gats::GatsStream::readObject(): Header read, looking for " << iSize << "b, we have " << qbRead.getSize() << "b." << sio.nl; - while( qbRead.getSize() < iSize ) - { - int32_t iRead = iSize - qbRead.getSize(); - if( iRead > 1500 ) - iRead = 1500; - // sio << "Gats::GatsStream::readObject(): Attempting to read " << iRead << "b." << sio.nl; - int32_t iReal = rStream.read( buf, iRead ); - // sio << "Gats::GatsStream::readObject(): Read " << iReal << "b." << sio.nl; - qbRead.write( buf, iReal ); - if( iReal < iRead ) - { - // sio << "Gats::GatsStream::readObject(): Insufficient data read in block, bailing on read." << sio.nl; - return NULL; - } - } - - if( qbRead.getSize() < iSize ) - { - // sio << "Gats::GatsStream::readObject(): Somehow, we still don't have enough data, bailing." << sio.nl; - return NULL; - } - - // sio << "Gats::GatsStream::readObject(): We have " << qbRead.getSize() << "b of " << iSize << "b, time to read the object." << sio.nl; - - qbRead.seek( 5 ); - Gats::Object *pObj = Gats::Object::read( qbRead ); - - // sio << "Gats::GatsStream::readObject(): Read completed, there are " << qbRead.getSize() << "b left in the buffer." << sio.nl; - return pObj; + char buf[1500]; + + // sio << "Gats::GatsStream::readObject(): Scanning for object header." << sio.nl; + do + { + if( qbRead.getSize() < 5 ) + { + // sio << "Gats::GatsStream::readObject(): reading header data, need 5b, have " << qbRead.getSize() << "b." << sio.nl; + int iRead = rStream.read( buf, 5-qbRead.getSize() ); + qbRead.write( buf, iRead ); + + if( qbRead.getSize() < 5 ) + return NULL; + } + } while( !skipReadNulls() ); + + uint8_t uVer; + qbRead.peek( &uVer, 1 ); + // sio << "Gats::GatsStream::readObject(): Packet version: " << (int)uVer << sio.nl; + + int32_t iSize; + qbRead.peek( &iSize, 4, 1 ); + iSize = be32toh( iSize ); + // sio << "Gats::GatsStream::readObject(): Header read, looking for " << iSize << "b, we have " << qbRead.getSize() << "b." << sio.nl; + while( qbRead.getSize() < iSize ) + { + int32_t iRead = iSize - qbRead.getSize(); + if( iRead > 1500 ) + iRead = 1500; + // sio << "Gats::GatsStream::readObject(): Attempting to read " << iRead << "b." << sio.nl; + int32_t iReal = rStream.read( buf, iRead ); + // sio << "Gats::GatsStream::readObject(): Read " << iReal << "b." << sio.nl; + qbRead.write( buf, iReal ); + if( iReal < iRead ) + { + // sio << "Gats::GatsStream::readObject(): Insufficient data read in block, bailing on read." << sio.nl; + return NULL; + } + } + + if( qbRead.getSize() < iSize ) + { + // sio << "Gats::GatsStream::readObject(): Somehow, we still don't have enough data, bailing." << sio.nl; + return NULL; + } + + // sio << "Gats::GatsStream::readObject(): We have " << qbRead.getSize() << "b of " << iSize << "b, time to read the object." << sio.nl; + + qbRead.seek( 5 ); + Gats::Object *pObj = Gats::Object::read( qbRead ); + + // sio << "Gats::GatsStream::readObject(): Read completed, there are " << qbRead.getSize() << "b left in the buffer." << sio.nl; + return pObj; } void Gats::GatsStream::writeObject( Gats::Object *pObject ) { - Bu::NullStream ns; - pObject->write( ns ); + Bu::NullStream ns; + pObject->write( ns ); - uint8_t uBuf = 1; - int32_t iSize = htobe32( ns.tell()+5 ); - rStream.write( &uBuf, 1 ); - rStream.write( &iSize, 4 ); - pObject->write( rStream ); + uint8_t uBuf = 1; + int32_t iSize = htobe32( ns.tell()+5 ); + rStream.write( &uBuf, 1 ); + rStream.write( &iSize, 4 ); + pObject->write( rStream ); - // sio << "Object consumed " << ns.tell() << "b." << sio.nl; + // sio << "Object consumed " << ns.tell() << "b." << sio.nl; } bool Gats::GatsStream::skipReadNulls() { - char buf; - - // sio << "Gats::GatsStream::skipReadNulls(): Scanning for nulls, " << qbRead.getSize() << "b." << sio.nl; - bool bHaveSeeked = false; - for(;;) - { - if( qbRead.peek( &buf, 1 ) == 0 ) - return false; - if( buf != 0 ) - return !bHaveSeeked; //true; - else - { - // sio << "Gats::GatsStream::skipReadNulls(): Null byte read, not header yet..." << sio.nl; - qbRead.seek( 1 ); - bHaveSeeked = true; - } - } + char buf; + + // sio << "Gats::GatsStream::skipReadNulls(): Scanning for nulls, " << qbRead.getSize() << "b." << sio.nl; + bool bHaveSeeked = false; + for(;;) + { + if( qbRead.peek( &buf, 1 ) == 0 ) + return false; + if( buf != 0 ) + return !bHaveSeeked; //true; + else + { + // sio << "Gats::GatsStream::skipReadNulls(): Null byte read, not header yet..." << sio.nl; + qbRead.seek( 1 ); + bHaveSeeked = true; + } + } } diff --git a/c++-libbu++/src/gatsstream.h b/c++-libbu++/src/gatsstream.h index 39719cf..e318b3c 100644 --- a/c++-libbu++/src/gatsstream.h +++ b/c++-libbu++/src/gatsstream.h @@ -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. + */ + #ifndef GATS_STREAM_H #define GATS_STREAM_H @@ -6,51 +13,51 @@ namespace Gats { - class Object; - - class GatsStream - { - public: - GatsStream( Bu::Stream &rStream ); - virtual ~GatsStream(); - - /** - * Read an object packet from the assosiated stream. This will make - * every effort to only read exactly enough data to describe one packet, - * in case you want to do other things with your stream. It will - * automatically skip NULL byte spacing between packets, which makes - * a convinient padding method for encrypted data streams. Since - * sizing information is available in the packet header exact amounts - * of data can be read, however this function doesn't assume that it - * can read the entire object in one operation. If it fails to read - * a complete packet in one call, it will keep the data it's read so - * far buffered and return NULL, ready for another attempt. You can - * use the function hasReadBuffer() to deterimne if readObject() - * has read part of an object packet or not. If readObject returns - * non-null then hasReadBuffer should return false on it's next call. - */ - Gats::Object *readObject(); - - /** - * Write an object - */ - void writeObject( Gats::Object *pObject ); - - /** - * Tells you if there is data still in the read buffer, i.e. that a - * packet is part way through being read. If readObject has returned - * non-null in the most recent call, this should always be false. - */ - bool hasReadBuffer() { return qbRead.getSize() > 0; } - int getReadBufferSize() { return qbRead.getSize(); } - - private: - bool skipReadNulls(); - - private: - Bu::Stream &rStream; - Bu::QueueBuf qbRead; - }; + class Object; + + class GatsStream + { + public: + GatsStream( Bu::Stream &rStream ); + virtual ~GatsStream(); + + /** + * Read an object packet from the assosiated stream. This will make + * every effort to only read exactly enough data to describe one packet, + * in case you want to do other things with your stream. It will + * automatically skip NULL byte spacing between packets, which makes + * a convinient padding method for encrypted data streams. Since + * sizing information is available in the packet header exact amounts + * of data can be read, however this function doesn't assume that it + * can read the entire object in one operation. If it fails to read + * a complete packet in one call, it will keep the data it's read so + * far buffered and return NULL, ready for another attempt. You can + * use the function hasReadBuffer() to deterimne if readObject() + * has read part of an object packet or not. If readObject returns + * non-null then hasReadBuffer should return false on it's next call. + */ + Gats::Object *readObject(); + + /** + * Write an object + */ + void writeObject( Gats::Object *pObject ); + + /** + * Tells you if there is data still in the read buffer, i.e. that a + * packet is part way through being read. If readObject has returned + * non-null in the most recent call, this should always be false. + */ + bool hasReadBuffer() { return qbRead.getSize() > 0; } + int getReadBufferSize() { return qbRead.getSize(); } + + private: + bool skipReadNulls(); + + private: + Bu::Stream &rStream; + Bu::QueueBuf qbRead; + }; }; #endif diff --git a/c++-libbu++/src/integer.cpp b/c++-libbu++/src/integer.cpp index e89ac1d..40fc609 100644 --- a/c++-libbu++/src/integer.cpp +++ b/c++-libbu++/src/integer.cpp @@ -1,14 +1,21 @@ +/* + * 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/integer.h" #include Gats::Integer::Integer() : - iVal( 0 ) + iVal( 0 ) { } Gats::Integer::Integer( int64_t iVal ) : - iVal( iVal ) + iVal( iVal ) { } @@ -18,22 +25,22 @@ Gats::Integer::~Integer() Gats::Object *Gats::Integer::clone() const { - return new Gats::Integer( iVal ); + return new Gats::Integer( iVal ); } void Gats::Integer::write( Bu::Stream &rOut ) const { - rOut.write("i", 1 ); - writePackedInt( rOut, iVal ); + rOut.write("i", 1 ); + writePackedInt( rOut, iVal ); } void Gats::Integer::read( Bu::Stream &rIn, char cType ) { - readPackedInt( rIn, iVal ); + readPackedInt( rIn, iVal ); } Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ) { - return f << "(int) " << i.getValue(); + return f << "(int) " << i.getValue(); } diff --git a/c++-libbu++/src/integer.h b/c++-libbu++/src/integer.h index a5e0d58..dc4ae4c 100644 --- a/c++-libbu++/src/integer.h +++ b/c++-libbu++/src/integer.h @@ -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. + */ + #ifndef GATS_INTEGER_H #define GATS_INTEGER_H @@ -9,76 +16,76 @@ namespace Gats { - class Integer : public Gats::Object - { - public: - Integer(); - Integer( int64_t iVal ); - virtual ~Integer(); - - virtual Object *clone() const; - - virtual Type getType() const { return typeInteger; } - int64_t getValue() const { return iVal; } - - virtual void write( Bu::Stream &rOut ) const; - virtual void read( Bu::Stream &rIn, char cType ); - - template - static void readPackedInt( Bu::Stream &rStream, itype &rOut ) - { - int8_t b; - rOut = 0; - bool bNeg; - - rStream.read( &b, 1 ); - bNeg = ( b&0x40 ); - rOut |= (itype(b&0x3F)); - int c = 0; - while( (b&0x80) ) - { - rStream.read( &b, 1 ); - rOut |= (itype(b&0x7F)) << (6+7*(c++)); - } - if( bNeg ) rOut = -rOut; - } - - template - static void writePackedInt( Bu::Stream &rStream, itype iIn ) - { - uint8_t b; - - if( iIn < 0 ) - { - iIn = -iIn; - b = (iIn&0x3F); - if( iIn > b ) - b |= 0x80 | 0x40; - else - b |= 0x40; - } - else - { - b = (iIn&0x3F); - if( iIn > b ) - b |= 0x80; - } - rStream.write( &b, 1 ); - iIn = iIn >> 6; - - while( iIn ) - { - b = (iIn&0x7F); - if( iIn > b ) - b |= 0x80; - rStream.write( &b, 1 ); - iIn = iIn >> 7; - } - } - - private: - int64_t iVal; - }; + class Integer : public Gats::Object + { + public: + Integer(); + Integer( int64_t iVal ); + virtual ~Integer(); + + virtual Object *clone() const; + + virtual Type getType() const { return typeInteger; } + int64_t getValue() const { return iVal; } + + virtual void write( Bu::Stream &rOut ) const; + virtual void read( Bu::Stream &rIn, char cType ); + + template + static void readPackedInt( Bu::Stream &rStream, itype &rOut ) + { + int8_t b; + rOut = 0; + bool bNeg; + + rStream.read( &b, 1 ); + bNeg = ( b&0x40 ); + rOut |= (itype(b&0x3F)); + int c = 0; + while( (b&0x80) ) + { + rStream.read( &b, 1 ); + rOut |= (itype(b&0x7F)) << (6+7*(c++)); + } + if( bNeg ) rOut = -rOut; + } + + template + static void writePackedInt( Bu::Stream &rStream, itype iIn ) + { + uint8_t b; + + if( iIn < 0 ) + { + iIn = -iIn; + b = (iIn&0x3F); + if( iIn > b ) + b |= 0x80 | 0x40; + else + b |= 0x40; + } + else + { + b = (iIn&0x3F); + if( iIn > b ) + b |= 0x80; + } + rStream.write( &b, 1 ); + iIn = iIn >> 6; + + while( iIn ) + { + b = (iIn&0x7F); + if( iIn > b ) + b |= 0x80; + rStream.write( &b, 1 ); + iIn = iIn >> 7; + } + } + + private: + int64_t iVal; + }; }; Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); diff --git a/c++-libbu++/src/list.cpp b/c++-libbu++/src/list.cpp index d081a22..c5217cd 100644 --- a/c++-libbu++/src/list.cpp +++ b/c++-libbu++/src/list.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/list.h" #include "gats/string.h" @@ -15,191 +22,191 @@ Gats::List::List() Gats::List::~List() { - for( iterator i = begin(); i; i++ ) - { - delete *i; - } + 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; + 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 ); + 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 ); - } + 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 ) ); + Bu::List::append( new Gats::String( s ) ); } void Gats::List::append( const Bu::String &s ) { - Bu::List::append( new Gats::String( s ) ); + Bu::List::append( new Gats::String( s ) ); } void Gats::List::append( int32_t i ) { - Bu::List::append( new Gats::Integer( i ) ); + Bu::List::append( new Gats::Integer( i ) ); } void Gats::List::append( int64_t i ) { - Bu::List::append( new Gats::Integer( i ) ); + Bu::List::append( new Gats::Integer( i ) ); } void Gats::List::append( double d ) { - Bu::List::append( new Gats::Float( d ) ); + Bu::List::append( new Gats::Float( d ) ); } void Gats::List::appendStr( const Bu::String &s ) { - Bu::List::append( new Gats::String( s ) ); + Bu::List::append( new Gats::String( s ) ); } void Gats::List::appendInt( int64_t i ) { - Bu::List::append( new Gats::Integer( i ) ); + Bu::List::append( new Gats::Integer( i ) ); } void Gats::List::appendFloat( double d ) { - Bu::List::append( new Gats::Float( d ) ); + Bu::List::append( new Gats::Float( d ) ); } void Gats::List::appendBool( bool b ) { - Bu::List::append( new Gats::Boolean( b ) ); + Bu::List::append( new Gats::Boolean( b ) ); } void Gats::List::appendList( Gats::List *pL ) { - Bu::List::append( pL ); + Bu::List::append( pL ); } void Gats::List::appendDict( Gats::Dictionary *pD ) { - Bu::List::append( pD ); + Bu::List::append( pD ); } Gats::List *Gats::List::appendList() { - Gats::List *pLst = new Gats::List(); - appendList( pLst ); - return pLst; + 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; + Gats::Dictionary *pDict = new Gats::Dictionary(); + appendDict( pDict ); + return pDict; } void Gats::List::prepend( const char *s ) { - Bu::List::prepend( new Gats::String( s ) ); + Bu::List::prepend( new Gats::String( s ) ); } void Gats::List::prepend( const Bu::String &s ) { - Bu::List::prepend( new Gats::String( s ) ); + Bu::List::prepend( new Gats::String( s ) ); } void Gats::List::prepend( int32_t i ) { - Bu::List::prepend( new Gats::Integer( i ) ); + Bu::List::prepend( new Gats::Integer( i ) ); } void Gats::List::prepend( int64_t i ) { - Bu::List::prepend( new Gats::Integer( i ) ); + Bu::List::prepend( new Gats::Integer( i ) ); } void Gats::List::prepend( double d ) { - Bu::List::prepend( new Gats::Float( d ) ); + Bu::List::prepend( new Gats::Float( d ) ); } void Gats::List::prependStr( const Bu::String &s ) { - Bu::List::prepend( new Gats::String( s ) ); + Bu::List::prepend( new Gats::String( s ) ); } void Gats::List::prependInt( int64_t i ) { - Bu::List::prepend( new Gats::Integer( i ) ); + Bu::List::prepend( new Gats::Integer( i ) ); } void Gats::List::prependFloat( double d ) { - Bu::List::prepend( new Gats::Float( d ) ); + Bu::List::prepend( new Gats::Float( d ) ); } void Gats::List::prependBool( bool b ) { - Bu::List::prepend( new Gats::Boolean( b ) ); + Bu::List::prepend( new Gats::Boolean( b ) ); } void Gats::List::prependList( Gats::List *pL ) { - Bu::List::prepend( pL ); + Bu::List::prepend( pL ); } void Gats::List::prependDict( Gats::Dictionary *pD ) { - Bu::List::prepend( pD ); + Bu::List::prepend( pD ); } Gats::List *Gats::List::prependList() { - Gats::List *pLst = new Gats::List(); - prependList( pLst ); - return pLst; + 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; + 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; + 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; } diff --git a/c++-libbu++/src/list.h b/c++-libbu++/src/list.h index 5c1cd6e..6f4c9a4 100644 --- a/c++-libbu++/src/list.h +++ b/c++-libbu++/src/list.h @@ -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. + */ + #ifndef GATS_LIST_H #define GATS_LIST_H @@ -7,50 +14,50 @@ namespace Gats { - class Dictionary; - - class List : public Gats::Object, public Bu::List - { - public: - List(); - virtual ~List(); - - virtual Object *clone() const; - virtual Type getType() const { return typeList; } - - virtual void write( Bu::Stream &rOut ) const; - virtual void read( Bu::Stream &rIn, char cType ); - - void append( const char *s ); - void append( const Bu::String &s ); - void append( int32_t i ); - void append( int64_t i ); - void append( double d ); - using Bu::List::append; - void appendStr( const Bu::String &s ); - void appendInt( int64_t i ); - void appendFloat( double d ); - void appendBool( bool b ); - void appendList( Gats::List *pL ); - void appendDict( Gats::Dictionary *pD ); - Gats::List *appendList(); - Gats::Dictionary *appendDict(); - - void prepend( const char *s ); - void prepend( const Bu::String &s ); - void prepend( int32_t i ); - void prepend( int64_t i ); - void prepend( double d ); - using Bu::List::prepend; - void prependStr( const Bu::String &s ); - void prependInt( int64_t i ); - void prependFloat( double d ); - void prependBool( bool b ); - void prependList( Gats::List *pL ); - void prependDict( Gats::Dictionary *pD ); - Gats::List *prependList(); - Gats::Dictionary *prependDict(); - }; + class Dictionary; + + class List : public Gats::Object, public Bu::List + { + public: + List(); + virtual ~List(); + + virtual Object *clone() const; + virtual Type getType() const { return typeList; } + + virtual void write( Bu::Stream &rOut ) const; + virtual void read( Bu::Stream &rIn, char cType ); + + void append( const char *s ); + void append( const Bu::String &s ); + void append( int32_t i ); + void append( int64_t i ); + void append( double d ); + using Bu::List::append; + void appendStr( const Bu::String &s ); + void appendInt( int64_t i ); + void appendFloat( double d ); + void appendBool( bool b ); + void appendList( Gats::List *pL ); + void appendDict( Gats::Dictionary *pD ); + Gats::List *appendList(); + Gats::Dictionary *appendDict(); + + void prepend( const char *s ); + void prepend( const Bu::String &s ); + void prepend( int32_t i ); + void prepend( int64_t i ); + void prepend( double d ); + using Bu::List::prepend; + void prependStr( const Bu::String &s ); + void prependInt( int64_t i ); + void prependFloat( double d ); + void prependBool( bool b ); + void prependList( Gats::List *pL ); + void prependDict( Gats::Dictionary *pD ); + Gats::List *prependList(); + Gats::Dictionary *prependDict(); + }; }; Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ); diff --git a/c++-libbu++/src/null.cpp b/c++-libbu++/src/null.cpp index 13a61ed..37c9e6a 100644 --- a/c++-libbu++/src/null.cpp +++ b/c++-libbu++/src/null.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/null.h" #include @@ -13,21 +20,21 @@ Gats::Null::~Null() Gats::Object *Gats::Null::clone() const { - return new Gats::Null(); + return new Gats::Null(); } void Gats::Null::write( Bu::Stream &rOut ) const { - rOut.write("n", 1 ); + rOut.write("n", 1 ); } void Gats::Null::read( Bu::Stream &rIn, char cType ) { - // Nothing to do... + // Nothing to do... } Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ) { - return f << "(null)"; + return f << "(null)"; } diff --git a/c++-libbu++/src/null.h b/c++-libbu++/src/null.h index afa2d0a..fc7825b 100644 --- a/c++-libbu++/src/null.h +++ b/c++-libbu++/src/null.h @@ -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. + */ + #ifndef GATS_NULL_H #define GATS_NULL_H @@ -5,18 +12,18 @@ namespace Gats { - class Null : public Gats::Object - { - public: - Null(); - virtual ~Null(); + class Null : public Gats::Object + { + public: + Null(); + virtual ~Null(); - virtual Type getType() const { return typeNull; } - virtual Object *clone() const; + virtual Type getType() const { return typeNull; } + virtual Object *clone() const; - virtual void write( Bu::Stream &rOut ) const; - virtual void read( Bu::Stream &rIn, char cType ); - }; + virtual void write( Bu::Stream &rOut ) const; + virtual void read( Bu::Stream &rIn, char cType ); + }; }; Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ); diff --git a/c++-libbu++/src/object.cpp b/c++-libbu++/src/object.cpp index 15d7cb5..db7b80b 100644 --- a/c++-libbu++/src/object.cpp +++ b/c++-libbu++/src/object.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/object.h" #include "gats/integer.h" @@ -26,137 +33,137 @@ Gats::Object::~Object() Gats::Object *Gats::Object::read( Bu::Stream &rIn ) { - char buf; - rIn.read( &buf, 1 ); - Object *pObj = NULL; - switch( buf ) - { - case 'i': - pObj = new Gats::Integer(); - break; - - case 's': - pObj = new Gats::String(); - break; - - case '0': - case '1': - pObj = new Gats::Boolean(); - break; - - case 'l': - pObj = new Gats::List(); - break; - - case 'd': - pObj = new Gats::Dictionary(); - break; - - case 'f': // Normal floats - case 'F': // Special float values - pObj = new Gats::Float(); - break; - - case 'n': - pObj = new Gats::Null(); - break; - - case 'e': - return NULL; - - default: - throw Bu::ExceptionBase("Invalid Gats type discovered: %c.", buf ); - } - - pObj->read( rIn, buf ); - - return pObj; + char buf; + rIn.read( &buf, 1 ); + Object *pObj = NULL; + switch( buf ) + { + case 'i': + pObj = new Gats::Integer(); + break; + + case 's': + pObj = new Gats::String(); + break; + + case '0': + case '1': + pObj = new Gats::Boolean(); + break; + + case 'l': + pObj = new Gats::List(); + break; + + case 'd': + pObj = new Gats::Dictionary(); + break; + + case 'f': // Normal floats + case 'F': // Special float values + pObj = new Gats::Float(); + break; + + case 'n': + pObj = new Gats::Null(); + break; + + case 'e': + return NULL; + + default: + throw Bu::ExceptionBase("Invalid Gats type discovered: %c.", buf ); + } + + pObj->read( rIn, buf ); + + return pObj; } void Gats::Object::skipWs( Bu::String::const_iterator &i ) { - for(; *i == ' ' || *i == '\t' || *i == '\r' || *i == '\n'; i++ ) { } + for(; *i == ' ' || *i == '\t' || *i == '\r' || *i == '\n'; i++ ) { } } Bu::String Gats::Object::token( Bu::String::const_iterator &i ) { - Bu::String sRet; - if( *i == '\"' ) + Bu::String sRet; + if( *i == '\"' ) { for( i++; i && *i != '\"' ; i++ ) - { - if( *i == '\\' ) - i++; - sRet += i; - } - i++; - } - else - { - for(; i && *i != ' ' && *i != '\t' && *i != '\r' && *i != '\n' && - *i != ',' && *i != ']' && *i != '}' && *i != '[' && - *i != '{'; i++ ) - { - sRet += i; - } - } - - return sRet; + { + if( *i == '\\' ) + i++; + sRet += i; + } + i++; + } + else + { + for(; i && *i != ' ' && *i != '\t' && *i != '\r' && *i != '\n' && + *i != ',' && *i != ']' && *i != '}' && *i != '[' && + *i != '{'; i++ ) + { + sRet += i; + } + } + + return sRet; } Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i ) { - skipWs( i ); - - switch( *i ) - { - case '[': - { - Gats::List *pLst = new Gats::List(); - i++; - for(;;) - { - skipWs( i ); - if( *i == ']' ) - { - i++; - return pLst; - } - Gats::Object *pObj = strToGats( i ); - if( !pObj ) - break; - pLst->append( pObj ); - skipWs( i ); - switch( *i ) - { - case ',': - i++; - break; - - case ']': - i++; - return pLst; - - default: - throw Bu::ExceptionBase("Invalid character found."); - } - } - } - break; - - case '{': - { - Gats::Dictionary *pDict = new Gats::Dictionary(); - i++; - for(;;) - { - skipWs( i ); - if( *i == '}' ) - { - i++; - return pDict; - } - if( *i != '\"' ) + skipWs( i ); + + switch( *i ) + { + case '[': + { + Gats::List *pLst = new Gats::List(); + i++; + for(;;) + { + skipWs( i ); + if( *i == ']' ) + { + i++; + return pLst; + } + Gats::Object *pObj = strToGats( i ); + if( !pObj ) + break; + pLst->append( pObj ); + skipWs( i ); + switch( *i ) + { + case ',': + i++; + break; + + case ']': + i++; + return pLst; + + default: + throw Bu::ExceptionBase("Invalid character found."); + } + } + } + break; + + case '{': + { + Gats::Dictionary *pDict = new Gats::Dictionary(); + i++; + for(;;) + { + skipWs( i ); + if( *i == '}' ) + { + i++; + return pDict; + } + if( *i != '\"' ) throw Bu::ExceptionBase("Keys must be quoted strings."); Bu::String sKey = token( i ); skipWs( i ); @@ -187,153 +194,153 @@ Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i ) break; case '\"': - return new Gats::String( token( i ) ); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '.': - case '+': - case '-': - { - Bu::String s = token( i ); - int iSize = s.getSize(); - if( s[iSize-1] == 'i' ) - { - return new Gats::Integer( - strtoll( s.getStr(), NULL, 10 ) - ); - } - else if( s[iSize-1] == 'f' ) - { - return new Gats::Float( - strtod( s.getStr(), NULL ) - ); - } - else - { - for( Bu::String::iterator i = s.begin(); i; i++ ) - { - if( *i == '.' ) - return new Gats::Float( - strtod( s.getStr(), NULL ) - ); - } - return new Gats::Integer( - strtoll( s.getStr(), NULL, 10 ) - ); - } - } - break; - - default: - { - Bu::String s = token( i ); - int iSize = s.getSize(); - // Test for explicit types first - if( iSize > 2 ) - { - if( (s[0] >= '0' && s[0] <= '9') || s[0] == '+' || s[0] == '-' ) - { - } - else - { - Bu::String st = s.toLower(); - if( st == "true" ) - { - return new Gats::Boolean( true ); - } - else if( st == "false" ) - { - return new Gats::Boolean( false ); - } - else if( st == "null" ) - { - return new Gats::Null(); - } - } - } - } - break; - } - - return NULL; + return new Gats::String( token( i ) ); + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '.': + case '+': + case '-': + { + Bu::String s = token( i ); + int iSize = s.getSize(); + if( s[iSize-1] == 'i' ) + { + return new Gats::Integer( + strtoll( s.getStr(), NULL, 10 ) + ); + } + else if( s[iSize-1] == 'f' ) + { + return new Gats::Float( + strtod( s.getStr(), NULL ) + ); + } + else + { + for( Bu::String::iterator i = s.begin(); i; i++ ) + { + if( *i == '.' ) + return new Gats::Float( + strtod( s.getStr(), NULL ) + ); + } + return new Gats::Integer( + strtoll( s.getStr(), NULL, 10 ) + ); + } + } + break; + + default: + { + Bu::String s = token( i ); + int iSize = s.getSize(); + // Test for explicit types first + if( iSize > 2 ) + { + if( (s[0] >= '0' && s[0] <= '9') || s[0] == '+' || s[0] == '-' ) + { + } + else + { + Bu::String st = s.toLower(); + if( st == "true" ) + { + return new Gats::Boolean( true ); + } + else if( st == "false" ) + { + return new Gats::Boolean( false ); + } + else if( st == "null" ) + { + return new Gats::Null(); + } + } + } + } + break; + } + + return NULL; } Gats::Object *Gats::Object::strToGats( const Bu::String &sStr ) { - Bu::String::const_iterator i = sStr.begin(); + Bu::String::const_iterator i = sStr.begin(); - return strToGats( i ); + return strToGats( i ); } Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ) { - switch( obj.getType() ) - { - case Gats::typeDictionary: - return f << dynamic_cast(obj); - - case Gats::typeList: - return f << dynamic_cast(obj); - - case Gats::typeString: - return f << dynamic_cast(obj); - - case Gats::typeInteger: - return f << dynamic_cast(obj); - - case Gats::typeFloat: - return f << dynamic_cast(obj); - - case Gats::typeBoolean: - return f << dynamic_cast(obj); - - case Gats::typeNull: - return f << dynamic_cast(obj); - - default: - return f << "***ERROR: Bad Gats type***"; - } + switch( obj.getType() ) + { + case Gats::typeDictionary: + return f << dynamic_cast(obj); + + case Gats::typeList: + return f << dynamic_cast(obj); + + case Gats::typeString: + return f << dynamic_cast(obj); + + case Gats::typeInteger: + return f << dynamic_cast(obj); + + case Gats::typeFloat: + return f << dynamic_cast(obj); + + case Gats::typeBoolean: + return f << dynamic_cast(obj); + + case Gats::typeNull: + return f << dynamic_cast(obj); + + default: + return f << "***ERROR: Bad Gats type***"; + } } Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ) { - switch( t ) - { - case Gats::typeDictionary: return f << "dictionary"; - case Gats::typeList: return f << "list"; - case Gats::typeString: return f << "string"; - case Gats::typeInteger: return f << "integer"; - case Gats::typeFloat: return f << "float"; - case Gats::typeBoolean: return f << "boolean"; - case Gats::typeNull: return f << "null"; - } - - return f << "***unknown***"; + switch( t ) + { + case Gats::typeDictionary: return f << "dictionary"; + case Gats::typeList: return f << "list"; + case Gats::typeString: return f << "string"; + case Gats::typeInteger: return f << "integer"; + case Gats::typeFloat: return f << "float"; + case Gats::typeBoolean: return f << "boolean"; + case Gats::typeNull: return f << "null"; + } + + return f << "***unknown***"; } const char *Gats::typeToStr( Gats::Type t ) { - switch( t ) - { - case Gats::typeDictionary: return "dictionary"; - case Gats::typeList: return "list"; - case Gats::typeString: return "string"; - case Gats::typeInteger: return "integer"; - case Gats::typeFloat: return "float"; - case Gats::typeBoolean: return "boolean"; - case Gats::typeNull: return "null"; - } - - return "***unknown***"; + switch( t ) + { + case Gats::typeDictionary: return "dictionary"; + case Gats::typeList: return "list"; + case Gats::typeString: return "string"; + case Gats::typeInteger: return "integer"; + case Gats::typeFloat: return "float"; + case Gats::typeBoolean: return "boolean"; + case Gats::typeNull: return "null"; + } + + return "***unknown***"; } diff --git a/c++-libbu++/src/object.h b/c++-libbu++/src/object.h index 2724189..e4da8de 100644 --- a/c++-libbu++/src/object.h +++ b/c++-libbu++/src/object.h @@ -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. + */ + #ifndef GATS_OBJECT_H #define GATS_OBJECT_H @@ -5,48 +12,48 @@ namespace Bu { - class Stream; - class Formatter; + class Stream; + class Formatter; }; namespace Gats { - enum Type - { - typeDictionary, - typeList, - typeString, - typeInteger, - typeFloat, - typeBoolean, - typeNull - }; - - /** - * The baseclass for every type that can be stored in a packet. - */ - class Object - { - public: - Object(); - virtual ~Object(); - - virtual Type getType() const =0; - - virtual void write( Bu::Stream &rOut ) const=0; - virtual void read( Bu::Stream &rIn, char cType )=0; - virtual Object *clone() const=0; - - static Object *read( Bu::Stream &rIn ); - static Object *strToGats( const Bu::String &sStr ); - - private: - static Object *strToGats( Bu::String::const_iterator &i ); - static Bu::String token( Bu::String::const_iterator &i ); - static void skipWs( Bu::String::const_iterator &i ); - }; - - const char *typeToStr( Type t ); + enum Type + { + typeDictionary, + typeList, + typeString, + typeInteger, + typeFloat, + typeBoolean, + typeNull + }; + + /** + * The baseclass for every type that can be stored in a packet. + */ + class Object + { + public: + Object(); + virtual ~Object(); + + virtual Type getType() const =0; + + virtual void write( Bu::Stream &rOut ) const=0; + virtual void read( Bu::Stream &rIn, char cType )=0; + virtual Object *clone() const=0; + + static Object *read( Bu::Stream &rIn ); + static Object *strToGats( const Bu::String &sStr ); + + private: + static Object *strToGats( Bu::String::const_iterator &i ); + static Bu::String token( Bu::String::const_iterator &i ); + static void skipWs( Bu::String::const_iterator &i ); + }; + + const char *typeToStr( Type t ); }; Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ); diff --git a/c++-libbu++/src/protocolgats.cpp b/c++-libbu++/src/protocolgats.cpp index 827eb65..f9d9e04 100644 --- a/c++-libbu++/src/protocolgats.cpp +++ b/c++-libbu++/src/protocolgats.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/protocolgats.h" #include "gats/gatsstream.h" @@ -7,50 +14,50 @@ using namespace Bu; Gats::ProtocolGats::ProtocolGats() : - pStream( NULL ), - pUsedClient( NULL ) + pStream( NULL ), + pUsedClient( NULL ) { } Gats::ProtocolGats::~ProtocolGats() { - delete pStream; - pStream = NULL; + delete pStream; + pStream = NULL; } void Gats::ProtocolGats::onNewConnection( Bu::Client *pClient ) { - if( pStream == NULL ) - { - pStream = new Gats::GatsStream( *pClient ); - pUsedClient = pClient; - } + if( pStream == NULL ) + { + pStream = new Gats::GatsStream( *pClient ); + pUsedClient = pClient; + } } void Gats::ProtocolGats::onNewData( Bu::Client *pClient ) { - if( pStream == NULL ) - { - pStream = new Gats::GatsStream( *pClient ); - pUsedClient = pClient; - } - else if( pClient != pUsedClient ) - { - throw Bu::ExceptionBase("ProtocolGats requires that you maintain a " - "1:1 relationship between client and protocol objects."); - } - - for(;;) - { - Gats::Object *pObj = pStream->readObject(); - if( pObj == NULL ) - break; - onNewObject( pClient, pObj ); - } + if( pStream == NULL ) + { + pStream = new Gats::GatsStream( *pClient ); + pUsedClient = pClient; + } + else if( pClient != pUsedClient ) + { + throw Bu::ExceptionBase("ProtocolGats requires that you maintain a " + "1:1 relationship between client and protocol objects."); + } + + for(;;) + { + Gats::Object *pObj = pStream->readObject(); + if( pObj == NULL ) + break; + onNewObject( pClient, pObj ); + } } void Gats::ProtocolGats::writeObject( Gats::Object *pObj ) { - pStream->writeObject( pObj ); + pStream->writeObject( pObj ); } diff --git a/c++-libbu++/src/protocolgats.h b/c++-libbu++/src/protocolgats.h index 7ed58d4..86dda00 100644 --- a/c++-libbu++/src/protocolgats.h +++ b/c++-libbu++/src/protocolgats.h @@ -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. + */ + #ifndef GATS_PROTOCOL_GATS_H #define GATS_PROTOCOL_GATS_H @@ -5,26 +12,26 @@ namespace Gats { - class Object; - class GatsStream; + class Object; + class GatsStream; - class ProtocolGats : public Bu::Protocol - { - public: - ProtocolGats(); - virtual ~ProtocolGats(); + class ProtocolGats : public Bu::Protocol + { + public: + ProtocolGats(); + virtual ~ProtocolGats(); - virtual void onNewConnection( Bu::Client *pClient ); - virtual void onNewData( Bu::Client *pClient ); + virtual void onNewConnection( Bu::Client *pClient ); + virtual void onNewData( Bu::Client *pClient ); - virtual void onNewObject( Bu::Client *pClient, Gats::Object *pObj )=0; + virtual void onNewObject( Bu::Client *pClient, Gats::Object *pObj )=0; - void writeObject( Gats::Object *pObj ); + void writeObject( Gats::Object *pObj ); - private: - Gats::GatsStream *pStream; - Bu::Client *pUsedClient; - }; + private: + Gats::GatsStream *pStream; + Bu::Client *pUsedClient; + }; }; #endif diff --git a/c++-libbu++/src/string.cpp b/c++-libbu++/src/string.cpp index de66d5d..f8e4071 100644 --- a/c++-libbu++/src/string.cpp +++ b/c++-libbu++/src/string.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/string.h" #include "gats/integer.h" @@ -9,27 +16,27 @@ Gats::String::String() } Gats::String::String( const char *s ) : - Bu::String( s ) + Bu::String( s ) { } Gats::String::String( const char *s, long iLength ) : - Bu::String( s, iLength ) + Bu::String( s, iLength ) { } Gats::String::String( long iLength ) : - Bu::String( iLength ) + Bu::String( iLength ) { } Gats::String::String( const String &s ) : - Bu::String( s ) + Bu::String( s ) { } Gats::String::String( const Bu::String &s ) : - Bu::String( s ) + Bu::String( s ) { } @@ -39,32 +46,32 @@ Gats::String::~String() Gats::Object *Gats::String::clone() const { - return new Gats::String( Bu::String::clone() ); + return new Gats::String( Bu::String::clone() ); } void Gats::String::write( Bu::Stream &rOut ) const { - rOut.write("s", 1 ); - uint32_t iSize = getSize(); - Gats::Integer::writePackedInt( rOut, iSize ); - rOut.write( getStr(), iSize ); + rOut.write("s", 1 ); + uint32_t iSize = getSize(); + Gats::Integer::writePackedInt( rOut, iSize ); + rOut.write( getStr(), iSize ); } void Gats::String::read( Bu::Stream &rIn, char cType ) { - uint32_t iSize; - Gats::Integer::readPackedInt( rIn, iSize ); - setSize( iSize ); - rIn.read( getStr(), iSize ); + uint32_t iSize; + Gats::Integer::readPackedInt( rIn, iSize ); + setSize( iSize ); + rIn.read( getStr(), iSize ); } Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ) { - for( Gats::String::const_iterator i = s.begin(); i; i++ ) - { - if( *i >= 127 || *i <= 31 ) - return f << "(binary str) " << s.getSize() << " bytes"; - } - return f << "(str) \"" << dynamic_cast(s) << "\""; + for( Gats::String::const_iterator i = s.begin(); i; i++ ) + { + if( *i >= 127 || *i <= 31 ) + return f << "(binary str) " << s.getSize() << " bytes"; + } + return f << "(str) \"" << dynamic_cast(s) << "\""; } diff --git a/c++-libbu++/src/string.h b/c++-libbu++/src/string.h index de8eedd..0d17a3e 100644 --- a/c++-libbu++/src/string.h +++ b/c++-libbu++/src/string.h @@ -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. + */ + #ifndef GATS_STRING_H #define GATS_STRING_H @@ -6,25 +13,25 @@ namespace Gats { - class String : public Gats::Object, public Bu::String - { - public: - String(); - String( const char *s ); - String( const char *s, long iLength ); - String( long iLength ); - String( const String &s ); - String( const Bu::String &s ); - virtual ~String(); - - virtual Object *clone() const; - virtual Type getType() const { return typeString; } - - virtual void write( Bu::Stream &rOut ) const; - virtual void read( Bu::Stream &rIn, char cType ); - - private: - }; + class String : public Gats::Object, public Bu::String + { + public: + String(); + String( const char *s ); + String( const char *s, long iLength ); + String( long iLength ); + String( const String &s ); + String( const Bu::String &s ); + virtual ~String(); + + virtual Object *clone() const; + virtual Type getType() const { return typeString; } + + virtual void write( Bu::Stream &rOut ) const; + virtual void read( Bu::Stream &rIn, char cType ); + + private: + }; }; Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ); diff --git a/c++-libbu++/src/tests/clone.cpp b/c++-libbu++/src/tests/clone.cpp index 8533376..bfb7b27 100644 --- a/c++-libbu++/src/tests/clone.cpp +++ b/c++-libbu++/src/tests/clone.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/types.h" #include @@ -6,17 +13,17 @@ using namespace Bu; int main( int argc, char *argv[] ) { - Gats::Object *pBase = Gats::Object::strToGats("{\"Thing\": 3.14159, \"bool\": true, \"list\":[\"string\",44,{\"Stuff\":{\"list\":[],\"what?\":false}}]}"); + Gats::Object *pBase = Gats::Object::strToGats("{\"Thing\": 3.14159, \"bool\": true, \"list\":[\"string\",44,{\"Stuff\":{\"list\":[],\"what?\":false}}]}"); - sio << *pBase << sio.nl; + sio << *pBase << sio.nl; - Gats::Object *pNew = pBase->clone(); - delete pBase; + Gats::Object *pNew = pBase->clone(); + delete pBase; - sio << *pNew << sio.nl; + sio << *pNew << sio.nl; - delete pNew; + delete pNew; - return 0; + return 0; } diff --git a/c++-libbu++/src/tests/dump.cpp b/c++-libbu++/src/tests/dump.cpp index e0dcb52..f1950b2 100644 --- a/c++-libbu++/src/tests/dump.cpp +++ b/c++-libbu++/src/tests/dump.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 #include #include @@ -7,24 +14,24 @@ using namespace Bu; int main( int argc, char *argv[] ) { - File fIn( argv[1], File::Read ); - Gats::GatsStream gsIn( fIn ); + File fIn( argv[1], File::Read ); + Gats::GatsStream gsIn( fIn ); - for(;;) - { - sio << "Reading from file position: " << fIn.tell() << sio.nl; - Gats::Object *pObj = gsIn.readObject(); - if( !pObj ) - { - if( gsIn.hasReadBuffer() ) - { - sio << "Premature end of stream detected, have " - << gsIn.getReadBufferSize() << "b." << sio.nl; - } - return 0; - } + for(;;) + { + sio << "Reading from file position: " << fIn.tell() << sio.nl; + Gats::Object *pObj = gsIn.readObject(); + if( !pObj ) + { + if( gsIn.hasReadBuffer() ) + { + sio << "Premature end of stream detected, have " + << gsIn.getReadBufferSize() << "b." << sio.nl; + } + return 0; + } - sio << *pObj << sio.nl; - } + sio << *pObj << sio.nl; + } } diff --git a/c++-libbu++/src/tests/int.cpp b/c++-libbu++/src/tests/int.cpp index c19df9c..25ef831 100644 --- a/c++-libbu++/src/tests/int.cpp +++ b/c++-libbu++/src/tests/int.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/integer.h" #include @@ -8,40 +15,40 @@ using namespace Bu; void hexdump( char *dat, int iSize ) { - static const char *hex="0123456789ABCDEF"; - printf("----\n"); - for( int j = 0; j < iSize; j += 8 ) - { - for( int k = j; /*k < iSize &&*/ k < j+8; k++ ) - printf((k>4)&0x0F], hex[dat[k]&0x0F] ); - printf("| "); - for( int k = j; k < iSize && k < j+8; k++ ) - printf("%c ", (dat[k]>13&&dat[k]<127)?(dat[k]):('.') ); - printf("\n"); - } - printf("----\n"); + static const char *hex="0123456789ABCDEF"; + printf("----\n"); + for( int j = 0; j < iSize; j += 8 ) + { + for( int k = j; /*k < iSize &&*/ k < j+8; k++ ) + printf((k>4)&0x0F], hex[dat[k]&0x0F] ); + printf("| "); + for( int k = j; k < iSize && k < j+8; k++ ) + printf("%c ", (dat[k]>13&&dat[k]<127)?(dat[k]):('.') ); + printf("\n"); + } + printf("----\n"); } int main( int argc, char *argv[] ) { - for( int j = 1; j < argc; j++ ) - { - int64_t i = strtoll( argv[j], NULL, 10 ); - MemBuf mb; - Gats::Integer::writePackedInt( mb, i ); - hexdump( mb.getString().getStr(), mb.getString().getSize() ); - } + for( int j = 1; j < argc; j++ ) + { + int64_t i = strtoll( argv[j], NULL, 10 ); + MemBuf mb; + Gats::Integer::writePackedInt( mb, i ); + hexdump( mb.getString().getStr(), mb.getString().getSize() ); + } /* - sio << "Before: " << i << sio.nl; - Gats::Integer::writePackedInt( mb, i ); - mb.write("aaa", 3 ); - mb.setPos( 0 ); - Gats::Integer::readPackedInt( mb, i ); - sio << "After: " << i << sio.nl; - char buf[4]; - buf[mb.read( buf, 3 )] = '\0'; - sio << "Extra: \"" << buf << "\"" << sio.nl; + sio << "Before: " << i << sio.nl; + Gats::Integer::writePackedInt( mb, i ); + mb.write("aaa", 3 ); + mb.setPos( 0 ); + Gats::Integer::readPackedInt( mb, i ); + sio << "After: " << i << sio.nl; + char buf[4]; + buf[mb.read( buf, 3 )] = '\0'; + sio << "Extra: \"" << buf << "\"" << sio.nl; */ - return 0; + return 0; } diff --git a/c++-libbu++/src/types.h b/c++-libbu++/src/types.h index 81240e8..50b3fb8 100644 --- a/c++-libbu++/src/types.h +++ b/c++-libbu++/src/types.h @@ -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/object.h" #include "gats/boolean.h" #include "gats/dictionary.h" -- cgit v1.2.3