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. --- LICENSE | 28 ++ README.md | 115 ++++++ 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 + c++-qt/src/boolean.cpp | 47 ++- c++-qt/src/boolean.h | 47 ++- c++-qt/src/dictionary.cpp | 351 ++++++++-------- c++-qt/src/dictionary.h | 109 ++--- c++-qt/src/float.cpp | 193 ++++----- c++-qt/src/float.h | 47 ++- c++-qt/src/gatsstream.cpp | 195 ++++----- c++-qt/src/gatsstream.h | 113 ++--- c++-qt/src/integer.cpp | 21 +- c++-qt/src/integer.h | 151 +++---- c++-qt/src/list.cpp | 139 ++++--- c++-qt/src/list.h | 99 ++--- c++-qt/src/null.cpp | 13 +- c++-qt/src/null.h | 29 +- c++-qt/src/object.cpp | 463 +++++++++++---------- c++-qt/src/object.h | 83 ++-- c++-qt/src/string.cpp | 41 +- c++-qt/src/string.h | 49 ++- c++-qt/src/types.h | 7 + c++-qt/tests/echo/main.cpp | 15 +- c++-qt/tests/echo/mainwnd.cpp | 39 +- c++-qt/tests/echo/mainwnd.h | 19 +- java/FileExample.java | 7 + java/com/xagasoft/gats/GatsBoolean.java | 7 + java/com/xagasoft/gats/GatsDictionary.java | 7 + java/com/xagasoft/gats/GatsFloat.java | 7 + java/com/xagasoft/gats/GatsInputStream.java | 7 + java/com/xagasoft/gats/GatsInteger.java | 7 + java/com/xagasoft/gats/GatsList.java | 7 + java/com/xagasoft/gats/GatsNull.java | 7 + java/com/xagasoft/gats/GatsObject.java | 7 + java/com/xagasoft/gats/GatsOutputStream.java | 7 + java/com/xagasoft/gats/GatsString.java | 7 + java/com/xagasoft/gats/KeyNotFoundException.java | 7 + java/com/xagasoft/gats/package-info.java | 7 + php/phpgats.php | 7 + php/phpgats2.php | 7 + python/client.py | 6 + python/gats.py | 6 + python/server.py | 6 + python/test.py | 6 + 93 files changed, 3600 insertions(+), 2838 deletions(-) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5eaeb9c --- /dev/null +++ b/LICENSE @@ -0,0 +1,28 @@ +Copyright (C) 2007-2012 Xagasoft + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + - Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + - Neither the name of Xagasoft nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f5302a8 --- /dev/null +++ b/README.md @@ -0,0 +1,115 @@ +# Generalized Agile Transport System (GATS) + +GATS is a data encoding format, as well as a set of libraries for reading and +writing data in that format. It's a structured format reminiscent of a binary +json, but with some extra cool features. + + * All numbers (integers and floating point) are stored in an arbitrary + precision format which takes up the least amount of space it can. + * Unlike textual formats (like json, xml, etc.) floating point numbers are + stored exactly, the exact number you write in is the exact number you read + out. + * All formats stored are machine independent, you can read and write them on + any architecture, any endianness and they will always be the same. No more + encoding worries. + * There are a number of data types you can use to make up data structures: + * Dictionaries + * Lists + * Integers + * Floats + * Strings (binary 8-bit strings, perfect for UTF-8) + * Booleans + * Nulls + +# License + +GATS is distributed under a new-BSD type license. This is fairly permissive, +but if you require other licensing options feel free to contact us. + +# Uses + +GATS was originally intended for use in internet protocols, and is great for +that purpose. Used correctly it allows you to create efficient yet highly +malleable protocols with very little extra effort. + +However, you can certainly use it for other purposes such as serializing data +for storage, and inter-process communication. In fact, with the different +language bindings available, sometimes GATS may be one of the easier ways to +allow, say, a PHP web service to communicate with a custom C++ executable or +python program. + +# Languages/Libraries Supported + +At the moment we actively maintain libraries for C++, java, php, and python. +Other languages and libraries are welcomed. Here's a little info on each +target directory: + + * ''c++-libbu++'' - The original libgats implementation. Works using libbu++ + data types and streams. You need to have libbu++ and Xagasoft build in + order to build this version. + * ''c++-qt'' - A version written using Qt data types. This version builds using + qmake, so if you're using Qt you already have everything you need. Also + features handy signals & slots to make event driven networking even easier! + * ''java'' - A library using the Java native interfaces, everything looks and + works exactly how you would expect it should. There is a Xagasoft Build + script to build a jar file, but it's simple enough that a single javac + command can build it all, or just import the code into your project directly. + This java version has been used on desktops and android devices. + * ''php'' - There are two libraries for working with php, the first defines a + set of classes for fine control over the format, sometimes this is necessary + as php's types are a little loose. The second simply uses php native types + like array() as data transport. The second option is usually the much easier + to use, but doesn't always get the encoding correct for all inputs. + * ''python'' - These work like other serialization mechanisms in Python like + pickle, json, shelve, and marshal. It exposes the functions load, dump, + loads, dumps, and also the handy helpers recv and send for working with + sockets. The Python implementation returns and transmits native Python + data types, which makes life pretty easy. To use this version simply copy + gats.py to your project. + +# Basic Operation + +The way GATS works is dictated by the format, so it works similarly in every +implementation, although they each have slightly different mechanics. When +encoding GATS you always encode each object in it's own "GATS packet." A GATS +packet has a very simple header which includes the size of the packet to make +parsing fast and efficient. + +Each packet can contain a single root object. It can be any type, but for most +protocols a dictionary is a great choice for the root object. + +The format is designed to make it very easy to work with various encoding, +packing, and encryption systems. The reader, by default, will skip all leading +zero bytes that come before a valid GATS packet, and will stop processing +precisely at the end of a valid GATS packet. + +Skipping leading zeros makes it easy to work in environments where padding may +be required. You can use the simplest of all padding schemes (pad with zeros) +and it will work seamlessly with GATS. + +Since the reader always reads exactly the number of bytes it needs, it's very +easy to embed GATS packets in other streams, or read them sequentially as fast +as you can from a socket. + +## A Note About Strings + +All strings in GATS are simply sequences of 8-bit bytes. There is no +overarching encoding that is dictated by the format. When using GATS it is +good to specify how you are encoding your text data, we recommend Unicode. +There is a possibility that a future version of GATS will include a separate +Unicode String data type, but for now it's important to remember this. + +For this reason, we also recommend making the keys in all dictionaries 7-bit +UTF-8 compatible ASCII/Latin1. This isn't required of course, but it makes +things a bit easier. + +# Speed vs Size + +GATS objects are, on average, smaller than storing in other binary formats, and +can be much smaller than textual formats by virtue of storing only as many +bytes as necessary for integers and floats. This also means that GATS requires +more processing than fixed field binary formats, but interestingly not quite as +much as text formats like json. The processing we do on floats is actually +roughly comparable in many ways to text processing, although with fewer steps. + + 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" diff --git a/c++-qt/src/boolean.cpp b/c++-qt/src/boolean.cpp index 3973607..1195bae 100644 --- a/c++-qt/src/boolean.cpp +++ b/c++-qt/src/boolean.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-qt/boolean.h" #include Gats::Boolean::Boolean() : - bVal( false ) + bVal( false ) { } Gats::Boolean::Boolean( bool bVal ) : - bVal( bVal ) + bVal( bVal ) { } @@ -18,35 +25,35 @@ Gats::Boolean::~Boolean() Gats::Object *Gats::Boolean::clone() const { - return new Gats::Boolean( bVal ); + return new Gats::Boolean( bVal ); } void Gats::Boolean::write( QIODevice &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( QIODevice &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++-qt/src/boolean.h b/c++-qt/src/boolean.h index d707e4d..7e42981 100644 --- a/c++-qt/src/boolean.h +++ b/c++-qt/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 @@ -7,26 +14,26 @@ class QIODevice; namespace Gats { - class Boolean : public Gats::Object - { - Q_OBJECT; - public: - Boolean(); - Boolean( bool bVal ); - virtual ~Boolean(); - - virtual Object *clone() const; - - virtual Type getType() const { return typeBoolean; } - bool getValue() const { return bVal; } - void setValue( bool b ) { bVal = b; } - - virtual void write( QIODevice &rOut ) const; - virtual void read( QIODevice &rIn, char cType ); - - private: - bool bVal; - }; + class Boolean : public Gats::Object + { + Q_OBJECT; + public: + Boolean(); + Boolean( bool bVal ); + virtual ~Boolean(); + + virtual Object *clone() const; + + virtual Type getType() const { return typeBoolean; } + bool getValue() const { return bVal; } + void setValue( bool b ) { bVal = b; } + + virtual void write( QIODevice &rOut ) const; + virtual void read( QIODevice &rIn, char cType ); + + private: + bool bVal; + }; }; //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ); diff --git a/c++-qt/src/dictionary.cpp b/c++-qt/src/dictionary.cpp index edcbdb1..b2ef35e 100644 --- a/c++-qt/src/dictionary.cpp +++ b/c++-qt/src/dictionary.cpp @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "gats-qt/dictionary.h" #include "gats-qt/boolean.h" @@ -12,352 +19,352 @@ Gats::Dictionary::Dictionary() Gats::Dictionary::~Dictionary() { - for( iterator i = begin(); i != end(); i++ ) - { - delete *i; - } + for( iterator i = begin(); i != end(); i++ ) + { + delete *i; + } } Gats::Object *Gats::Dictionary::clone() const { - Gats::Dictionary *pClone = new Gats::Dictionary; + Gats::Dictionary *pClone = new Gats::Dictionary; - for( const_iterator i = begin(); i != end(); i++ ) - { - QByteArray bKey = i.key(); - bKey.detach(); - pClone->insert( bKey, (*i)->clone() ); - } + for( const_iterator i = begin(); i != end(); i++ ) + { + QByteArray bKey = i.key(); + bKey.detach(); + pClone->insert( bKey, (*i)->clone() ); + } - return pClone; + return pClone; } void Gats::Dictionary::write( QIODevice &rOut ) const { - rOut.write("d", 1 ); - for( const_iterator i= begin(); i != end(); i++ ) - { - Gats::String s( i.key() ); - s.write( rOut ); - (*i)->write( rOut ); - } - rOut.write("e", 1 ); + rOut.write("d", 1 ); + for( const_iterator i= begin(); i != end(); i++ ) + { + Gats::String s( i.key() ); + s.write( rOut ); + (*i)->write( rOut ); + } + rOut.write("e", 1 ); } void Gats::Dictionary::read( QIODevice &rIn, char cType ) { - for(;;) - { - char cNext; - rIn.read( &cNext, 1 ); - if( cNext == 'e' ) - break; - if( cNext != 's' ) - throw "PUT GOOD EXCEPTION HERE"; - Gats::String sKey; - sKey.read( rIn, cNext ); + for(;;) + { + char cNext; + rIn.read( &cNext, 1 ); + if( cNext == 'e' ) + break; + if( cNext != 's' ) + throw "PUT GOOD EXCEPTION HERE"; + Gats::String sKey; + sKey.read( rIn, cNext ); - ((QHash *)this)->insert( - sKey, Gats::Object::read( rIn ) - ); - } + ((QHash *)this)->insert( + sKey, Gats::Object::read( rIn ) + ); + } } void Gats::Dictionary::insert( const QByteArray &sKey, char i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, unsigned char i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, signed char i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, unsigned short i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, signed short i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, unsigned int i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, signed int i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, signed long i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long long i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, signed long long i ) { - ((QHash *)this)->insert( - sKey, new Gats::Integer( i ) - ); + ((QHash *)this)->insert( + sKey, new Gats::Integer( i ) + ); } /* void Gats::Dictionary::insert( const QByteArray &sKey, bool b ) { - QHash::insert( - sKey, new Gats::Boolean( b ) - ); + QHash::insert( + sKey, new Gats::Boolean( b ) + ); }*/ void Gats::Dictionary::insert( const QByteArray &sKey, float d ) { - QHash::insert( - sKey, new Gats::Float( d ) - ); + QHash::insert( + sKey, new Gats::Float( d ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, double d ) { - QHash::insert( - sKey, new Gats::Float( d ) - ); + QHash::insert( + sKey, new Gats::Float( d ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, const char *s ) { - QHash::insert( - sKey, new Gats::String( s ) - ); + QHash::insert( + sKey, new Gats::String( s ) + ); } void Gats::Dictionary::insert( const QByteArray &sKey, const QByteArray &s ) { - QHash::insert( - sKey, new Gats::String( s ) - ); + QHash::insert( + sKey, new Gats::String( s ) + ); } void Gats::Dictionary::insertBool( const QByteArray &sKey, bool b ) { - QHash::insert( - sKey, new Gats::Boolean( b ) - ); + QHash::insert( + sKey, new Gats::Boolean( b ) + ); } void Gats::Dictionary::insertInt( const QByteArray &sKey, int64_t i ) { - QHash::insert( - sKey, new Gats::Integer( i ) - ); + QHash::insert( + sKey, new Gats::Integer( i ) + ); } void Gats::Dictionary::insertFloat( const QByteArray &sKey, double d ) { - QHash::insert( - sKey, new Gats::Float( d ) - ); + QHash::insert( + sKey, new Gats::Float( d ) + ); } void Gats::Dictionary::insertStr( const QByteArray &sKey, const QByteArray &s ) { - QHash::insert( - sKey, new Gats::String( s ) - ); + QHash::insert( + sKey, new Gats::String( s ) + ); } void Gats::Dictionary::insertList( const QByteArray &sKey, Gats::List *pL ) { - QHash::insert( - sKey, pL - ); + QHash::insert( + sKey, pL + ); } void Gats::Dictionary::insertDict( const QByteArray &sKey, - Gats::Dictionary *pD ) + Gats::Dictionary *pD ) { - QHash::insert( - sKey, pD - ); + QHash::insert( + sKey, pD + ); } Gats::List *Gats::Dictionary::insertList( const QByteArray &sKey ) { - Gats::List *pLst = new Gats::List(); - insertList( sKey, pLst ); - return pLst; + Gats::List *pLst = new Gats::List(); + insertList( sKey, pLst ); + return pLst; } Gats::Dictionary *Gats::Dictionary::insertDict( const QByteArray &sKey ) { - Gats::Dictionary *pDict = new Gats::Dictionary(); - insertDict( sKey, pDict ); - return pDict; + Gats::Dictionary *pDict = new Gats::Dictionary(); + insertDict( sKey, pDict ); + return pDict; } bool Gats::Dictionary::valueBool( const QByteArray &sKey ) { - Gats::Boolean *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Boolean *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } int64_t Gats::Dictionary::valueInt( const QByteArray &sKey ) { - Gats::Integer *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Integer *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } double Gats::Dictionary::valueFloat( const QByteArray &sKey ) { - Gats::Float *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Float *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } QByteArray Gats::Dictionary::valueStr( const QByteArray &sKey ) { - Gats::String *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::String *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return *pOb; + return *pOb; } Gats::List *Gats::Dictionary::valueList( const QByteArray &sKey ) { - Gats::List *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::List *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb; + return pOb; } Gats::Dictionary *Gats::Dictionary::valueDict( const QByteArray &sKey ) { - Gats::Dictionary *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Dictionary *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb; + return pOb; } bool Gats::Dictionary::valueBool( const QByteArray &sKey ) const { - Gats::Boolean *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Boolean *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } int64_t Gats::Dictionary::valueInt( const QByteArray &sKey ) const { - Gats::Integer *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Integer *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } double Gats::Dictionary::valueFloat( const QByteArray &sKey ) const { - Gats::Float *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Float *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb->getValue(); + return pOb->getValue(); } QByteArray Gats::Dictionary::valueStr( const QByteArray &sKey ) const { - Gats::String *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::String *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return *pOb; + return *pOb; } Gats::List *Gats::Dictionary::valueList( const QByteArray &sKey ) const { - Gats::List *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::List *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb; + return pOb; } Gats::Dictionary *Gats::Dictionary::valueDict( const QByteArray &sKey ) const { - Gats::Dictionary *pOb = dynamic_cast( value( sKey ) ); - if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + Gats::Dictionary *pOb = dynamic_cast( value( sKey ) ); + if( !pOb ) + throw "PUT GOOD EXCEPTION HERE"; - return pOb; + return pOb; } /* Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ) { - f << "(dict) {"; - f.incIndent(); - int iMax = 0; - for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) - { - if( i.valueKey().valueSize() > iMax ) - iMax = i.valueKey().valueSize(); - } - iMax += 2; - for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) - { - f << f.nl << Bu::Fmt( iMax ) << i.valueKey() + ": " << *i.getValue(); - } - f.decIndent(); - f << f.nl << "}"; - - return f; + f << "(dict) {"; + f.incIndent(); + int iMax = 0; + for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) + { + if( i.valueKey().valueSize() > iMax ) + iMax = i.valueKey().valueSize(); + } + iMax += 2; + for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) + { + f << f.nl << Bu::Fmt( iMax ) << i.valueKey() + ": " << *i.getValue(); + } + f.decIndent(); + f << f.nl << "}"; + + return f; } */ diff --git a/c++-qt/src/dictionary.h b/c++-qt/src/dictionary.h index 7f95cf1..af1d436 100644 --- a/c++-qt/src/dictionary.h +++ b/c++-qt/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,62 +14,62 @@ namespace Gats { - class List; + class List; - class Dictionary : public Gats::Object, - public QHash - { - Q_OBJECT; - public: - Dictionary(); - virtual ~Dictionary(); + class Dictionary : public Gats::Object, + public QHash + { + Q_OBJECT; + public: + Dictionary(); + virtual ~Dictionary(); - virtual Object *clone() const; + virtual Object *clone() const; - virtual Type getType() const { return typeDictionary; } - virtual void write( QIODevice &rOut ) const; - virtual void read( QIODevice &rIn, char cType ); + virtual Type getType() const { return typeDictionary; } + virtual void write( QIODevice &rOut ) const; + virtual void read( QIODevice &rIn, char cType ); - void insert( const QByteArray &sKey, const char *s ); - void insert( const QByteArray &sKey, const QByteArray &s ); - void insert( const QByteArray &sKey, char i ); - void insert( const QByteArray &sKey, unsigned char i ); - void insert( const QByteArray &sKey, signed char i ); - void insert( const QByteArray &sKey, unsigned short i ); - void insert( const QByteArray &sKey, signed short i ); - void insert( const QByteArray &sKey, unsigned int i ); - void insert( const QByteArray &sKey, signed int i ); - void insert( const QByteArray &sKey, unsigned long i ); - void insert( const QByteArray &sKey, signed long i ); - void insert( const QByteArray &sKey, unsigned long long i ); - void insert( const QByteArray &sKey, signed long long i ); - //void insert( const QByteArray &sKey, bool b ); - void insert( const QByteArray &sKey, float d ); - void insert( const QByteArray &sKey, double d ); - using QHash::insert; - void insertBool( const QByteArray &sKey, bool b ); - void insertInt( const QByteArray &sKey, int64_t i ); - void insertFloat( const QByteArray &sKey, double d ); - void insertStr( const QByteArray &sKey, const QByteArray &s ); - void insertList( const QByteArray &sKey, Gats::List *pL ); - void insertDict( const QByteArray &sKey, Gats::Dictionary *pD ); - Gats::List *insertList( const QByteArray &sKey ); - Gats::Dictionary *insertDict( const QByteArray &sKey ); + void insert( const QByteArray &sKey, const char *s ); + void insert( const QByteArray &sKey, const QByteArray &s ); + void insert( const QByteArray &sKey, char i ); + void insert( const QByteArray &sKey, unsigned char i ); + void insert( const QByteArray &sKey, signed char i ); + void insert( const QByteArray &sKey, unsigned short i ); + void insert( const QByteArray &sKey, signed short i ); + void insert( const QByteArray &sKey, unsigned int i ); + void insert( const QByteArray &sKey, signed int i ); + void insert( const QByteArray &sKey, unsigned long i ); + void insert( const QByteArray &sKey, signed long i ); + void insert( const QByteArray &sKey, unsigned long long i ); + void insert( const QByteArray &sKey, signed long long i ); + //void insert( const QByteArray &sKey, bool b ); + void insert( const QByteArray &sKey, float d ); + void insert( const QByteArray &sKey, double d ); + using QHash::insert; + void insertBool( const QByteArray &sKey, bool b ); + void insertInt( const QByteArray &sKey, int64_t i ); + void insertFloat( const QByteArray &sKey, double d ); + void insertStr( const QByteArray &sKey, const QByteArray &s ); + void insertList( const QByteArray &sKey, Gats::List *pL ); + void insertDict( const QByteArray &sKey, Gats::Dictionary *pD ); + Gats::List *insertList( const QByteArray &sKey ); + Gats::Dictionary *insertDict( const QByteArray &sKey ); - bool valueBool( const QByteArray &sKey ); - int64_t valueInt( const QByteArray &sKey ); - double valueFloat( const QByteArray &sKey ); - QByteArray valueStr( const QByteArray &sKey ); - Gats::List *valueList( const QByteArray &sKey ); - Gats::Dictionary *valueDict( const QByteArray &sKey ); - - bool valueBool( const QByteArray &sKey ) const; - int64_t valueInt( const QByteArray &sKey ) const; - double valueFloat( const QByteArray &sKey ) const; - QByteArray valueStr( const QByteArray &sKey ) const; - Gats::List *valueList( const QByteArray &sKey ) const; - Gats::Dictionary *valueDict( const QByteArray &sKey ) const; - }; + bool valueBool( const QByteArray &sKey ); + int64_t valueInt( const QByteArray &sKey ); + double valueFloat( const QByteArray &sKey ); + QByteArray valueStr( const QByteArray &sKey ); + Gats::List *valueList( const QByteArray &sKey ); + Gats::Dictionary *valueDict( const QByteArray &sKey ); + + bool valueBool( const QByteArray &sKey ) const; + int64_t valueInt( const QByteArray &sKey ) const; + double valueFloat( const QByteArray &sKey ) const; + QByteArray valueStr( const QByteArray &sKey ) const; + Gats::List *valueList( const QByteArray &sKey ) const; + Gats::Dictionary *valueDict( const QByteArray &sKey ) const; + }; }; //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ); diff --git a/c++-qt/src/float.cpp b/c++-qt/src/float.cpp index fedecf3..03ff755 100644 --- a/c++-qt/src/float.cpp +++ b/c++-qt/src/float.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-qt/float.h" #include "gats-qt/integer.h" #include Gats::Float::Float() : - fVal( 0.0 ) + fVal( 0.0 ) { } Gats::Float::Float( double f ) : - fVal( f ) + fVal( f ) { } @@ -19,109 +26,109 @@ Gats::Float::~Float() Gats::Object *Gats::Float::clone() const { - return new Gats::Float( fVal ); + return new Gats::Float( fVal ); } void Gats::Float::write( QIODevice &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 ); - - QByteArray 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.size():s.size() ); - rOut.write( s.constData(), s.size() ); - Gats::Integer::writePackedInt( rOut, iScale ); - } + iScale = log( d ) / 0x1.62e42fefa39efp+2; // log( 256.0 ) + if( iScale < 0 ) iScale--; + d /= pow( 256.0, iScale ); + + QByteArray 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.size():s.size() ); + rOut.write( s.constData(), s.size() ); + Gats::Integer::writePackedInt( rOut, iScale ); + } } void Gats::Float::read( QIODevice &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; - } - QByteArray s( iStr, '\0' ); - rIn.read( s.data(), 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; + } + QByteArray s( iStr, '\0' ); + rIn.read( s.data(), 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++-qt/src/float.h b/c++-qt/src/float.h index 93bfe18..6cc9950 100644 --- a/c++-qt/src/float.h +++ b/c++-qt/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 @@ -5,26 +12,26 @@ namespace Gats { - class Float : public Gats::Object - { - Q_OBJECT; - public: - Float(); - Float( double f ); - virtual ~Float(); - - virtual Object *clone() const; - - virtual Type getType() const { return typeFloat; } - double getValue() const { return fVal; } - - virtual void write( QIODevice &rOut ) const; - virtual void read( QIODevice &rIn, char cType ); - - private: - double fVal; - mutable QByteArray sWriteCache; - }; + class Float : public Gats::Object + { + Q_OBJECT; + public: + Float(); + Float( double f ); + virtual ~Float(); + + virtual Object *clone() const; + + virtual Type getType() const { return typeFloat; } + double getValue() const { return fVal; } + + virtual void write( QIODevice &rOut ) const; + virtual void read( QIODevice &rIn, char cType ); + + private: + double fVal; + mutable QByteArray sWriteCache; + }; } //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ); diff --git a/c++-qt/src/gatsstream.cpp b/c++-qt/src/gatsstream.cpp index 920b2d6..f49fdb5 100644 --- a/c++-qt/src/gatsstream.cpp +++ b/c++-qt/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-qt/gatsstream.h" #include "gats-qt/object.h" @@ -10,7 +17,7 @@ #include Gats::GatsStream::GatsStream( QIODevice &rStream ) : - rStream( rStream ) + rStream( rStream ) { } @@ -20,110 +27,110 @@ Gats::GatsStream::~GatsStream() Gats::Object *Gats::GatsStream::readObject() { - char buf[1500]; - - do - { - if( qbRead.size() < 5 ) - { - int iRead = rStream.read( buf, 5-qbRead.size() ); - qbRead.append( buf, iRead ); - - if( qbRead.size() < 5 ) - return NULL; - } - } while( !skipReadNulls() ); - - uint8_t uVer; - uVer = qbRead[0]; - - int32_t iSize; - memcpy( &iSize, qbRead.constData()+1, 4 ); - iSize = ntohl( iSize ); - while( qbRead.size() < iSize ) - { - int32_t iRead = iSize - qbRead.size(); - if( iRead > 1500 ) - iRead = 1500; - int32_t iReal = rStream.read( buf, iRead ); - qbRead.append( buf, iReal ); - if( iReal < iRead ) - { - return NULL; - } - } - - if( qbRead.size() < iSize ) - { - return NULL; - } - - QBuffer rTmp( &qbRead ); - rTmp.open( QIODevice::ReadOnly ); - rTmp.seek( 5 ); - Gats::Object *pObj = Gats::Object::read( rTmp ); - qbRead.clear(); - - emit objectRead( pObj ); - - return pObj; + char buf[1500]; + + do + { + if( qbRead.size() < 5 ) + { + int iRead = rStream.read( buf, 5-qbRead.size() ); + qbRead.append( buf, iRead ); + + if( qbRead.size() < 5 ) + return NULL; + } + } while( !skipReadNulls() ); + + uint8_t uVer; + uVer = qbRead[0]; + + int32_t iSize; + memcpy( &iSize, qbRead.constData()+1, 4 ); + iSize = ntohl( iSize ); + while( qbRead.size() < iSize ) + { + int32_t iRead = iSize - qbRead.size(); + if( iRead > 1500 ) + iRead = 1500; + int32_t iReal = rStream.read( buf, iRead ); + qbRead.append( buf, iReal ); + if( iReal < iRead ) + { + return NULL; + } + } + + if( qbRead.size() < iSize ) + { + return NULL; + } + + QBuffer rTmp( &qbRead ); + rTmp.open( QIODevice::ReadOnly ); + rTmp.seek( 5 ); + Gats::Object *pObj = Gats::Object::read( rTmp ); + qbRead.clear(); + + emit objectRead( pObj ); + + return pObj; } void Gats::GatsStream::readAllObjects() { - while( readObject() ) { } + while( readObject() ) { } } void Gats::GatsStream::writeObject( Gats::Object *pObject ) { - QIODevice *pTmp; - if( rStream.isSequential() ) - { - pTmp = new QBuffer(); - pTmp->open( QIODevice::WriteOnly ); - } - else - { - pTmp = &rStream; - } - - uint8_t uBuf = 1; - uint32_t iSize = 0; - pTmp->write( (const char *)&uBuf, 1 ); - uint64_t iSizePos = pTmp->pos(); - pTmp->write( (const char *)&iSize, 4 ); - pObject->write( *pTmp ); - iSize = htonl( pTmp->pos() ); - uint64_t iEndPos = pTmp->pos(); - pTmp->seek( iSizePos ); - pTmp->write( (const char *)&iSize, 4 ); - - if( rStream.isSequential() ) - { - pTmp->close(); - rStream.write( ((QBuffer *)pTmp)->data() ); - delete pTmp; - } - else - { - pTmp->seek( iSizePos ); - } + QIODevice *pTmp; + if( rStream.isSequential() ) + { + pTmp = new QBuffer(); + pTmp->open( QIODevice::WriteOnly ); + } + else + { + pTmp = &rStream; + } + + uint8_t uBuf = 1; + uint32_t iSize = 0; + pTmp->write( (const char *)&uBuf, 1 ); + uint64_t iSizePos = pTmp->pos(); + pTmp->write( (const char *)&iSize, 4 ); + pObject->write( *pTmp ); + iSize = htonl( pTmp->pos() ); + uint64_t iEndPos = pTmp->pos(); + pTmp->seek( iSizePos ); + pTmp->write( (const char *)&iSize, 4 ); + + if( rStream.isSequential() ) + { + pTmp->close(); + rStream.write( ((QBuffer *)pTmp)->data() ); + delete pTmp; + } + else + { + pTmp->seek( iSizePos ); + } } bool Gats::GatsStream::skipReadNulls() { - bool bHaveSeeked = false; - for(;;) - { - if( qbRead.size() == 0 ) - return false; - if( qbRead.at(0) != 0 ) - return !bHaveSeeked; //true; - else - { - qbRead.remove( 0, 1 ); - bHaveSeeked = true; - } - } + bool bHaveSeeked = false; + for(;;) + { + if( qbRead.size() == 0 ) + return false; + if( qbRead.at(0) != 0 ) + return !bHaveSeeked; //true; + else + { + qbRead.remove( 0, 1 ); + bHaveSeeked = true; + } + } } diff --git a/c++-qt/src/gatsstream.h b/c++-qt/src/gatsstream.h index 90e0514..979ca60 100644 --- a/c++-qt/src/gatsstream.h +++ b/c++-qt/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,67 +13,67 @@ namespace Gats { - class Object; + class Object; - class GatsStream : public QObject - { - Q_OBJECT; - public: - GatsStream( QIODevice &rStream ); - virtual ~GatsStream(); + class GatsStream : public QObject + { + Q_OBJECT; + public: + GatsStream( QIODevice &rStream ); + virtual ~GatsStream(); - public slots: - /** - * 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(); - - /** - * Works exactly like readObject, except it reads all pending objects - * and emits a objectRead signal for each one read. It doesn't return - * anything. This is perfect for connecting to a QIODevice's readRead - * signal. - */ - void readAllObjects(); + public slots: + /** + * 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(); + + /** + * Works exactly like readObject, except it reads all pending objects + * and emits a objectRead signal for each one read. It doesn't return + * anything. This is perfect for connecting to a QIODevice's readRead + * signal. + */ + void readAllObjects(); - public: - /** - * Write an object - */ - void writeObject( Gats::Object *pObject ); + public: + /** + * 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.size() > 0; } - int getReadBufferSize() { return qbRead.size(); } + /** + * 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.size() > 0; } + int getReadBufferSize() { return qbRead.size(); } - QIODevice &getIODevice() { return rStream; } + QIODevice &getIODevice() { return rStream; } - signals: - void objectRead( Gats::Object *pObj ); + signals: + void objectRead( Gats::Object *pObj ); - private: - bool skipReadNulls(); + private: + bool skipReadNulls(); - private: - QIODevice &rStream; - QByteArray qbRead; - }; + private: + QIODevice &rStream; + QByteArray qbRead; + }; }; #endif diff --git a/c++-qt/src/integer.cpp b/c++-qt/src/integer.cpp index 82727f3..721c434 100644 --- a/c++-qt/src/integer.cpp +++ b/c++-qt/src/integer.cpp @@ -1,12 +1,19 @@ +/* + * Copyright (C) 2007-2012 Xagasoft, All rights reserved. + * + * This file is part of the libgats library and is released under the + * terms of the license contained in the file LICENSE. + */ + #include "gats-qt/integer.h" Gats::Integer::Integer() : - iVal( 0 ) + iVal( 0 ) { } Gats::Integer::Integer( int64_t iVal ) : - iVal( iVal ) + iVal( iVal ) { } @@ -16,22 +23,22 @@ Gats::Integer::~Integer() Gats::Object *Gats::Integer::clone() const { - return new Gats::Integer( iVal ); + return new Gats::Integer( iVal ); } void Gats::Integer::write( QIODevice &rOut ) const { - rOut.write("i", 1 ); - writePackedInt( rOut, iVal ); + rOut.write("i", 1 ); + writePackedInt( rOut, iVal ); } void Gats::Integer::read( QIODevice &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++-qt/src/integer.h b/c++-qt/src/integer.h index db36e30..9178796 100644 --- a/c++-qt/src/integer.h +++ b/c++-qt/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,78 +16,78 @@ namespace Gats { - class Integer : public Gats::Object - { - Q_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; } - void setValue( int64_t iNewVal ) { iVal = iNewVal; } - - virtual void write( QIODevice &rOut ) const; - virtual void read( QIODevice &rIn, char cType ); - - template - static void readPackedInt( QIODevice &rStream, itype &rOut ) - { - int8_t b; - rOut = 0; - bool bNeg; - - rStream.read( (char *)&b, 1 ); - bNeg = ( b&0x40 ); - rOut |= (itype(b&0x3F)); - int c = 0; - while( (b&0x80) ) - { - rStream.read( (char *)&b, 1 ); - rOut |= (itype(b&0x7F)) << (6+7*(c++)); - } - if( bNeg ) rOut = -rOut; - } - - template - static void writePackedInt( QIODevice &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( (const char *)&b, 1 ); - iIn = iIn >> 6; - - while( iIn ) - { - b = (iIn&0x7F); - if( iIn > b ) - b |= 0x80; - rStream.write( (const char *)&b, 1 ); - iIn = iIn >> 7; - } - } - - private: - int64_t iVal; - }; + class Integer : public Gats::Object + { + Q_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; } + void setValue( int64_t iNewVal ) { iVal = iNewVal; } + + virtual void write( QIODevice &rOut ) const; + virtual void read( QIODevice &rIn, char cType ); + + template + static void readPackedInt( QIODevice &rStream, itype &rOut ) + { + int8_t b; + rOut = 0; + bool bNeg; + + rStream.read( (char *)&b, 1 ); + bNeg = ( b&0x40 ); + rOut |= (itype(b&0x3F)); + int c = 0; + while( (b&0x80) ) + { + rStream.read( (char *)&b, 1 ); + rOut |= (itype(b&0x7F)) << (6+7*(c++)); + } + if( bNeg ) rOut = -rOut; + } + + template + static void writePackedInt( QIODevice &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( (const char *)&b, 1 ); + iIn = iIn >> 6; + + while( iIn ) + { + b = (iIn&0x7F); + if( iIn > b ) + b |= 0x80; + rStream.write( (const char *)&b, 1 ); + iIn = iIn >> 7; + } + } + + private: + int64_t iVal; + }; }; //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); diff --git a/c++-qt/src/list.cpp b/c++-qt/src/list.cpp index 8a648e9..158a7c1 100644 --- a/c++-qt/src/list.cpp +++ b/c++-qt/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-qt/list.h" #include "gats-qt/string.h" @@ -12,193 +19,193 @@ Gats::List::List() Gats::List::~List() { - for( iterator i = begin(); i != end(); i++ ) - { - delete *i; - } + for( iterator i = begin(); i != end(); i++ ) + { + delete *i; + } } Gats::Object *Gats::List::clone() const { - Gats::List *pClone = new Gats::List; + Gats::List *pClone = new Gats::List; - for( const_iterator i = begin(); i != end(); i++ ) - { - pClone->append( (*i)->clone() ); - } + for( const_iterator i = begin(); i != end(); i++ ) + { + pClone->append( (*i)->clone() ); + } - return pClone; + return pClone; } void Gats::List::write( QIODevice &rOut ) const { - rOut.write("l", 1 ); - for( const_iterator i = begin(); i != end(); i++ ) - { - (*i)->write( rOut ); - } - rOut.write("e", 1 ); + rOut.write("l", 1 ); + for( const_iterator i = begin(); i != end(); i++ ) + { + (*i)->write( rOut ); + } + rOut.write("e", 1 ); } void Gats::List::read( QIODevice &rIn, char cType ) { - for(;;) - { - Gats::Object *pObj = Gats::Object::read( rIn ); - if( pObj == NULL ) - break; - append( pObj ); - } + for(;;) + { + Gats::Object *pObj = Gats::Object::read( rIn ); + if( pObj == NULL ) + break; + append( pObj ); + } } void Gats::List::append( const char *s ) { - QList::append( new Gats::String( s ) ); + QList::append( new Gats::String( s ) ); } void Gats::List::append( const QByteArray &s ) { - QList::append( new Gats::String( s ) ); + QList::append( new Gats::String( s ) ); } void Gats::List::append( int32_t i ) { - QList::append( new Gats::Integer( i ) ); + QList::append( new Gats::Integer( i ) ); } void Gats::List::append( int64_t i ) { - QList::append( new Gats::Integer( i ) ); + QList::append( new Gats::Integer( i ) ); } void Gats::List::append( double d ) { - QList::append( new Gats::Float( d ) ); + QList::append( new Gats::Float( d ) ); } void Gats::List::appendStr( const QByteArray &s ) { - QList::append( new Gats::String( s ) ); + QList::append( new Gats::String( s ) ); } void Gats::List::appendInt( int64_t i ) { - QList::append( new Gats::Integer( i ) ); + QList::append( new Gats::Integer( i ) ); } void Gats::List::appendFloat( double d ) { - QList::append( new Gats::Float( d ) ); + QList::append( new Gats::Float( d ) ); } void Gats::List::appendBool( bool b ) { - QList::append( new Gats::Boolean( b ) ); + QList::append( new Gats::Boolean( b ) ); } void Gats::List::appendList( Gats::List *pL ) { - QList::append( pL ); + QList::append( pL ); } void Gats::List::appendDict( Gats::Dictionary *pD ) { - QList::append( pD ); + QList::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 ) { - QList::prepend( new Gats::String( s ) ); + QList::prepend( new Gats::String( s ) ); } void Gats::List::prepend( const QByteArray &s ) { - QList::prepend( new Gats::String( s ) ); + QList::prepend( new Gats::String( s ) ); } void Gats::List::prepend( int32_t i ) { - QList::prepend( new Gats::Integer( i ) ); + QList::prepend( new Gats::Integer( i ) ); } void Gats::List::prepend( int64_t i ) { - QList::prepend( new Gats::Integer( i ) ); + QList::prepend( new Gats::Integer( i ) ); } void Gats::List::prepend( double d ) { - QList::prepend( new Gats::Float( d ) ); + QList::prepend( new Gats::Float( d ) ); } void Gats::List::prependStr( const QByteArray &s ) { - QList::prepend( new Gats::String( s ) ); + QList::prepend( new Gats::String( s ) ); } void Gats::List::prependInt( int64_t i ) { - QList::prepend( new Gats::Integer( i ) ); + QList::prepend( new Gats::Integer( i ) ); } void Gats::List::prependFloat( double d ) { - QList::prepend( new Gats::Float( d ) ); + QList::prepend( new Gats::Float( d ) ); } void Gats::List::prependBool( bool b ) { - QList::prepend( new Gats::Boolean( b ) ); + QList::prepend( new Gats::Boolean( b ) ); } void Gats::List::prependList( Gats::List *pL ) { - QList::prepend( pL ); + QList::prepend( pL ); } void Gats::List::prependDict( Gats::Dictionary *pD ) { - QList::prepend( pD ); + QList::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++-qt/src/list.h b/c++-qt/src/list.h index 6e5ac56..7577bad 100644 --- a/c++-qt/src/list.h +++ b/c++-qt/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 @@ -6,52 +13,52 @@ namespace Gats { - class Dictionary; - - class List : public Gats::Object, public QList - { - Q_OBJECT; - public: - List(); - virtual ~List(); - - virtual Object *clone() const; - - virtual Type getType() const { return typeList; } - - virtual void write( QIODevice &rOut ) const; - virtual void read( QIODevice &rIn, char cType ); - - void append( const char *s ); - void append( const QByteArray &s ); - void append( int32_t i ); - void append( int64_t i ); - void append( double d ); - using QList::append; - void appendStr( const QByteArray &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 QByteArray &s ); - void prepend( int32_t i ); - void prepend( int64_t i ); - void prepend( double d ); - using QList::prepend; - void prependStr( const QByteArray &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 QList + { + Q_OBJECT; + public: + List(); + virtual ~List(); + + virtual Object *clone() const; + + virtual Type getType() const { return typeList; } + + virtual void write( QIODevice &rOut ) const; + virtual void read( QIODevice &rIn, char cType ); + + void append( const char *s ); + void append( const QByteArray &s ); + void append( int32_t i ); + void append( int64_t i ); + void append( double d ); + using QList::append; + void appendStr( const QByteArray &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 QByteArray &s ); + void prepend( int32_t i ); + void prepend( int64_t i ); + void prepend( double d ); + using QList::prepend; + void prependStr( const QByteArray &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++-qt/src/null.cpp b/c++-qt/src/null.cpp index f259887..8d46250 100644 --- a/c++-qt/src/null.cpp +++ b/c++-qt/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-qt/null.h" #include @@ -12,12 +19,12 @@ Gats::Null::~Null() Gats::Object *Gats::Null::clone() const { - return new Gats::Null(); + return new Gats::Null(); } void Gats::Null::write( QIODevice &rOut ) const { - rOut.write("n", 1 ); + rOut.write("n", 1 ); } void Gats::Null::read( QIODevice &rIn, char cType ) @@ -26,6 +33,6 @@ void Gats::Null::read( QIODevice &rIn, char cType ) /* Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ) { - return f << "(bool) " << b.getValue(); + return f << "(bool) " << b.getValue(); } */ diff --git a/c++-qt/src/null.h b/c++-qt/src/null.h index 354de12..f3ec45b 100644 --- a/c++-qt/src/null.h +++ b/c++-qt/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 @@ -7,20 +14,20 @@ class QIODevice; namespace Gats { - class Null : public Gats::Object - { - Q_OBJECT; - public: - Null(); - virtual ~Null(); + class Null : public Gats::Object + { + Q_OBJECT; + public: + Null(); + virtual ~Null(); - virtual Object *clone() const; + virtual Object *clone() const; - virtual Type getType() const { return typeNull; } + virtual Type getType() const { return typeNull; } - virtual void write( QIODevice &rOut ) const; - virtual void read( QIODevice &rIn, char cType ); - }; + virtual void write( QIODevice &rOut ) const; + virtual void read( QIODevice &rIn, char cType ); + }; }; //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ); diff --git a/c++-qt/src/object.cpp b/c++-qt/src/object.cpp index 4290e17..7c05228 100644 --- a/c++-qt/src/object.cpp +++ b/c++-qt/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-qt/object.h" #include "gats-qt/integer.h" @@ -22,126 +29,126 @@ Gats::Object::~Object() Gats::Object *Gats::Object::read( QIODevice &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 "Invalid Gats type discovered: "; - } - - 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 "Invalid Gats type discovered: "; + } + + pObj->read( rIn, buf ); + + return pObj; } /* void Gats::Object::skipWs( QByteArray::const_iterator &i ) { - for(; *i == ' ' || *i == '\t' || *i == '\r' || *i == '\n'; i++ ) { } + for(; *i == ' ' || *i == '\t' || *i == '\r' || *i == '\n'; i++ ) { } } QByteArray Gats::Object::token( QByteArray::const_iterator &i ) { - QByteArray sRet; - if( *i == '\"' ) + QByteArray 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( QByteArray::const_iterator &i ) { - skipWs( i ); - - switch( *i ) - { - case '[': - { - Gats::List *pLst = new Gats::List(); - i++; - for(;;) - { - Gats::Object *pObj = strToGats( i ); - if( !pObj ) - break; - pLst->append( pObj ); - skipWs( i ); - switch( *i ) - { - case ',': - i++; - break; - - case ']': - i++; - return pLst; - - default: - throw "PUT GOOD EXCEPTION HERE"; - } - } - } - break; - - case '{': - { - Gats::Dictionary *pDict = new Gats::Dictionary(); - i++; - for(;;) - { - skipWs( i ); - if( *i != '\"' ) + skipWs( i ); + + switch( *i ) + { + case '[': + { + Gats::List *pLst = new Gats::List(); + i++; + for(;;) + { + Gats::Object *pObj = strToGats( i ); + if( !pObj ) + break; + pLst->append( pObj ); + skipWs( i ); + switch( *i ) + { + case ',': + i++; + break; + + case ']': + i++; + return pLst; + + default: + throw "PUT GOOD EXCEPTION HERE"; + } + } + } + break; + + case '{': + { + Gats::Dictionary *pDict = new Gats::Dictionary(); + i++; + for(;;) + { + skipWs( i ); + if( *i != '\"' ) throw "PUT GOOD EXCEPTION HERE"; QByteArray sKey = token( i ); skipWs( i ); @@ -172,144 +179,144 @@ Gats::Object *Gats::Object::strToGats( QByteArray::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 '-': - { - QByteArray 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( QByteArray::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: - { - QByteArray 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 - { - QByteArray st = s.toLower(); - if( st == "true" ) - { - return new Gats::Boolean( true ); - } - else if( st == "false" ) - { - return new Gats::Boolean( false ); - } - } - } - } - 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 '-': + { + QByteArray 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( QByteArray::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: + { + QByteArray 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 + { + QByteArray st = s.toLower(); + if( st == "true" ) + { + return new Gats::Boolean( true ); + } + else if( st == "false" ) + { + return new Gats::Boolean( false ); + } + } + } + } + break; + } + + return NULL; } Gats::Object *Gats::Object::strToGats( const QByteArray &sStr ) { - QByteArray::const_iterator i = sStr.begin(); + QByteArray::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); - - 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); + + 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"; - } - - 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"; + } + + 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"; - } - - 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"; + } + + return "***unknown***"; } diff --git a/c++-qt/src/object.h b/c++-qt/src/object.h index 008ebef..7e12b87 100644 --- a/c++-qt/src/object.h +++ b/c++-qt/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 @@ -8,44 +15,44 @@ class QIODevice; 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 QObject - { - Q_OBJECT; - public: - Object(); - virtual ~Object(); - - virtual Object *clone() const=0; - - virtual Type getType() const =0; - - virtual void write( QIODevice &rOut ) const=0; - virtual void read( QIODevice &rIn, char cType )=0; - - static Object *read( QIODevice &rIn ); -// static Object *strToGats( const &sStr ); - - private: -// static Object *strToGats( QByteArray::const_iterator &i ); -// static QByteArray token( QByteArray::const_iterator &i ); -// static void skipWs( QByteArray::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 QObject + { + Q_OBJECT; + public: + Object(); + virtual ~Object(); + + virtual Object *clone() const=0; + + virtual Type getType() const =0; + + virtual void write( QIODevice &rOut ) const=0; + virtual void read( QIODevice &rIn, char cType )=0; + + static Object *read( QIODevice &rIn ); +// static Object *strToGats( const &sStr ); + + private: +// static Object *strToGats( QByteArray::const_iterator &i ); +// static QByteArray token( QByteArray::const_iterator &i ); +// static void skipWs( QByteArray::const_iterator &i ); + }; + + const char *typeToStr( Type t ); }; //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ); diff --git a/c++-qt/src/string.cpp b/c++-qt/src/string.cpp index ef23829..7d2d20f 100644 --- a/c++-qt/src/string.cpp +++ b/c++-qt/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-qt/string.h" #include "gats-qt/integer.h" @@ -7,27 +14,27 @@ Gats::String::String() } Gats::String::String( const char *s ) : - QByteArray( s ) + QByteArray( s ) { } Gats::String::String( const char *s, long iLength ) : - QByteArray( s, iLength ) + QByteArray( s, iLength ) { } Gats::String::String( long iLength ) : - QByteArray( iLength, '\0' ) + QByteArray( iLength, '\0' ) { } Gats::String::String( const String &s ) : - QByteArray( s ) + QByteArray( s ) { } Gats::String::String( const QByteArray &s ) : - QByteArray( s ) + QByteArray( s ) { } @@ -37,29 +44,29 @@ Gats::String::~String() Gats::Object *Gats::String::clone() const { - QByteArray baClone = *this; - baClone.detach(); - return new Gats::String( baClone ); + QByteArray baClone = *this; + baClone.detach(); + return new Gats::String( baClone ); } void Gats::String::write( QIODevice &rOut ) const { - rOut.write("s", 1 ); - uint32_t iSize = size(); - Gats::Integer::writePackedInt( rOut, iSize ); - rOut.write( constData(), iSize ); + rOut.write("s", 1 ); + uint32_t iSize = size(); + Gats::Integer::writePackedInt( rOut, iSize ); + rOut.write( constData(), iSize ); } void Gats::String::read( QIODevice &rIn, char cType ) { - uint32_t iSize; - Gats::Integer::readPackedInt( rIn, iSize ); - fill( '\0', iSize ); - rIn.read( data(), iSize ); + uint32_t iSize; + Gats::Integer::readPackedInt( rIn, iSize ); + fill( '\0', iSize ); + rIn.read( data(), iSize ); } /* Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ) { - return f << "(str) \"" << dynamic_cast(s) << "\""; + return f << "(str) \"" << dynamic_cast(s) << "\""; } */ diff --git a/c++-qt/src/string.h b/c++-qt/src/string.h index 9bf6ce3..a679fc0 100644 --- a/c++-qt/src/string.h +++ b/c++-qt/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,27 +13,27 @@ namespace Gats { - class String : public Gats::Object, public QByteArray - { - Q_OBJECT; - public: - String(); - String( const char *s ); - String( const char *s, long iLength ); - String( long iLength ); - String( const String &s ); - String( const QByteArray &s ); - virtual ~String(); - - virtual Object *clone() const; - - virtual Type getType() const { return typeString; } - - virtual void write( QIODevice &rOut ) const; - virtual void read( QIODevice &rIn, char cType ); - - private: - }; + class String : public Gats::Object, public QByteArray + { + Q_OBJECT; + public: + String(); + String( const char *s ); + String( const char *s, long iLength ); + String( long iLength ); + String( const String &s ); + String( const QByteArray &s ); + virtual ~String(); + + virtual Object *clone() const; + + virtual Type getType() const { return typeString; } + + virtual void write( QIODevice &rOut ) const; + virtual void read( QIODevice &rIn, char cType ); + + private: + }; }; //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ); diff --git a/c++-qt/src/types.h b/c++-qt/src/types.h index bd1c8ae..1efdf26 100644 --- a/c++-qt/src/types.h +++ b/c++-qt/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-qt/object.h" #include "gats-qt/boolean.h" #include "gats-qt/dictionary.h" diff --git a/c++-qt/tests/echo/main.cpp b/c++-qt/tests/echo/main.cpp index 43ceae4..4925fc6 100644 --- a/c++-qt/tests/echo/main.cpp +++ b/c++-qt/tests/echo/main.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 #include "mainwnd.h" 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++-qt/tests/echo/mainwnd.cpp b/c++-qt/tests/echo/mainwnd.cpp index 13c93a1..3995720 100644 --- a/c++-qt/tests/echo/mainwnd.cpp +++ b/c++-qt/tests/echo/mainwnd.cpp @@ -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. + */ + #include "mainwnd.h" MainWnd::MainWnd() { - pSrv = new QTcpServer( this ); - connect( pSrv, SIGNAL(newConnection()), this, SLOT(newConnection())); - pSrv->listen( QHostAddress::Any, 7317 ); + pSrv = new QTcpServer( this ); + connect( pSrv, SIGNAL(newConnection()), this, SLOT(newConnection())); + pSrv->listen( QHostAddress::Any, 7317 ); } MainWnd::~MainWnd() @@ -13,24 +20,24 @@ MainWnd::~MainWnd() void MainWnd::newConnection() { - while( pSrv->hasPendingConnections() ) - { - QTcpSocket *pSock = pSrv->nextPendingConnection(); - Gats::GatsStream *pGats = new Gats::GatsStream( *pSock ); - connect( pSock, SIGNAL(readyRead()), pGats, SLOT(readObject()) ); - connect( pGats, SIGNAL(objectRead( Gats::Object * )), - this, SLOT(objectRead( Gats::Object * ))); - } + while( pSrv->hasPendingConnections() ) + { + QTcpSocket *pSock = pSrv->nextPendingConnection(); + Gats::GatsStream *pGats = new Gats::GatsStream( *pSock ); + connect( pSock, SIGNAL(readyRead()), pGats, SLOT(readObject()) ); + connect( pGats, SIGNAL(objectRead( Gats::Object * )), + this, SLOT(objectRead( Gats::Object * ))); + } } void MainWnd::objectRead( Gats::Object *pObj ) { - ((Gats::GatsStream *)sender())->writeObject( pObj ); + ((Gats::GatsStream *)sender())->writeObject( pObj ); - Gats::Object *pCopy = pObj->clone(); - delete pObj; + Gats::Object *pCopy = pObj->clone(); + delete pObj; - ((Gats::GatsStream *)sender())->writeObject( pCopy ); + ((Gats::GatsStream *)sender())->writeObject( pCopy ); - delete pCopy; + delete pCopy; } diff --git a/c++-qt/tests/echo/mainwnd.h b/c++-qt/tests/echo/mainwnd.h index 0afbd6a..71c5c8e 100644 --- a/c++-qt/tests/echo/mainwnd.h +++ b/c++-qt/tests/echo/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. + */ + #include #include @@ -8,16 +15,16 @@ class MainWnd : public QMainWindow { - Q_OBJECT; + Q_OBJECT; public: - QTcpServer *pSrv; + QTcpServer *pSrv; - MainWnd(); - virtual ~MainWnd(); + MainWnd(); + virtual ~MainWnd(); public slots: - void newConnection(); - void objectRead( Gats::Object *pObj ); + void newConnection(); + void objectRead( Gats::Object *pObj ); signals: }; diff --git a/java/FileExample.java b/java/FileExample.java index e0db728..1bfa710 100644 --- a/java/FileExample.java +++ b/java/FileExample.java @@ -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. + */ + import com.xagasoft.gats.*; import java.io.FileInputStream; diff --git a/java/com/xagasoft/gats/GatsBoolean.java b/java/com/xagasoft/gats/GatsBoolean.java index 7e5d217..d54e8de 100644 --- a/java/com/xagasoft/gats/GatsBoolean.java +++ b/java/com/xagasoft/gats/GatsBoolean.java @@ -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. + */ + package com.xagasoft.gats; import java.io.InputStream; diff --git a/java/com/xagasoft/gats/GatsDictionary.java b/java/com/xagasoft/gats/GatsDictionary.java index e359dfa..7909c68 100644 --- a/java/com/xagasoft/gats/GatsDictionary.java +++ b/java/com/xagasoft/gats/GatsDictionary.java @@ -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. + */ + package com.xagasoft.gats; import java.io.InputStream; diff --git a/java/com/xagasoft/gats/GatsFloat.java b/java/com/xagasoft/gats/GatsFloat.java index 3d7583e..4440ea5 100644 --- a/java/com/xagasoft/gats/GatsFloat.java +++ b/java/com/xagasoft/gats/GatsFloat.java @@ -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. + */ + package com.xagasoft.gats; import java.io.InputStream; diff --git a/java/com/xagasoft/gats/GatsInputStream.java b/java/com/xagasoft/gats/GatsInputStream.java index 7d598b4..6502258 100644 --- a/java/com/xagasoft/gats/GatsInputStream.java +++ b/java/com/xagasoft/gats/GatsInputStream.java @@ -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. + */ + package com.xagasoft.gats; import java.io.InputStream; diff --git a/java/com/xagasoft/gats/GatsInteger.java b/java/com/xagasoft/gats/GatsInteger.java index 0ea5122..de8e343 100644 --- a/java/com/xagasoft/gats/GatsInteger.java +++ b/java/com/xagasoft/gats/GatsInteger.java @@ -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. + */ + package com.xagasoft.gats; import java.io.OutputStream; diff --git a/java/com/xagasoft/gats/GatsList.java b/java/com/xagasoft/gats/GatsList.java index 84a9b31..1c3bba8 100644 --- a/java/com/xagasoft/gats/GatsList.java +++ b/java/com/xagasoft/gats/GatsList.java @@ -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. + */ + package com.xagasoft.gats; import java.io.InputStream; diff --git a/java/com/xagasoft/gats/GatsNull.java b/java/com/xagasoft/gats/GatsNull.java index 7919433..370028e 100644 --- a/java/com/xagasoft/gats/GatsNull.java +++ b/java/com/xagasoft/gats/GatsNull.java @@ -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. + */ + package com.xagasoft.gats; import java.io.InputStream; diff --git a/java/com/xagasoft/gats/GatsObject.java b/java/com/xagasoft/gats/GatsObject.java index e26ab7b..df489aa 100644 --- a/java/com/xagasoft/gats/GatsObject.java +++ b/java/com/xagasoft/gats/GatsObject.java @@ -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. + */ + package com.xagasoft.gats; import java.io.InputStream; diff --git a/java/com/xagasoft/gats/GatsOutputStream.java b/java/com/xagasoft/gats/GatsOutputStream.java index c71491b..2a20d99 100644 --- a/java/com/xagasoft/gats/GatsOutputStream.java +++ b/java/com/xagasoft/gats/GatsOutputStream.java @@ -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. + */ + package com.xagasoft.gats; import java.io.OutputStream; diff --git a/java/com/xagasoft/gats/GatsString.java b/java/com/xagasoft/gats/GatsString.java index 8e5c5c0..442ef67 100644 --- a/java/com/xagasoft/gats/GatsString.java +++ b/java/com/xagasoft/gats/GatsString.java @@ -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. + */ + package com.xagasoft.gats; import java.io.InputStream; diff --git a/java/com/xagasoft/gats/KeyNotFoundException.java b/java/com/xagasoft/gats/KeyNotFoundException.java index 49d14e1..ddcde18 100644 --- a/java/com/xagasoft/gats/KeyNotFoundException.java +++ b/java/com/xagasoft/gats/KeyNotFoundException.java @@ -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. + */ + package com.xagasoft.gats; /** diff --git a/java/com/xagasoft/gats/package-info.java b/java/com/xagasoft/gats/package-info.java index 6feb5f1..1792bc5 100644 --- a/java/com/xagasoft/gats/package-info.java +++ b/java/com/xagasoft/gats/package-info.java @@ -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. + */ + /** * The Generalized Agile Transport System. * diff --git a/php/phpgats.php b/php/phpgats.php index 8a16e09..df9b1ba 100644 --- a/php/phpgats.php +++ b/php/phpgats.php @@ -1,4 +1,11 @@