diff options
Diffstat (limited to 'c++-libbu++')
50 files changed, 2116 insertions, 1780 deletions
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"); | |||
| 3 | 3 | ||
| 4 | action "default" | 4 | action "default" |
| 5 | { | 5 | { |
| 6 | build: [targets("header-links"), "libgats.a", "gatsc"]; | 6 | build: [targets("header-links"), "libgats.a", "gatsc"]; |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | action "all" | 9 | action "all" |
| 10 | { | 10 | { |
| 11 | build: [targets("header-links"), "libgats.a", targets("headers"), | 11 | build: [targets("header-links"), "libgats.a", targets("headers"), |
| 12 | targets()]; | 12 | targets()]; |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | action "gatscon" | 15 | action "gatscon" |
| 16 | { | 16 | { |
| 17 | build: [targets("header-links"), "libgats.a", | 17 | build: [targets("header-links"), "libgats.a", |
| 18 | targets("headers"), "gatscon"]; | 18 | targets("headers"), "gatscon"]; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | CXXFLAGS += "-ggdb -Wall"; | 21 | CXXFLAGS += "-ggdb -Wall"; |
| 22 | 22 | ||
| 23 | target [files("src/*.h").replace("src/", "gats/"), "gats/version.h"] | 23 | target [files("src/*.h").replace("src/", "gats/"), "gats/version.h"] |
| 24 | { | 24 | { |
| 25 | tag "header-links"; | 25 | tag "header-links"; |
| 26 | display "symlink"; | 26 | display "symlink"; |
| 27 | input OUTPUT.replace("gats/","src/"); | 27 | input OUTPUT.replace("gats/","src/"); |
| 28 | profile "build" | 28 | profile "build" |
| 29 | { | 29 | { |
| 30 | execute("ln -s ../${INPUT} ${OUTPUT}"); | 30 | execute("ln -s ../${INPUT} ${OUTPUT}"); |
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | target "src/version.h" | 34 | target "src/version.h" |
| 35 | { | 35 | { |
| 36 | input ".svn"; | 36 | input ".svn"; |
| 37 | display "svnver"; | 37 | display "svnver"; |
| 38 | profile "build" | 38 | profile "build" |
| 39 | { | 39 | { |
| 40 | execute("echo Revision number: `svnversion`; echo \\#ifndef LIBGATS_VC_ID > ${OUTPUT}; echo \\#define LIBGATS_VC_ID \\\"`svnversion`\\\" >> ${OUTPUT}; echo \\#endif >> ${OUTPUT}"); | 40 | execute("echo Revision number: `svnversion`; echo \\#ifndef LIBGATS_VC_ID > ${OUTPUT}; echo \\#define LIBGATS_VC_ID \\\"`svnversion`\\\" >> ${OUTPUT}; echo \\#endif >> ${OUTPUT}"); |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | target "libgats.a" | 44 | target "libgats.a" |
| 45 | { | 45 | { |
| 46 | rule "lib"; | 46 | rule "lib"; |
| 47 | input files("src/*.cpp"); | 47 | input files("src/*.cpp"); |
| 48 | CXXFLAGS += "-I. -Ilibbu++ -fPIC"; | 48 | CXXFLAGS += "-I. -Ilibbu++ -fPIC"; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | target "gatsc" | 51 | target "gatsc" |
| 52 | { | 52 | { |
| 53 | rule "exe"; | 53 | rule "exe"; |
| 54 | input files("src/gatsc/*.cpp"); | 54 | input files("src/gatsc/*.cpp"); |
| 55 | CXXFLAGS += "-I. -Ilibbu++"; | 55 | CXXFLAGS += "-I. -Ilibbu++"; |
| 56 | LDFLAGS += "-L. -lgats -lbu++"; | 56 | LDFLAGS += "-L. -lgats -lbu++"; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | target files("src/tests/*.cpp").replace("src/","").replace(".cpp","") | 59 | target files("src/tests/*.cpp").replace("src/","").replace(".cpp","") |
| 60 | { | 60 | { |
| 61 | input "src/${OUTPUT}.cpp"; | 61 | input "src/${OUTPUT}.cpp"; |
| 62 | rule "exe"; | 62 | rule "exe"; |
| 63 | tag ["tests", "general tests"]; | 63 | tag ["tests", "general tests"]; |
| 64 | CXXFLAGS += "-I. -Ilibbu++"; | 64 | CXXFLAGS += "-I. -Ilibbu++"; |
| 65 | LDFLAGS += "-L. -lgats -Llibbu++ -lbu++"; | 65 | LDFLAGS += "-L. -lgats -Llibbu++ -lbu++"; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | target files("src/unit/*.unit").replace("src/","").replace(".unit","") | 68 | target files("src/unit/*.unit").replace("src/","").replace(".unit","") |
| 69 | { | 69 | { |
| 70 | input "src/${OUTPUT}.unit"; | 70 | input "src/${OUTPUT}.unit"; |
| 71 | rule "exe"; | 71 | rule "exe"; |
| 72 | requires "libbu++.a"; | 72 | requires "libbu++.a"; |
| 73 | tag ["tests", "unit tests"]; | 73 | tag ["tests", "unit tests"]; |
| 74 | CXXFLAGS += "-I."; | 74 | CXXFLAGS += "-I."; |
| 75 | LDFLAGS += "-L. -lgats -lbu++"; | 75 | LDFLAGS += "-L. -lgats -lbu++"; |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | rule "unit" | 78 | rule "unit" |
| 79 | { | 79 | { |
| 80 | input "*.unit"; | 80 | input "*.unit"; |
| 81 | output INPUT.replace(".unit", ".cpp"); | 81 | output INPUT.replace(".unit", ".cpp"); |
| 82 | 82 | ||
| 83 | profile "build" | 83 | profile "build" |
| 84 | { | 84 | { |
| 85 | execute("../libbu++/mkunit \"${INPUT}\" \"${OUTPUT}\""); | 85 | execute("../libbu++/mkunit \"${INPUT}\" \"${OUTPUT}\""); |
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | include "qt4.bld"; | 89 | include "qt4.bld"; |
| @@ -95,15 +95,15 @@ UI_DIR = "tmp"; | |||
| 95 | 95 | ||
| 96 | target "gatscon" | 96 | target "gatscon" |
| 97 | { | 97 | { |
| 98 | input files("src/gatscon/*.h", "src/gatscon/*.cpp", "src/gatscon/*.ui"); | 98 | input files("src/gatscon/*.h", "src/gatscon/*.cpp", "src/gatscon/*.ui"); |
| 99 | rule "exe"; | 99 | rule "exe"; |
| 100 | 100 | ||
| 101 | CXXFLAGS += qt_getCXXFLAGS(); | 101 | CXXFLAGS += qt_getCXXFLAGS(); |
| 102 | LDFLAGS += qt_getLDFLAGS(); | 102 | LDFLAGS += qt_getLDFLAGS(); |
| 103 | 103 | ||
| 104 | CXXFLAGS += "-Isrc/gatscon"; | 104 | CXXFLAGS += "-Isrc/gatscon"; |
| 105 | 105 | ||
| 106 | CXXFLAGS += "-I. -Ilibbu++ -Itmp -Ilibzamui/src"; | 106 | CXXFLAGS += "-I. -Ilibbu++ -Itmp -Ilibzamui/src"; |
| 107 | LDFLAGS += "-L. -lgats -Llibbu++ -lbu++ -Llibzamui -lzamui"; | 107 | LDFLAGS += "-L. -lgats -Llibbu++ -lbu++ -Llibzamui -lzamui"; |
| 108 | } | 108 | } |
| 109 | 109 | ||
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"; | |||
| 8 | 8 | ||
| 9 | action "default" | 9 | action "default" |
| 10 | { | 10 | { |
| 11 | build: [targets("header-links"), "libgatswin.a"]; | 11 | build: [targets("header-links"), "libgatswin.a"]; |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | action "gatscon" | 14 | action "gatscon" |
| 15 | { | 15 | { |
| 16 | build: ["gatscon.exe"]; | 16 | build: ["gatscon.exe"]; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | target files("src/*.h").replace("src/", "gats/") | 19 | target files("src/*.h").replace("src/", "gats/") |
| 20 | { | 20 | { |
| 21 | tag "header-links"; | 21 | tag "header-links"; |
| 22 | display "symlink"; | 22 | display "symlink"; |
| 23 | input OUTPUT.replace("gats/","src/"); | 23 | input OUTPUT.replace("gats/","src/"); |
| 24 | profile "build" | 24 | profile "build" |
| 25 | { | 25 | { |
| 26 | execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../${INPUT} ${OUTPUT}"); | 26 | execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../${INPUT} ${OUTPUT}"); |
| 27 | } | 27 | } |
| 28 | } | 28 | } |
| 29 | target files("src/compat/*.h").replace("src/", "gats/") | 29 | target files("src/compat/*.h").replace("src/", "gats/") |
| 30 | { | 30 | { |
| 31 | tag "header-links"; | 31 | tag "header-links"; |
| 32 | display "symlink"; | 32 | display "symlink"; |
| 33 | input OUTPUT.replace("gats/","src/"); | 33 | input OUTPUT.replace("gats/","src/"); |
| 34 | profile "build" | 34 | profile "build" |
| 35 | { | 35 | { |
| 36 | execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../../${INPUT} ${OUTPUT}"); | 36 | execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../../${INPUT} ${OUTPUT}"); |
| 37 | } | 37 | } |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | target "libgatswin.a" | 40 | target "libgatswin.a" |
| 41 | { | 41 | { |
| 42 | input files("src/*.cpp"); | 42 | input files("src/*.cpp"); |
| 43 | rule "lib"; | 43 | rule "lib"; |
| 44 | CXXFLAGS += "-I. -Ilibbu++"; | 44 | CXXFLAGS += "-I. -Ilibbu++"; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | target "gatscon.exe" | 47 | target "gatscon.exe" |
| 48 | { | 48 | { |
| 49 | rule "winexe"; | 49 | rule "winexe"; |
| 50 | tag "exe"; | 50 | tag "exe"; |
| 51 | input files("src/gatscon/*.cpp", "src/gatscon/*.ui", "src/gatscon/*.h", | 51 | input files("src/gatscon/*.cpp", "src/gatscon/*.ui", "src/gatscon/*.h", |
| 52 | "tmp/*.cpp"); | 52 | "tmp/*.cpp"); |
| 53 | 53 | ||
| 54 | 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"; | 54 | 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"; |
| 55 | 55 | ||
| 56 | 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"; | 56 | 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"; |
| 57 | 57 | ||
| 58 | CXXFLAGS += "-ggdb -Itmp"; | 58 | CXXFLAGS += "-ggdb -Itmp"; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | function cppToWinObj() | 61 | function cppToWinObj() |
| 62 | { | 62 | { |
| 63 | if OBJ_DIR == null then | 63 | if OBJ_DIR == null then |
| 64 | { | 64 | { |
| 65 | return INPUT.regex("\\.cpp$", ".win_o"); | 65 | return INPUT.regex("\\.cpp$", ".win_o"); |
| 66 | } | 66 | } |
| 67 | else | 67 | else |
| 68 | { | 68 | { |
| 69 | return OBJ_DIR + "/" + INPUT.fileName().regex("\\.cpp$", ".win_o"); | 69 | return OBJ_DIR + "/" + INPUT.fileName().regex("\\.cpp$", ".win_o"); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | rule "lib" | 74 | rule "lib" |
| 75 | { | 75 | { |
| 76 | input "*.win_o"; | 76 | input "*.win_o"; |
| 77 | profile "build" | 77 | profile "build" |
| 78 | { | 78 | { |
| 79 | execute("wine C:/MinGW/bin/ar.exe cr ${OUTPUT} ${INPUT}"); | 79 | execute("wine C:/MinGW/bin/ar.exe cr ${OUTPUT} ${INPUT}"); |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | rule "wincpp" | 83 | rule "wincpp" |
| 84 | { | 84 | { |
| 85 | input "*.cpp"; | 85 | input "*.cpp"; |
| 86 | output INPUT.cppToWinObj(); | 86 | output INPUT.cppToWinObj(); |
| 87 | //requires getMakeDeps("wine C:/MinGW/bin/g++.exe ${CXXFLAGS} -M ${INPUT}"); | 87 | //requires getMakeDeps("wine C:/MinGW/bin/g++.exe ${CXXFLAGS} -M ${INPUT}"); |
| 88 | profile "build" | 88 | profile "build" |
| 89 | { | 89 | { |
| 90 | execute("wine C:/MinGW/bin/g++.exe ${CXXFLAGS} -c -o ${OUTPUT} ${INPUT}", "g++"); | 90 | execute("wine C:/MinGW/bin/g++.exe ${CXXFLAGS} -c -o ${OUTPUT} ${INPUT}", "g++"); |
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | rule "winexe" | 94 | rule "winexe" |
| 95 | { | 95 | { |
| 96 | input "*.win_o"; | 96 | input "*.win_o"; |
| 97 | profile "build" | 97 | profile "build" |
| 98 | { | 98 | { |
| 99 | if DEBUG != "true" then | 99 | if DEBUG != "true" then |
| 100 | { | 100 | { |
| 101 | LDFLAGS += "-Wl,-s"; | 101 | LDFLAGS += "-Wl,-s"; |
| 102 | } | 102 | } |
| 103 | execute("wine C:/MinGW/bin/mingw32-g++.exe -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); | 103 | execute("wine C:/MinGW/bin/mingw32-g++.exe -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); |
| 104 | } | 104 | } |
| 105 | } | 105 | } |
| 106 | 106 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/boolean.h" | 8 | #include "gats/boolean.h" |
| 2 | 9 | ||
| 3 | #include <bu/formatter.h> | 10 | #include <bu/formatter.h> |
| 4 | #include <bu/stream.h> | 11 | #include <bu/stream.h> |
| 5 | 12 | ||
| 6 | Gats::Boolean::Boolean() : | 13 | Gats::Boolean::Boolean() : |
| 7 | bVal( false ) | 14 | bVal( false ) |
| 8 | { | 15 | { |
| 9 | } | 16 | } |
| 10 | 17 | ||
| 11 | Gats::Boolean::Boolean( bool bVal ) : | 18 | Gats::Boolean::Boolean( bool bVal ) : |
| 12 | bVal( bVal ) | 19 | bVal( bVal ) |
| 13 | { | 20 | { |
| 14 | } | 21 | } |
| 15 | 22 | ||
| @@ -19,35 +26,35 @@ Gats::Boolean::~Boolean() | |||
| 19 | 26 | ||
| 20 | Gats::Object *Gats::Boolean::clone() const | 27 | Gats::Object *Gats::Boolean::clone() const |
| 21 | { | 28 | { |
| 22 | return new Gats::Boolean( bVal ); | 29 | return new Gats::Boolean( bVal ); |
| 23 | } | 30 | } |
| 24 | 31 | ||
| 25 | void Gats::Boolean::write( Bu::Stream &rOut ) const | 32 | void Gats::Boolean::write( Bu::Stream &rOut ) const |
| 26 | { | 33 | { |
| 27 | if( bVal ) | 34 | if( bVal ) |
| 28 | { | 35 | { |
| 29 | rOut.write("1", 1 ); | 36 | rOut.write("1", 1 ); |
| 30 | } | 37 | } |
| 31 | else | 38 | else |
| 32 | { | 39 | { |
| 33 | rOut.write("0", 1 ); | 40 | rOut.write("0", 1 ); |
| 34 | } | 41 | } |
| 35 | } | 42 | } |
| 36 | 43 | ||
| 37 | void Gats::Boolean::read( Bu::Stream &rIn, char cType ) | 44 | void Gats::Boolean::read( Bu::Stream &rIn, char cType ) |
| 38 | { | 45 | { |
| 39 | if( cType == '1' ) | 46 | if( cType == '1' ) |
| 40 | { | 47 | { |
| 41 | bVal = true; | 48 | bVal = true; |
| 42 | } | 49 | } |
| 43 | else | 50 | else |
| 44 | { | 51 | { |
| 45 | bVal = false; | 52 | bVal = false; |
| 46 | } | 53 | } |
| 47 | } | 54 | } |
| 48 | 55 | ||
| 49 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ) | 56 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ) |
| 50 | { | 57 | { |
| 51 | return f << "(bool) " << b.getValue(); | 58 | return f << "(bool) " << b.getValue(); |
| 52 | } | 59 | } |
| 53 | 60 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef GATS_BOOLEAN_H | 8 | #ifndef GATS_BOOLEAN_H |
| 2 | #define GATS_BOOLEAN_H | 9 | #define GATS_BOOLEAN_H |
| 3 | 10 | ||
| @@ -5,24 +12,24 @@ | |||
| 5 | 12 | ||
| 6 | namespace Gats | 13 | namespace Gats |
| 7 | { | 14 | { |
| 8 | class Boolean : public Gats::Object | 15 | class Boolean : public Gats::Object |
| 9 | { | 16 | { |
| 10 | public: | 17 | public: |
| 11 | Boolean(); | 18 | Boolean(); |
| 12 | Boolean( bool bVal ); | 19 | Boolean( bool bVal ); |
| 13 | virtual ~Boolean(); | 20 | virtual ~Boolean(); |
| 14 | 21 | ||
| 15 | virtual Type getType() const { return typeBoolean; } | 22 | virtual Type getType() const { return typeBoolean; } |
| 16 | bool getValue() const { return bVal; } | 23 | bool getValue() const { return bVal; } |
| 17 | void setValue( bool b ) { bVal = b; } | 24 | void setValue( bool b ) { bVal = b; } |
| 18 | virtual Object *clone() const; | 25 | virtual Object *clone() const; |
| 19 | 26 | ||
| 20 | virtual void write( Bu::Stream &rOut ) const; | 27 | virtual void write( Bu::Stream &rOut ) const; |
| 21 | virtual void read( Bu::Stream &rIn, char cType ); | 28 | virtual void read( Bu::Stream &rIn, char cType ); |
| 22 | 29 | ||
| 23 | private: | 30 | private: |
| 24 | bool bVal; | 31 | bool bVal; |
| 25 | }; | 32 | }; |
| 26 | }; | 33 | }; |
| 27 | 34 | ||
| 28 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ); | 35 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/dictionary.h" | 8 | #include "gats/dictionary.h" |
| 2 | 9 | ||
| 3 | #include "gats/boolean.h" | 10 | #include "gats/boolean.h" |
| @@ -11,7 +18,7 @@ | |||
| 11 | template<> | 18 | template<> |
| 12 | uint32_t Bu::__calcHashCode<Gats::String>( const Gats::String &s ) | 19 | uint32_t Bu::__calcHashCode<Gats::String>( const Gats::String &s ) |
| 13 | { | 20 | { |
| 14 | return __calcHashCode( dynamic_cast<const Bu::String &>(s) ); | 21 | return __calcHashCode( dynamic_cast<const Bu::String &>(s) ); |
| 15 | } | 22 | } |
| 16 | 23 | ||
| 17 | Gats::Dictionary::Dictionary() | 24 | Gats::Dictionary::Dictionary() |
| @@ -20,361 +27,361 @@ Gats::Dictionary::Dictionary() | |||
| 20 | 27 | ||
| 21 | Gats::Dictionary::~Dictionary() | 28 | Gats::Dictionary::~Dictionary() |
| 22 | { | 29 | { |
| 23 | for( iterator i = begin(); i; i++ ) | 30 | for( iterator i = begin(); i; i++ ) |
| 24 | { | 31 | { |
| 25 | delete *i; | 32 | delete *i; |
| 26 | } | 33 | } |
| 27 | } | 34 | } |
| 28 | 35 | ||
| 29 | Gats::Object *Gats::Dictionary::clone() const | 36 | Gats::Object *Gats::Dictionary::clone() const |
| 30 | { | 37 | { |
| 31 | Gats::Dictionary *pClone = new Gats::Dictionary; | 38 | Gats::Dictionary *pClone = new Gats::Dictionary; |
| 32 | for( const_iterator i = begin(); i; i++ ) | 39 | for( const_iterator i = begin(); i; i++ ) |
| 33 | { | 40 | { |
| 34 | Bu::String s(i.getKey()); | 41 | Bu::String s(i.getKey()); |
| 35 | pClone->insert( s.clone(), (*i)->clone() ); | 42 | pClone->insert( s.clone(), (*i)->clone() ); |
| 36 | } | 43 | } |
| 37 | 44 | ||
| 38 | return pClone; | 45 | return pClone; |
| 39 | } | 46 | } |
| 40 | 47 | ||
| 41 | void Gats::Dictionary::write( Bu::Stream &rOut ) const | 48 | void Gats::Dictionary::write( Bu::Stream &rOut ) const |
| 42 | { | 49 | { |
| 43 | rOut.write("d", 1 ); | 50 | rOut.write("d", 1 ); |
| 44 | for( const_iterator i= begin(); i; i++ ) | 51 | for( const_iterator i= begin(); i; i++ ) |
| 45 | { | 52 | { |
| 46 | i.getKey().write( rOut ); | 53 | i.getKey().write( rOut ); |
| 47 | (*i)->write( rOut ); | 54 | (*i)->write( rOut ); |
| 48 | } | 55 | } |
| 49 | rOut.write("e", 1 ); | 56 | rOut.write("e", 1 ); |
| 50 | } | 57 | } |
| 51 | 58 | ||
| 52 | void Gats::Dictionary::read( Bu::Stream &rIn, char cType ) | 59 | void Gats::Dictionary::read( Bu::Stream &rIn, char cType ) |
| 53 | { | 60 | { |
| 54 | for(;;) | 61 | for(;;) |
| 55 | { | 62 | { |
| 56 | char cNext; | 63 | char cNext; |
| 57 | rIn.read( &cNext, 1 ); | 64 | rIn.read( &cNext, 1 ); |
| 58 | if( cNext == 'e' ) | 65 | if( cNext == 'e' ) |
| 59 | break; | 66 | break; |
| 60 | if( cNext != 's' ) | 67 | if( cNext != 's' ) |
| 61 | throw Bu::ExceptionBase("You can only use strings as keys."); | 68 | throw Bu::ExceptionBase("You can only use strings as keys."); |
| 62 | Gats::String sKey; | 69 | Gats::String sKey; |
| 63 | sKey.read( rIn, cNext ); | 70 | sKey.read( rIn, cNext ); |
| 64 | 71 | ||
| 65 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 72 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 66 | sKey, Gats::Object::read( rIn ) | 73 | sKey, Gats::Object::read( rIn ) |
| 67 | ); | 74 | ); |
| 68 | } | 75 | } |
| 69 | } | 76 | } |
| 70 | 77 | ||
| 71 | void Gats::Dictionary::insert( const Bu::String &sKey, char i ) | 78 | void Gats::Dictionary::insert( const Bu::String &sKey, char i ) |
| 72 | { | 79 | { |
| 73 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 80 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 74 | sKey, new Gats::Integer( i ) | 81 | sKey, new Gats::Integer( i ) |
| 75 | ); | 82 | ); |
| 76 | } | 83 | } |
| 77 | 84 | ||
| 78 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned char i ) | 85 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned char i ) |
| 79 | { | 86 | { |
| 80 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 87 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 81 | sKey, new Gats::Integer( i ) | 88 | sKey, new Gats::Integer( i ) |
| 82 | ); | 89 | ); |
| 83 | } | 90 | } |
| 84 | 91 | ||
| 85 | void Gats::Dictionary::insert( const Bu::String &sKey, signed char i ) | 92 | void Gats::Dictionary::insert( const Bu::String &sKey, signed char i ) |
| 86 | { | 93 | { |
| 87 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 94 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 88 | sKey, new Gats::Integer( i ) | 95 | sKey, new Gats::Integer( i ) |
| 89 | ); | 96 | ); |
| 90 | } | 97 | } |
| 91 | 98 | ||
| 92 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned short i ) | 99 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned short i ) |
| 93 | { | 100 | { |
| 94 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 101 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 95 | sKey, new Gats::Integer( i ) | 102 | sKey, new Gats::Integer( i ) |
| 96 | ); | 103 | ); |
| 97 | } | 104 | } |
| 98 | 105 | ||
| 99 | void Gats::Dictionary::insert( const Bu::String &sKey, signed short i ) | 106 | void Gats::Dictionary::insert( const Bu::String &sKey, signed short i ) |
| 100 | { | 107 | { |
| 101 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 108 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 102 | sKey, new Gats::Integer( i ) | 109 | sKey, new Gats::Integer( i ) |
| 103 | ); | 110 | ); |
| 104 | } | 111 | } |
| 105 | 112 | ||
| 106 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned int i ) | 113 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned int i ) |
| 107 | { | 114 | { |
| 108 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 115 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 109 | sKey, new Gats::Integer( i ) | 116 | sKey, new Gats::Integer( i ) |
| 110 | ); | 117 | ); |
| 111 | } | 118 | } |
| 112 | 119 | ||
| 113 | void Gats::Dictionary::insert( const Bu::String &sKey, signed int i ) | 120 | void Gats::Dictionary::insert( const Bu::String &sKey, signed int i ) |
| 114 | { | 121 | { |
| 115 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 122 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 116 | sKey, new Gats::Integer( i ) | 123 | sKey, new Gats::Integer( i ) |
| 117 | ); | 124 | ); |
| 118 | } | 125 | } |
| 119 | 126 | ||
| 120 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned long i ) | 127 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned long i ) |
| 121 | { | 128 | { |
| 122 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 129 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 123 | sKey, new Gats::Integer( i ) | 130 | sKey, new Gats::Integer( i ) |
| 124 | ); | 131 | ); |
| 125 | } | 132 | } |
| 126 | 133 | ||
| 127 | void Gats::Dictionary::insert( const Bu::String &sKey, signed long i ) | 134 | void Gats::Dictionary::insert( const Bu::String &sKey, signed long i ) |
| 128 | { | 135 | { |
| 129 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 136 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 130 | sKey, new Gats::Integer( i ) | 137 | sKey, new Gats::Integer( i ) |
| 131 | ); | 138 | ); |
| 132 | } | 139 | } |
| 133 | 140 | ||
| 134 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned long long i ) | 141 | void Gats::Dictionary::insert( const Bu::String &sKey, unsigned long long i ) |
| 135 | { | 142 | { |
| 136 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 143 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 137 | sKey, new Gats::Integer( i ) | 144 | sKey, new Gats::Integer( i ) |
| 138 | ); | 145 | ); |
| 139 | } | 146 | } |
| 140 | 147 | ||
| 141 | void Gats::Dictionary::insert( const Bu::String &sKey, signed long long i ) | 148 | void Gats::Dictionary::insert( const Bu::String &sKey, signed long long i ) |
| 142 | { | 149 | { |
| 143 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( | 150 | ((Bu::Hash<Gats::String, Gats::Object *> *)this)->insert( |
| 144 | sKey, new Gats::Integer( i ) | 151 | sKey, new Gats::Integer( i ) |
| 145 | ); | 152 | ); |
| 146 | } | 153 | } |
| 147 | /* | 154 | /* |
| 148 | void Gats::Dictionary::insert( const Bu::String &sKey, bool b ) | 155 | void Gats::Dictionary::insert( const Bu::String &sKey, bool b ) |
| 149 | { | 156 | { |
| 150 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 157 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
| 151 | sKey, new Gats::Boolean( b ) | 158 | sKey, new Gats::Boolean( b ) |
| 152 | ); | 159 | ); |
| 153 | }*/ | 160 | }*/ |
| 154 | 161 | ||
| 155 | void Gats::Dictionary::insert( const Bu::String &sKey, float d ) | 162 | void Gats::Dictionary::insert( const Bu::String &sKey, float d ) |
| 156 | { | 163 | { |
| 157 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 164 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
| 158 | sKey, new Gats::Float( d ) | 165 | sKey, new Gats::Float( d ) |
| 159 | ); | 166 | ); |
| 160 | } | 167 | } |
| 161 | 168 | ||
| 162 | void Gats::Dictionary::insert( const Bu::String &sKey, double d ) | 169 | void Gats::Dictionary::insert( const Bu::String &sKey, double d ) |
| 163 | { | 170 | { |
| 164 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 171 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
| 165 | sKey, new Gats::Float( d ) | 172 | sKey, new Gats::Float( d ) |
| 166 | ); | 173 | ); |
| 167 | } | 174 | } |
| 168 | 175 | ||
| 169 | void Gats::Dictionary::insert( const Bu::String &sKey, const char *s ) | 176 | void Gats::Dictionary::insert( const Bu::String &sKey, const char *s ) |
| 170 | { | 177 | { |
| 171 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 178 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
| 172 | sKey, new Gats::String( s ) | 179 | sKey, new Gats::String( s ) |
| 173 | ); | 180 | ); |
| 174 | } | 181 | } |
| 175 | 182 | ||
| 176 | void Gats::Dictionary::insert( const Bu::String &sKey, const Bu::String &s ) | 183 | void Gats::Dictionary::insert( const Bu::String &sKey, const Bu::String &s ) |
| 177 | { | 184 | { |
| 178 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 185 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
| 179 | sKey, new Gats::String( s ) | 186 | sKey, new Gats::String( s ) |
| 180 | ); | 187 | ); |
| 181 | } | 188 | } |
| 182 | 189 | ||
| 183 | void Gats::Dictionary::insertBool( const Bu::String &sKey, bool b ) | 190 | void Gats::Dictionary::insertBool( const Bu::String &sKey, bool b ) |
| 184 | { | 191 | { |
| 185 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 192 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
| 186 | sKey, new Gats::Boolean( b ) | 193 | sKey, new Gats::Boolean( b ) |
| 187 | ); | 194 | ); |
| 188 | } | 195 | } |
| 189 | 196 | ||
| 190 | void Gats::Dictionary::insertInt( const Bu::String &sKey, int64_t i ) | 197 | void Gats::Dictionary::insertInt( const Bu::String &sKey, int64_t i ) |
| 191 | { | 198 | { |
| 192 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 199 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
| 193 | sKey, new Gats::Integer( i ) | 200 | sKey, new Gats::Integer( i ) |
| 194 | ); | 201 | ); |
| 195 | } | 202 | } |
| 196 | 203 | ||
| 197 | void Gats::Dictionary::insertFloat( const Bu::String &sKey, double d ) | 204 | void Gats::Dictionary::insertFloat( const Bu::String &sKey, double d ) |
| 198 | { | 205 | { |
| 199 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 206 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
| 200 | sKey, new Gats::Float( d ) | 207 | sKey, new Gats::Float( d ) |
| 201 | ); | 208 | ); |
| 202 | } | 209 | } |
| 203 | 210 | ||
| 204 | void Gats::Dictionary::insertStr( const Bu::String &sKey, const Bu::String &s ) | 211 | void Gats::Dictionary::insertStr( const Bu::String &sKey, const Bu::String &s ) |
| 205 | { | 212 | { |
| 206 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 213 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
| 207 | sKey, new Gats::String( s ) | 214 | sKey, new Gats::String( s ) |
| 208 | ); | 215 | ); |
| 209 | } | 216 | } |
| 210 | 217 | ||
| 211 | void Gats::Dictionary::insertList( const Bu::String &sKey, Gats::List *pL ) | 218 | void Gats::Dictionary::insertList( const Bu::String &sKey, Gats::List *pL ) |
| 212 | { | 219 | { |
| 213 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 220 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
| 214 | sKey, pL | 221 | sKey, pL |
| 215 | ); | 222 | ); |
| 216 | } | 223 | } |
| 217 | 224 | ||
| 218 | void Gats::Dictionary::insertDict( const Bu::String &sKey, | 225 | void Gats::Dictionary::insertDict( const Bu::String &sKey, |
| 219 | Gats::Dictionary *pD ) | 226 | Gats::Dictionary *pD ) |
| 220 | { | 227 | { |
| 221 | Bu::Hash<Gats::String, Gats::Object *>::insert( | 228 | Bu::Hash<Gats::String, Gats::Object *>::insert( |
| 222 | sKey, pD | 229 | sKey, pD |
| 223 | ); | 230 | ); |
| 224 | } | 231 | } |
| 225 | 232 | ||
| 226 | Gats::List *Gats::Dictionary::insertList( const Bu::String &sKey ) | 233 | Gats::List *Gats::Dictionary::insertList( const Bu::String &sKey ) |
| 227 | { | 234 | { |
| 228 | Gats::List *pLst = new Gats::List(); | 235 | Gats::List *pLst = new Gats::List(); |
| 229 | insertList( sKey, pLst ); | 236 | insertList( sKey, pLst ); |
| 230 | return pLst; | 237 | return pLst; |
| 231 | } | 238 | } |
| 232 | 239 | ||
| 233 | Gats::Dictionary *Gats::Dictionary::insertDict( const Bu::String &sKey ) | 240 | Gats::Dictionary *Gats::Dictionary::insertDict( const Bu::String &sKey ) |
| 234 | { | 241 | { |
| 235 | Gats::Dictionary *pDict = new Gats::Dictionary(); | 242 | Gats::Dictionary *pDict = new Gats::Dictionary(); |
| 236 | insertDict( sKey, pDict ); | 243 | insertDict( sKey, pDict ); |
| 237 | return pDict; | 244 | return pDict; |
| 238 | } | 245 | } |
| 239 | 246 | ||
| 240 | bool Gats::Dictionary::getBool( const Bu::String &sKey ) | 247 | bool Gats::Dictionary::getBool( const Bu::String &sKey ) |
| 241 | { | 248 | { |
| 242 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); | 249 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); |
| 243 | if( !pOb ) | 250 | if( !pOb ) |
| 244 | throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", | 251 | throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", |
| 245 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 252 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 246 | 253 | ||
| 247 | return pOb->getValue(); | 254 | return pOb->getValue(); |
| 248 | } | 255 | } |
| 249 | 256 | ||
| 250 | int64_t Gats::Dictionary::getInt( const Bu::String &sKey ) | 257 | int64_t Gats::Dictionary::getInt( const Bu::String &sKey ) |
| 251 | { | 258 | { |
| 252 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); | 259 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); |
| 253 | if( !pOb ) | 260 | if( !pOb ) |
| 254 | throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", | 261 | throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", |
| 255 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 262 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 256 | 263 | ||
| 257 | return pOb->getValue(); | 264 | return pOb->getValue(); |
| 258 | } | 265 | } |
| 259 | 266 | ||
| 260 | double Gats::Dictionary::getFloat( const Bu::String &sKey ) | 267 | double Gats::Dictionary::getFloat( const Bu::String &sKey ) |
| 261 | { | 268 | { |
| 262 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); | 269 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); |
| 263 | if( !pOb ) | 270 | if( !pOb ) |
| 264 | throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", | 271 | throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", |
| 265 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 272 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 266 | 273 | ||
| 267 | return pOb->getValue(); | 274 | return pOb->getValue(); |
| 268 | } | 275 | } |
| 269 | 276 | ||
| 270 | Bu::String Gats::Dictionary::getStr( const Bu::String &sKey ) | 277 | Bu::String Gats::Dictionary::getStr( const Bu::String &sKey ) |
| 271 | { | 278 | { |
| 272 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); | 279 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); |
| 273 | if( !pOb ) | 280 | if( !pOb ) |
| 274 | throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", | 281 | throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", |
| 275 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 282 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 276 | 283 | ||
| 277 | return *pOb; | 284 | return *pOb; |
| 278 | } | 285 | } |
| 279 | 286 | ||
| 280 | Gats::List *Gats::Dictionary::getList( const Bu::String &sKey ) | 287 | Gats::List *Gats::Dictionary::getList( const Bu::String &sKey ) |
| 281 | { | 288 | { |
| 282 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); | 289 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); |
| 283 | if( !pOb ) | 290 | if( !pOb ) |
| 284 | throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", | 291 | throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", |
| 285 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 292 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 286 | 293 | ||
| 287 | return pOb; | 294 | return pOb; |
| 288 | } | 295 | } |
| 289 | 296 | ||
| 290 | Gats::Dictionary *Gats::Dictionary::getDict( const Bu::String &sKey ) | 297 | Gats::Dictionary *Gats::Dictionary::getDict( const Bu::String &sKey ) |
| 291 | { | 298 | { |
| 292 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); | 299 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); |
| 293 | if( !pOb ) | 300 | if( !pOb ) |
| 294 | throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", | 301 | throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", |
| 295 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 302 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 296 | 303 | ||
| 297 | return pOb; | 304 | return pOb; |
| 298 | } | 305 | } |
| 299 | 306 | ||
| 300 | bool Gats::Dictionary::getBool( const Bu::String &sKey ) const | 307 | bool Gats::Dictionary::getBool( const Bu::String &sKey ) const |
| 301 | { | 308 | { |
| 302 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); | 309 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); |
| 303 | if( !pOb ) | 310 | if( !pOb ) |
| 304 | throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", | 311 | throw Bu::ExceptionBase("Cannot use %s item '%s' as bool.", |
| 305 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 312 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 306 | 313 | ||
| 307 | return pOb->getValue(); | 314 | return pOb->getValue(); |
| 308 | } | 315 | } |
| 309 | 316 | ||
| 310 | int64_t Gats::Dictionary::getInt( const Bu::String &sKey ) const | 317 | int64_t Gats::Dictionary::getInt( const Bu::String &sKey ) const |
| 311 | { | 318 | { |
| 312 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); | 319 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) ); |
| 313 | if( !pOb ) | 320 | if( !pOb ) |
| 314 | throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", | 321 | throw Bu::ExceptionBase("Cannot use %s item '%s' as int.", |
| 315 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 322 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 316 | 323 | ||
| 317 | return pOb->getValue(); | 324 | return pOb->getValue(); |
| 318 | } | 325 | } |
| 319 | 326 | ||
| 320 | double Gats::Dictionary::getFloat( const Bu::String &sKey ) const | 327 | double Gats::Dictionary::getFloat( const Bu::String &sKey ) const |
| 321 | { | 328 | { |
| 322 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); | 329 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( get( sKey ) ); |
| 323 | if( !pOb ) | 330 | if( !pOb ) |
| 324 | throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", | 331 | throw Bu::ExceptionBase("Cannot use %s item '%s' as float.", |
| 325 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 332 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 326 | 333 | ||
| 327 | return pOb->getValue(); | 334 | return pOb->getValue(); |
| 328 | } | 335 | } |
| 329 | 336 | ||
| 330 | Bu::String Gats::Dictionary::getStr( const Bu::String &sKey ) const | 337 | Bu::String Gats::Dictionary::getStr( const Bu::String &sKey ) const |
| 331 | { | 338 | { |
| 332 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); | 339 | Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) ); |
| 333 | if( !pOb ) | 340 | if( !pOb ) |
| 334 | throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", | 341 | throw Bu::ExceptionBase("Cannot use %s item '%s' as string.", |
| 335 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 342 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 336 | 343 | ||
| 337 | return *pOb; | 344 | return *pOb; |
| 338 | } | 345 | } |
| 339 | 346 | ||
| 340 | Gats::List *Gats::Dictionary::getList( const Bu::String &sKey ) const | 347 | Gats::List *Gats::Dictionary::getList( const Bu::String &sKey ) const |
| 341 | { | 348 | { |
| 342 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); | 349 | Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) ); |
| 343 | if( !pOb ) | 350 | if( !pOb ) |
| 344 | throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", | 351 | throw Bu::ExceptionBase("Cannot use %s item '%s' as list.", |
| 345 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 352 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 346 | 353 | ||
| 347 | return pOb; | 354 | return pOb; |
| 348 | } | 355 | } |
| 349 | 356 | ||
| 350 | Gats::Dictionary *Gats::Dictionary::getDict( const Bu::String &sKey ) const | 357 | Gats::Dictionary *Gats::Dictionary::getDict( const Bu::String &sKey ) const |
| 351 | { | 358 | { |
| 352 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); | 359 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) ); |
| 353 | if( !pOb ) | 360 | if( !pOb ) |
| 354 | throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", | 361 | throw Bu::ExceptionBase("Cannot use %s item '%s' as dictionary.", |
| 355 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); | 362 | typeToStr( get( sKey )->getType() ), sKey.getStr() ); |
| 356 | 363 | ||
| 357 | return pOb; | 364 | return pOb; |
| 358 | } | 365 | } |
| 359 | 366 | ||
| 360 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ) | 367 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ) |
| 361 | { | 368 | { |
| 362 | f << "(dict) {"; | 369 | f << "(dict) {"; |
| 363 | f.incIndent(); | 370 | f.incIndent(); |
| 364 | int iMax = 0; | 371 | int iMax = 0; |
| 365 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) | 372 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) |
| 366 | { | 373 | { |
| 367 | if( i.getKey().getSize() > iMax ) | 374 | if( i.getKey().getSize() > iMax ) |
| 368 | iMax = i.getKey().getSize(); | 375 | iMax = i.getKey().getSize(); |
| 369 | } | 376 | } |
| 370 | iMax += 2; | 377 | iMax += 2; |
| 371 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) | 378 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) |
| 372 | { | 379 | { |
| 373 | f << f.nl << Bu::Fmt( iMax ) << i.getKey() + ": " << *i.getValue(); | 380 | f << f.nl << Bu::Fmt( iMax ) << i.getKey() + ": " << *i.getValue(); |
| 374 | } | 381 | } |
| 375 | f.decIndent(); | 382 | f.decIndent(); |
| 376 | f << f.nl << "}"; | 383 | f << f.nl << "}"; |
| 377 | 384 | ||
| 378 | return f; | 385 | return f; |
| 379 | } | 386 | } |
| 380 | 387 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef GATS_DICTIONARY_H | 8 | #ifndef GATS_DICTIONARY_H |
| 2 | #define GATS_DICTIONARY_H | 9 | #define GATS_DICTIONARY_H |
| 3 | 10 | ||
| @@ -7,60 +14,60 @@ | |||
| 7 | 14 | ||
| 8 | namespace Gats | 15 | namespace Gats |
| 9 | { | 16 | { |
| 10 | class List; | 17 | class List; |
| 11 | 18 | ||
| 12 | class Dictionary : public Gats::Object, | 19 | class Dictionary : public Gats::Object, |
| 13 | public Bu::Hash<Gats::String, Gats::Object *> | 20 | public Bu::Hash<Gats::String, Gats::Object *> |
| 14 | { | 21 | { |
| 15 | public: | 22 | public: |
| 16 | Dictionary(); | 23 | Dictionary(); |
| 17 | virtual ~Dictionary(); | 24 | virtual ~Dictionary(); |
| 18 | 25 | ||
| 19 | virtual Type getType() const { return typeDictionary; } | 26 | virtual Type getType() const { return typeDictionary; } |
| 20 | virtual Object *clone() const; | 27 | virtual Object *clone() const; |
| 21 | virtual void write( Bu::Stream &rOut ) const; | 28 | virtual void write( Bu::Stream &rOut ) const; |
| 22 | virtual void read( Bu::Stream &rIn, char cType ); | 29 | virtual void read( Bu::Stream &rIn, char cType ); |
| 23 | 30 | ||
| 24 | void insert( const Bu::String &sKey, const char *s ); | 31 | void insert( const Bu::String &sKey, const char *s ); |
| 25 | void insert( const Bu::String &sKey, const Bu::String &s ); | 32 | void insert( const Bu::String &sKey, const Bu::String &s ); |
| 26 | void insert( const Bu::String &sKey, char i ); | 33 | void insert( const Bu::String &sKey, char i ); |
| 27 | void insert( const Bu::String &sKey, unsigned char i ); | 34 | void insert( const Bu::String &sKey, unsigned char i ); |
| 28 | void insert( const Bu::String &sKey, signed char i ); | 35 | void insert( const Bu::String &sKey, signed char i ); |
| 29 | void insert( const Bu::String &sKey, unsigned short i ); | 36 | void insert( const Bu::String &sKey, unsigned short i ); |
| 30 | void insert( const Bu::String &sKey, signed short i ); | 37 | void insert( const Bu::String &sKey, signed short i ); |
| 31 | void insert( const Bu::String &sKey, unsigned int i ); | 38 | void insert( const Bu::String &sKey, unsigned int i ); |
| 32 | void insert( const Bu::String &sKey, signed int i ); | 39 | void insert( const Bu::String &sKey, signed int i ); |
| 33 | void insert( const Bu::String &sKey, unsigned long i ); | 40 | void insert( const Bu::String &sKey, unsigned long i ); |
| 34 | void insert( const Bu::String &sKey, signed long i ); | 41 | void insert( const Bu::String &sKey, signed long i ); |
| 35 | void insert( const Bu::String &sKey, unsigned long long i ); | 42 | void insert( const Bu::String &sKey, unsigned long long i ); |
| 36 | void insert( const Bu::String &sKey, signed long long i ); | 43 | void insert( const Bu::String &sKey, signed long long i ); |
| 37 | //void insert( const Bu::String &sKey, bool b ); | 44 | //void insert( const Bu::String &sKey, bool b ); |
| 38 | void insert( const Bu::String &sKey, float d ); | 45 | void insert( const Bu::String &sKey, float d ); |
| 39 | void insert( const Bu::String &sKey, double d ); | 46 | void insert( const Bu::String &sKey, double d ); |
| 40 | using Bu::Hash<Gats::String, Gats::Object *>::insert; | 47 | using Bu::Hash<Gats::String, Gats::Object *>::insert; |
| 41 | void insertBool( const Bu::String &sKey, bool b ); | 48 | void insertBool( const Bu::String &sKey, bool b ); |
| 42 | void insertInt( const Bu::String &sKey, int64_t i ); | 49 | void insertInt( const Bu::String &sKey, int64_t i ); |
| 43 | void insertFloat( const Bu::String &sKey, double d ); | 50 | void insertFloat( const Bu::String &sKey, double d ); |
| 44 | void insertStr( const Bu::String &sKey, const Bu::String &s ); | 51 | void insertStr( const Bu::String &sKey, const Bu::String &s ); |
| 45 | void insertList( const Bu::String &sKey, Gats::List *pL ); | 52 | void insertList( const Bu::String &sKey, Gats::List *pL ); |
| 46 | void insertDict( const Bu::String &sKey, Gats::Dictionary *pD ); | 53 | void insertDict( const Bu::String &sKey, Gats::Dictionary *pD ); |
| 47 | Gats::List *insertList( const Bu::String &sKey ); | 54 | Gats::List *insertList( const Bu::String &sKey ); |
| 48 | Gats::Dictionary *insertDict( const Bu::String &sKey ); | 55 | Gats::Dictionary *insertDict( const Bu::String &sKey ); |
| 49 | 56 | ||
| 50 | bool getBool( const Bu::String &sKey ); | 57 | bool getBool( const Bu::String &sKey ); |
| 51 | int64_t getInt( const Bu::String &sKey ); | 58 | int64_t getInt( const Bu::String &sKey ); |
| 52 | double getFloat( const Bu::String &sKey ); | 59 | double getFloat( const Bu::String &sKey ); |
| 53 | Bu::String getStr( const Bu::String &sKey ); | 60 | Bu::String getStr( const Bu::String &sKey ); |
| 54 | Gats::List *getList( const Bu::String &sKey ); | 61 | Gats::List *getList( const Bu::String &sKey ); |
| 55 | Gats::Dictionary *getDict( const Bu::String &sKey ); | 62 | Gats::Dictionary *getDict( const Bu::String &sKey ); |
| 56 | 63 | ||
| 57 | bool getBool( const Bu::String &sKey ) const; | 64 | bool getBool( const Bu::String &sKey ) const; |
| 58 | int64_t getInt( const Bu::String &sKey ) const; | 65 | int64_t getInt( const Bu::String &sKey ) const; |
| 59 | double getFloat( const Bu::String &sKey ) const; | 66 | double getFloat( const Bu::String &sKey ) const; |
| 60 | Bu::String getStr( const Bu::String &sKey ) const; | 67 | Bu::String getStr( const Bu::String &sKey ) const; |
| 61 | Gats::List *getList( const Bu::String &sKey ) const; | 68 | Gats::List *getList( const Bu::String &sKey ) const; |
| 62 | Gats::Dictionary *getDict( const Bu::String &sKey ) const; | 69 | Gats::Dictionary *getDict( const Bu::String &sKey ) const; |
| 63 | }; | 70 | }; |
| 64 | }; | 71 | }; |
| 65 | 72 | ||
| 66 | namespace Bu | 73 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/float.h" | 8 | #include "gats/float.h" |
| 2 | #include "gats/integer.h" | 9 | #include "gats/integer.h" |
| 3 | 10 | ||
| @@ -7,12 +14,12 @@ | |||
| 7 | #include <bu/sio.h> | 14 | #include <bu/sio.h> |
| 8 | using namespace Bu; | 15 | using namespace Bu; |
| 9 | Gats::Float::Float() : | 16 | Gats::Float::Float() : |
| 10 | fVal( 0.0 ) | 17 | fVal( 0.0 ) |
| 11 | { | 18 | { |
| 12 | } | 19 | } |
| 13 | 20 | ||
| 14 | Gats::Float::Float( double f ) : | 21 | Gats::Float::Float( double f ) : |
| 15 | fVal( f ) | 22 | fVal( f ) |
| 16 | { | 23 | { |
| 17 | } | 24 | } |
| 18 | 25 | ||
| @@ -22,109 +29,109 @@ Gats::Float::~Float() | |||
| 22 | 29 | ||
| 23 | Gats::Object *Gats::Float::clone() const | 30 | Gats::Object *Gats::Float::clone() const |
| 24 | { | 31 | { |
| 25 | return new Gats::Float( fVal ); | 32 | return new Gats::Float( fVal ); |
| 26 | } | 33 | } |
| 27 | 34 | ||
| 28 | void Gats::Float::write( Bu::Stream &rOut ) const | 35 | void Gats::Float::write( Bu::Stream &rOut ) const |
| 29 | { | 36 | { |
| 30 | if( fVal == 0.0 ) | 37 | if( fVal == 0.0 ) |
| 31 | { | 38 | { |
| 32 | if( signbit( fVal ) ) | 39 | if( signbit( fVal ) ) |
| 33 | rOut.write("FZ", 2 ); | 40 | rOut.write("FZ", 2 ); |
| 34 | else | 41 | else |
| 35 | rOut.write("Fz", 2 ); | 42 | rOut.write("Fz", 2 ); |
| 36 | } | 43 | } |
| 37 | else if( !isfinite( fVal ) ) | 44 | else if( !isfinite( fVal ) ) |
| 38 | { | 45 | { |
| 39 | if( isnan( fVal ) ) | 46 | if( isnan( fVal ) ) |
| 40 | { | 47 | { |
| 41 | if( signbit( fVal ) ) | 48 | if( signbit( fVal ) ) |
| 42 | rOut.write("FN", 2 ); | 49 | rOut.write("FN", 2 ); |
| 43 | else | 50 | else |
| 44 | rOut.write("Fn", 2 ); | 51 | rOut.write("Fn", 2 ); |
| 45 | } | 52 | } |
| 46 | else | 53 | else |
| 47 | { | 54 | { |
| 48 | if( signbit( fVal ) ) | 55 | if( signbit( fVal ) ) |
| 49 | rOut.write("FI", 2 ); | 56 | rOut.write("FI", 2 ); |
| 50 | else | 57 | else |
| 51 | rOut.write("Fi", 2 ); | 58 | rOut.write("Fi", 2 ); |
| 52 | } | 59 | } |
| 53 | } | 60 | } |
| 54 | else | 61 | else |
| 55 | { | 62 | { |
| 56 | rOut.write("f", 1 ); | 63 | rOut.write("f", 1 ); |
| 57 | double d = fVal; | 64 | double d = fVal; |
| 58 | bool bNeg = false; | 65 | bool bNeg = false; |
| 59 | int64_t iScale=0; | 66 | int64_t iScale=0; |
| 60 | if( signbit( d ) ) | 67 | if( signbit( d ) ) |
| 61 | { | 68 | { |
| 62 | bNeg = true; | 69 | bNeg = true; |
| 63 | d = -d; | 70 | d = -d; |
| 64 | } | 71 | } |
| 65 | 72 | ||
| 66 | iScale = log( d ) / 0x1.62e42fefa39efp+2; // log( 256.0 ) | 73 | iScale = log( d ) / 0x1.62e42fefa39efp+2; // log( 256.0 ) |
| 67 | if( iScale < 0 ) iScale--; | 74 | if( iScale < 0 ) iScale--; |
| 68 | d /= pow( 256.0, iScale ); | 75 | d /= pow( 256.0, iScale ); |
| 69 | 76 | ||
| 70 | Bu::String s; | 77 | Bu::String s; |
| 71 | s += (uint8_t)(d); | 78 | s += (uint8_t)(d); |
| 72 | d -= (int)d; | 79 | d -= (int)d; |
| 73 | for( int j = 0; j < 150 && d; j++ ) | 80 | for( int j = 0; j < 150 && d; j++ ) |
| 74 | { | 81 | { |
| 75 | d = d*256.0; | 82 | d = d*256.0; |
| 76 | s += (uint8_t)d; | 83 | s += (uint8_t)d; |
| 77 | d -= (int)d; | 84 | d -= (int)d; |
| 78 | } | 85 | } |
| 79 | Gats::Integer::writePackedInt( rOut, bNeg?-s.getSize():s.getSize() ); | 86 | Gats::Integer::writePackedInt( rOut, bNeg?-s.getSize():s.getSize() ); |
| 80 | rOut.write( s.getStr(), s.getSize() ); | 87 | rOut.write( s.getStr(), s.getSize() ); |
| 81 | Gats::Integer::writePackedInt( rOut, iScale ); | 88 | Gats::Integer::writePackedInt( rOut, iScale ); |
| 82 | } | 89 | } |
| 83 | } | 90 | } |
| 84 | 91 | ||
| 85 | void Gats::Float::read( Bu::Stream &rIn, char cType ) | 92 | void Gats::Float::read( Bu::Stream &rIn, char cType ) |
| 86 | { | 93 | { |
| 87 | if( cType == 'F' ) | 94 | if( cType == 'F' ) |
| 88 | { | 95 | { |
| 89 | char buf; | 96 | char buf; |
| 90 | rIn.read( &buf, 1 ); | 97 | rIn.read( &buf, 1 ); |
| 91 | switch( buf ) | 98 | switch( buf ) |
| 92 | { | 99 | { |
| 93 | case 'N': fVal = -NAN; break; | 100 | case 'N': fVal = -NAN; break; |
| 94 | case 'n': fVal = NAN; break; | 101 | case 'n': fVal = NAN; break; |
| 95 | case 'I': fVal = -INFINITY; break; | 102 | case 'I': fVal = -INFINITY; break; |
| 96 | case 'i': fVal = INFINITY; break; | 103 | case 'i': fVal = INFINITY; break; |
| 97 | case 'Z': fVal = -0.0; break; | 104 | case 'Z': fVal = -0.0; break; |
| 98 | case 'z': fVal = 0.0; break; | 105 | case 'z': fVal = 0.0; break; |
| 99 | } | 106 | } |
| 100 | } | 107 | } |
| 101 | else if( cType == 'f' ) | 108 | else if( cType == 'f' ) |
| 102 | { | 109 | { |
| 103 | int64_t iStr; | 110 | int64_t iStr; |
| 104 | Gats::Integer::readPackedInt( rIn, iStr ); | 111 | Gats::Integer::readPackedInt( rIn, iStr ); |
| 105 | bool bNeg = false; | 112 | bool bNeg = false; |
| 106 | if( iStr < 0 ) | 113 | if( iStr < 0 ) |
| 107 | { | 114 | { |
| 108 | bNeg = true; | 115 | bNeg = true; |
| 109 | iStr = -iStr; | 116 | iStr = -iStr; |
| 110 | } | 117 | } |
| 111 | Bu::String s( iStr ); | 118 | Bu::String s( iStr ); |
| 112 | rIn.read( s.getStr(), iStr ); | 119 | rIn.read( s.getStr(), iStr ); |
| 113 | fVal = 0.0; | 120 | fVal = 0.0; |
| 114 | for( int j = iStr-1; j > 0; j-- ) | 121 | for( int j = iStr-1; j > 0; j-- ) |
| 115 | { | 122 | { |
| 116 | fVal = (fVal+(uint8_t)s[j])*0x1p-8; | 123 | fVal = (fVal+(uint8_t)s[j])*0x1p-8; |
| 117 | } | 124 | } |
| 118 | fVal += (uint8_t)s[0]; | 125 | fVal += (uint8_t)s[0]; |
| 119 | int64_t iScale; | 126 | int64_t iScale; |
| 120 | Gats::Integer::readPackedInt( rIn, iScale ); | 127 | Gats::Integer::readPackedInt( rIn, iScale ); |
| 121 | fVal *= pow( 256.0, iScale ); | 128 | fVal *= pow( 256.0, iScale ); |
| 122 | if( bNeg ) fVal = -fVal; | 129 | if( bNeg ) fVal = -fVal; |
| 123 | } | 130 | } |
| 124 | } | 131 | } |
| 125 | 132 | ||
| 126 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ) | 133 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ) |
| 127 | { | 134 | { |
| 128 | return f << "(float) " << flt.getValue(); | 135 | return f << "(float) " << flt.getValue(); |
| 129 | } | 136 | } |
| 130 | 137 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef GATS_FLOAT_H | 8 | #ifndef GATS_FLOAT_H |
| 2 | #define GATS_FLOAT_H | 9 | #define GATS_FLOAT_H |
| 3 | 10 | ||
| @@ -7,25 +14,25 @@ | |||
| 7 | 14 | ||
| 8 | namespace Gats | 15 | namespace Gats |
| 9 | { | 16 | { |
| 10 | class Float : public Gats::Object | 17 | class Float : public Gats::Object |
| 11 | { | 18 | { |
| 12 | public: | 19 | public: |
| 13 | Float(); | 20 | Float(); |
| 14 | Float( double f ); | 21 | Float( double f ); |
| 15 | virtual ~Float(); | 22 | virtual ~Float(); |
| 16 | 23 | ||
| 17 | virtual Object *clone() const; | 24 | virtual Object *clone() const; |
| 18 | 25 | ||
| 19 | virtual Type getType() const { return typeFloat; } | 26 | virtual Type getType() const { return typeFloat; } |
| 20 | double getValue() const { return fVal; } | 27 | double getValue() const { return fVal; } |
| 21 | 28 | ||
| 22 | virtual void write( Bu::Stream &rOut ) const; | 29 | virtual void write( Bu::Stream &rOut ) const; |
| 23 | virtual void read( Bu::Stream &rIn, char cType ); | 30 | virtual void read( Bu::Stream &rIn, char cType ); |
| 24 | 31 | ||
| 25 | private: | 32 | private: |
| 26 | double fVal; | 33 | double fVal; |
| 27 | mutable Bu::String sWriteCache; | 34 | mutable Bu::String sWriteCache; |
| 28 | }; | 35 | }; |
| 29 | } | 36 | } |
| 30 | 37 | ||
| 31 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ); | 38 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include <bu/optparser.h> | 8 | #include <bu/optparser.h> |
| 2 | #include <bu/string.h> | 9 | #include <bu/string.h> |
| 3 | #include <bu/file.h> | 10 | #include <bu/file.h> |
| @@ -11,63 +18,63 @@ using namespace Bu; | |||
| 11 | class Options : public OptParser | 18 | class Options : public OptParser |
| 12 | { | 19 | { |
| 13 | public: | 20 | public: |
| 14 | Options( int argc, char *argv[] ) : | 21 | Options( int argc, char *argv[] ) : |
| 15 | bCompile( true ) | 22 | bCompile( true ) |
| 16 | { | 23 | { |
| 17 | addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n"); | 24 | addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n"); |
| 18 | 25 | ||
| 19 | addOption( sInput, 'i', "input", "Specify input file."); | 26 | addOption( sInput, 'i', "input", "Specify input file."); |
| 20 | addOption( sOutput, 'o', "output", "Specify output file."); | 27 | addOption( sOutput, 'o', "output", "Specify output file."); |
| 21 | 28 | ||
| 22 | addOption( bCompile, 'd', "decompile", | 29 | addOption( bCompile, 'd', "decompile", |
| 23 | "Convert binary gats to text gats."); | 30 | "Convert binary gats to text gats."); |
| 24 | 31 | ||
| 25 | addHelpOption('h', "help", "This Help"); | 32 | addHelpOption('h', "help", "This Help"); |
| 26 | 33 | ||
| 27 | setNonOption( slot( this, &Options::setInput ) ); | 34 | setNonOption( slot( this, &Options::setInput ) ); |
| 28 | 35 | ||
| 29 | setOverride("decompile", false ); | 36 | setOverride("decompile", false ); |
| 30 | 37 | ||
| 31 | parse( argc, argv ); | 38 | parse( argc, argv ); |
| 32 | } | 39 | } |
| 33 | 40 | ||
| 34 | int setInput( StrArray aParam ) | 41 | int setInput( StrArray aParam ) |
| 35 | { | 42 | { |
| 36 | sInput = aParam[0]; | 43 | sInput = aParam[0]; |
| 37 | return 0; | 44 | return 0; |
| 38 | } | 45 | } |
| 39 | 46 | ||
| 40 | bool bCompile; | 47 | bool bCompile; |
| 41 | String sInput; | 48 | String sInput; |
| 42 | String sOutput; | 49 | String sOutput; |
| 43 | }; | 50 | }; |
| 44 | 51 | ||
| 45 | int main( int argc, char *argv[] ) | 52 | int main( int argc, char *argv[] ) |
| 46 | { | 53 | { |
| 47 | Options opt( argc, argv ); | 54 | Options opt( argc, argv ); |
| 48 | 55 | ||
| 49 | if( opt.sInput.isEmpty() ) | 56 | if( opt.sInput.isEmpty() ) |
| 50 | { | 57 | { |
| 51 | sio << "You must specify an input." << sio.nl << sio.nl; | 58 | sio << "You must specify an input." << sio.nl << sio.nl; |
| 52 | return 1; | 59 | return 1; |
| 53 | } | 60 | } |
| 54 | 61 | ||
| 55 | if( opt.sOutput.isEmpty() ) | 62 | if( opt.sOutput.isEmpty() ) |
| 56 | { | 63 | { |
| 57 | opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') ); | 64 | opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') ); |
| 58 | opt.sOutput += ".gats"; | 65 | opt.sOutput += ".gats"; |
| 59 | } | 66 | } |
| 60 | 67 | ||
| 61 | if( opt.bCompile ) | 68 | if( opt.bCompile ) |
| 62 | { | 69 | { |
| 63 | File fIn( opt.sInput, File::Read ); | 70 | File fIn( opt.sInput, File::Read ); |
| 64 | File fOut( opt.sOutput, File::WriteNew ); | 71 | File fOut( opt.sOutput, File::WriteNew ); |
| 65 | Gats::GatsStream gs( fOut ); | 72 | Gats::GatsStream gs( fOut ); |
| 66 | Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() ); | 73 | Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() ); |
| 67 | gs.writeObject( pObj ); | 74 | gs.writeObject( pObj ); |
| 68 | delete pObj; | 75 | delete pObj; |
| 69 | } | 76 | } |
| 70 | 77 | ||
| 71 | return 0; | 78 | return 0; |
| 72 | } | 79 | } |
| 73 | 80 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "clientthread.h" | 8 | #include "clientthread.h" |
| 2 | 9 | ||
| 3 | #include <bu/tcpsocket.h> | 10 | #include <bu/tcpsocket.h> |
| 4 | 11 | ||
| 5 | ClientThread::ClientThread( QObject *pParent, const QByteArray &baHost, | 12 | ClientThread::ClientThread( QObject *pParent, const QByteArray &baHost, |
| 6 | int iPort ) : | 13 | int iPort ) : |
| 7 | QThread( pParent ), | 14 | QThread( pParent ), |
| 8 | baHost( baHost ), | 15 | baHost( baHost ), |
| 9 | iPort( iPort ), | 16 | iPort( iPort ), |
| 10 | gsCli( ssCli ) | 17 | gsCli( ssCli ) |
| 11 | { | 18 | { |
| 12 | } | 19 | } |
| 13 | 20 | ||
| @@ -17,22 +24,22 @@ ClientThread::~ClientThread() | |||
| 17 | 24 | ||
| 18 | void ClientThread::send( Gats::Object *pObj ) | 25 | void ClientThread::send( Gats::Object *pObj ) |
| 19 | { | 26 | { |
| 20 | gsCli.writeObject( pObj ); | 27 | gsCli.writeObject( pObj ); |
| 21 | } | 28 | } |
| 22 | 29 | ||
| 23 | void ClientThread::run() | 30 | void ClientThread::run() |
| 24 | { | 31 | { |
| 25 | ssCli.setStream( | 32 | ssCli.setStream( |
| 26 | new Bu::TcpSocket( baHost.constData(), iPort ) | 33 | new Bu::TcpSocket( baHost.constData(), iPort ) |
| 27 | ); | 34 | ); |
| 28 | 35 | ||
| 29 | while( !ssCli.isEos() ) | 36 | while( !ssCli.isEos() ) |
| 30 | { | 37 | { |
| 31 | Gats::Object *pObj = gsCli.readObject(); | 38 | Gats::Object *pObj = gsCli.readObject(); |
| 32 | if( pObj == NULL ) | 39 | if( pObj == NULL ) |
| 33 | continue; | 40 | continue; |
| 34 | 41 | ||
| 35 | emit recv( pObj ); | 42 | emit recv( pObj ); |
| 36 | } | 43 | } |
| 37 | } | 44 | } |
| 38 | 45 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef CLIENT_THREAD_H | 8 | #ifndef CLIENT_THREAD_H |
| 2 | #define CLIENT_THREAD_H | 9 | #define CLIENT_THREAD_H |
| 3 | 10 | ||
| @@ -9,29 +16,29 @@ | |||
| 9 | 16 | ||
| 10 | namespace Gats | 17 | namespace Gats |
| 11 | { | 18 | { |
| 12 | class Object; | 19 | class Object; |
| 13 | }; | 20 | }; |
| 14 | 21 | ||
| 15 | class ClientThread : public QThread | 22 | class ClientThread : public QThread |
| 16 | { | 23 | { |
| 17 | Q_OBJECT; | 24 | Q_OBJECT; |
| 18 | public: | 25 | public: |
| 19 | ClientThread( QObject *pParent, const QByteArray &baHost, int iPort ); | 26 | ClientThread( QObject *pParent, const QByteArray &baHost, int iPort ); |
| 20 | virtual ~ClientThread(); | 27 | virtual ~ClientThread(); |
| 21 | 28 | ||
| 22 | void send( Gats::Object *pObj ); | 29 | void send( Gats::Object *pObj ); |
| 23 | 30 | ||
| 24 | signals: | 31 | signals: |
| 25 | void recv( Gats::Object *pObj ); | 32 | void recv( Gats::Object *pObj ); |
| 26 | 33 | ||
| 27 | protected: | 34 | protected: |
| 28 | virtual void run(); | 35 | virtual void run(); |
| 29 | 36 | ||
| 30 | private: | 37 | private: |
| 31 | QByteArray baHost; | 38 | QByteArray baHost; |
| 32 | int iPort; | 39 | int iPort; |
| 33 | Bu::StreamStack ssCli; | 40 | Bu::StreamStack ssCli; |
| 34 | Gats::GatsStream gsCli; | 41 | Gats::GatsStream gsCli; |
| 35 | }; | 42 | }; |
| 36 | 43 | ||
| 37 | #endif | 44 | #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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "clientwidget.h" | 8 | #include "clientwidget.h" |
| 2 | #include "clientthread.h" | 9 | #include "clientthread.h" |
| 3 | 10 | ||
| @@ -14,16 +21,16 @@ | |||
| 14 | using namespace Bu; | 21 | using namespace Bu; |
| 15 | 22 | ||
| 16 | ClientWidget::ClientWidget( QWidget *pParent, const QByteArray &baHost, | 23 | ClientWidget::ClientWidget( QWidget *pParent, const QByteArray &baHost, |
| 17 | int iPort ) : | 24 | int iPort ) : |
| 18 | QWidget( pParent ) | 25 | QWidget( pParent ) |
| 19 | { | 26 | { |
| 20 | setupUi( this ); | 27 | setupUi( this ); |
| 21 | 28 | ||
| 22 | pCli = new ClientThread( this, baHost, iPort ); | 29 | pCli = new ClientThread( this, baHost, iPort ); |
| 23 | connect( pCli, SIGNAL(recv( Gats::Object *)), | 30 | connect( pCli, SIGNAL(recv( Gats::Object *)), |
| 24 | this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection ); | 31 | this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection ); |
| 25 | 32 | ||
| 26 | pCli->start(); | 33 | pCli->start(); |
| 27 | } | 34 | } |
| 28 | 35 | ||
| 29 | ClientWidget::~ClientWidget() | 36 | ClientWidget::~ClientWidget() |
| @@ -32,51 +39,51 @@ ClientWidget::~ClientWidget() | |||
| 32 | 39 | ||
| 33 | void ClientWidget::saveTo( const QString &sFile ) | 40 | void ClientWidget::saveTo( const QString &sFile ) |
| 34 | { | 41 | { |
| 35 | File fOut( sFile.toAscii().constData(), File::WriteNew ); | 42 | File fOut( sFile.toAscii().constData(), File::WriteNew ); |
| 36 | Gats::GatsStream gsOut( fOut ); | 43 | Gats::GatsStream gsOut( fOut ); |
| 37 | QTreeWidgetItem *pRoot = twHistory->invisibleRootItem(); | 44 | QTreeWidgetItem *pRoot = twHistory->invisibleRootItem(); |
| 38 | for( int j = 0; j < pRoot->childCount(); j++ ) | 45 | for( int j = 0; j < pRoot->childCount(); j++ ) |
| 39 | { | 46 | { |
| 40 | Gats::Object *pObj = treeToGats( pRoot->child( j ) ); | 47 | Gats::Object *pObj = treeToGats( pRoot->child( j ) ); |
| 41 | gsOut.writeObject( pObj ); | 48 | gsOut.writeObject( pObj ); |
| 42 | delete pObj; | 49 | delete pObj; |
| 43 | } | 50 | } |
| 44 | } | 51 | } |
| 45 | 52 | ||
| 46 | void ClientWidget::send() | 53 | void ClientWidget::send() |
| 47 | { | 54 | { |
| 48 | try | 55 | try |
| 49 | { | 56 | { |
| 50 | Gats::Object *pObj = Gats::Object::strToGats( | 57 | Gats::Object *pObj = Gats::Object::strToGats( |
| 51 | leGats->text().toAscii().constData() | 58 | leGats->text().toAscii().constData() |
| 52 | ); | 59 | ); |
| 53 | sio << "Send: " << *pObj << sio.nl; | 60 | sio << "Send: " << *pObj << sio.nl; |
| 54 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | 61 | QTreeWidgetItem *pIt = new QTreeWidgetItem( |
| 55 | twHistory->invisibleRootItem() | 62 | twHistory->invisibleRootItem() |
| 56 | ); | 63 | ); |
| 57 | pIt->setText( 0, "send" ); | 64 | pIt->setText( 0, "send" ); |
| 58 | gatsToTree( pIt, pObj ); | 65 | gatsToTree( pIt, pObj ); |
| 59 | pCli->send( pObj ); | 66 | pCli->send( pObj ); |
| 60 | delete pObj; | 67 | delete pObj; |
| 61 | 68 | ||
| 62 | leGats->setText(""); | 69 | leGats->setText(""); |
| 63 | leGats->setFocus(); | 70 | leGats->setFocus(); |
| 64 | } | 71 | } |
| 65 | catch( Bu::ExceptionBase &e ) | 72 | catch( Bu::ExceptionBase &e ) |
| 66 | { | 73 | { |
| 67 | QMessageBox::critical( this, "Gats Console - Error", e.what() ); | 74 | QMessageBox::critical( this, "Gats Console - Error", e.what() ); |
| 68 | } | 75 | } |
| 69 | } | 76 | } |
| 70 | 77 | ||
| 71 | void ClientWidget::recv( Gats::Object *pObj ) | 78 | void ClientWidget::recv( Gats::Object *pObj ) |
| 72 | { | 79 | { |
| 73 | sio << "Recv: " << *pObj << sio.nl; | 80 | sio << "Recv: " << *pObj << sio.nl; |
| 74 | 81 | ||
| 75 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | 82 | QTreeWidgetItem *pIt = new QTreeWidgetItem( |
| 76 | twHistory->invisibleRootItem() | 83 | twHistory->invisibleRootItem() |
| 77 | ); | 84 | ); |
| 78 | pIt->setText( 0, "recv" ); | 85 | pIt->setText( 0, "recv" ); |
| 79 | gatsToTree( pIt, pObj ); | 86 | gatsToTree( pIt, pObj ); |
| 80 | delete pObj; | 87 | delete pObj; |
| 81 | } | 88 | } |
| 82 | 89 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef CLIENT_WIDGET_H | 8 | #ifndef CLIENT_WIDGET_H |
| 2 | #define CLIENT_WIDGET_H | 9 | #define CLIENT_WIDGET_H |
| 3 | 10 | ||
| @@ -7,24 +14,24 @@ | |||
| 7 | 14 | ||
| 8 | namespace Gats | 15 | namespace Gats |
| 9 | { | 16 | { |
| 10 | class Object; | 17 | class Object; |
| 11 | }; | 18 | }; |
| 12 | 19 | ||
| 13 | class ClientWidget : public QWidget, protected Ui::ClientWidget, public IoBase | 20 | class ClientWidget : public QWidget, protected Ui::ClientWidget, public IoBase |
| 14 | { | 21 | { |
| 15 | Q_OBJECT; | 22 | Q_OBJECT; |
| 16 | public: | 23 | public: |
| 17 | ClientWidget( QWidget *pParent, const QByteArray &baHost, int iPort ); | 24 | ClientWidget( QWidget *pParent, const QByteArray &baHost, int iPort ); |
| 18 | virtual ~ClientWidget(); | 25 | virtual ~ClientWidget(); |
| 19 | 26 | ||
| 20 | virtual void saveTo( const QString &sFile ); | 27 | virtual void saveTo( const QString &sFile ); |
| 21 | 28 | ||
| 22 | public slots: | 29 | public slots: |
| 23 | void send(); | 30 | void send(); |
| 24 | void recv( Gats::Object *pObj ); | 31 | void recv( Gats::Object *pObj ); |
| 25 | 32 | ||
| 26 | private: | 33 | private: |
| 27 | class ClientThread *pCli; | 34 | class ClientThread *pCli; |
| 28 | }; | 35 | }; |
| 29 | 36 | ||
| 30 | #endif | 37 | #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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "connectdlg.h" | 8 | #include "connectdlg.h" |
| 2 | 9 | ||
| 3 | ConnectDlg::ConnectDlg( QWidget *pParent ) : | 10 | ConnectDlg::ConnectDlg( QWidget *pParent ) : |
| 4 | QDialog( pParent ) | 11 | QDialog( pParent ) |
| 5 | { | 12 | { |
| 6 | setupUi( this ); | 13 | setupUi( this ); |
| 7 | } | 14 | } |
| 8 | 15 | ||
| 9 | ConnectDlg::~ConnectDlg() | 16 | ConnectDlg::~ConnectDlg() |
| @@ -12,11 +19,11 @@ ConnectDlg::~ConnectDlg() | |||
| 12 | 19 | ||
| 13 | QByteArray ConnectDlg::getHostname() const | 20 | QByteArray ConnectDlg::getHostname() const |
| 14 | { | 21 | { |
| 15 | return leHost->text().toAscii(); | 22 | return leHost->text().toAscii(); |
| 16 | } | 23 | } |
| 17 | 24 | ||
| 18 | int ConnectDlg::getPort() const | 25 | int ConnectDlg::getPort() const |
| 19 | { | 26 | { |
| 20 | return sbPort->value(); | 27 | return sbPort->value(); |
| 21 | } | 28 | } |
| 22 | 29 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef CONNECT_DLG_H | 8 | #ifndef CONNECT_DLG_H |
| 2 | #define CONNECT_DLG_H | 9 | #define CONNECT_DLG_H |
| 3 | 10 | ||
| @@ -5,13 +12,13 @@ | |||
| 5 | 12 | ||
| 6 | class ConnectDlg : public QDialog, protected Ui::ConnectDlg | 13 | class ConnectDlg : public QDialog, protected Ui::ConnectDlg |
| 7 | { | 14 | { |
| 8 | Q_OBJECT; | 15 | Q_OBJECT; |
| 9 | public: | 16 | public: |
| 10 | ConnectDlg( QWidget *pParent ); | 17 | ConnectDlg( QWidget *pParent ); |
| 11 | virtual ~ConnectDlg(); | 18 | virtual ~ConnectDlg(); |
| 12 | 19 | ||
| 13 | QByteArray getHostname() const; | 20 | QByteArray getHostname() const; |
| 14 | int getPort() const; | 21 | int getPort() const; |
| 15 | }; | 22 | }; |
| 16 | 23 | ||
| 17 | #endif | 24 | #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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "filewidget.h" | 8 | #include "filewidget.h" |
| 2 | 9 | ||
| 3 | #include "gatstotree.h" | 10 | #include "gatstotree.h" |
| @@ -12,28 +19,28 @@ | |||
| 12 | using namespace Bu; | 19 | using namespace Bu; |
| 13 | 20 | ||
| 14 | FileWidget::FileWidget( QWidget *pParent ) : | 21 | FileWidget::FileWidget( QWidget *pParent ) : |
| 15 | QWidget( pParent ) | 22 | QWidget( pParent ) |
| 16 | { | 23 | { |
| 17 | setupUi( this ); | 24 | setupUi( this ); |
| 18 | } | 25 | } |
| 19 | 26 | ||
| 20 | FileWidget::FileWidget( QWidget *pParent, QString sFile ) : | 27 | FileWidget::FileWidget( QWidget *pParent, QString sFile ) : |
| 21 | QWidget( pParent ) | 28 | QWidget( pParent ) |
| 22 | { | 29 | { |
| 23 | setupUi( this ); | 30 | setupUi( this ); |
| 24 | 31 | ||
| 25 | File fIn( sFile.toAscii().constData(), File::Read ); | 32 | File fIn( sFile.toAscii().constData(), File::Read ); |
| 26 | Gats::GatsStream gsIn( fIn ); | 33 | Gats::GatsStream gsIn( fIn ); |
| 27 | Gats::Object *pObj; | 34 | Gats::Object *pObj; |
| 28 | while( (pObj = gsIn.readObject()) ) | 35 | while( (pObj = gsIn.readObject()) ) |
| 29 | { | 36 | { |
| 30 | QTreeWidgetItem *pNew = new QTreeWidgetItem( | 37 | QTreeWidgetItem *pNew = new QTreeWidgetItem( |
| 31 | twGats->invisibleRootItem() | 38 | twGats->invisibleRootItem() |
| 32 | ); | 39 | ); |
| 33 | pNew->setText( 0, "<root>" ); | 40 | pNew->setText( 0, "<root>" ); |
| 34 | gatsToTree( pNew, pObj ); | 41 | gatsToTree( pNew, pObj ); |
| 35 | delete pObj; | 42 | delete pObj; |
| 36 | } | 43 | } |
| 37 | } | 44 | } |
| 38 | 45 | ||
| 39 | FileWidget::~FileWidget() | 46 | FileWidget::~FileWidget() |
| @@ -42,28 +49,28 @@ FileWidget::~FileWidget() | |||
| 42 | 49 | ||
| 43 | void FileWidget::saveTo( const QString &sFile ) | 50 | void FileWidget::saveTo( const QString &sFile ) |
| 44 | { | 51 | { |
| 45 | File fOut( sFile.toAscii().constData(), File::WriteNew ); | 52 | File fOut( sFile.toAscii().constData(), File::WriteNew ); |
| 46 | Gats::GatsStream gsOut( fOut ); | 53 | Gats::GatsStream gsOut( fOut ); |
| 47 | QTreeWidgetItem *pRoot = twGats->invisibleRootItem(); | 54 | QTreeWidgetItem *pRoot = twGats->invisibleRootItem(); |
| 48 | for( int j = 0; j < pRoot->childCount(); j++ ) | 55 | for( int j = 0; j < pRoot->childCount(); j++ ) |
| 49 | { | 56 | { |
| 50 | Gats::Object *pObj = treeToGats( pRoot->child( j ) ); | 57 | Gats::Object *pObj = treeToGats( pRoot->child( j ) ); |
| 51 | gsOut.writeObject( pObj ); | 58 | gsOut.writeObject( pObj ); |
| 52 | delete pObj; | 59 | delete pObj; |
| 53 | } | 60 | } |
| 54 | } | 61 | } |
| 55 | 62 | ||
| 56 | void FileWidget::addRootItem() | 63 | void FileWidget::addRootItem() |
| 57 | { | 64 | { |
| 58 | QString sText = QInputDialog::getText( this, "Gats Console - Add Root Item", | 65 | QString sText = QInputDialog::getText( this, "Gats Console - Add Root Item", |
| 59 | "Gats:"); | 66 | "Gats:"); |
| 60 | Gats::Object *pObj = Gats::Object::strToGats( sText.toAscii().constData() ); | 67 | Gats::Object *pObj = Gats::Object::strToGats( sText.toAscii().constData() ); |
| 61 | QTreeWidgetItem *pNew = new QTreeWidgetItem( | 68 | QTreeWidgetItem *pNew = new QTreeWidgetItem( |
| 62 | twGats->invisibleRootItem() | 69 | twGats->invisibleRootItem() |
| 63 | ); | 70 | ); |
| 64 | pNew->setText( 0, "<root>" ); | 71 | pNew->setText( 0, "<root>" ); |
| 65 | gatsToTree( pNew, pObj ); | 72 | gatsToTree( pNew, pObj ); |
| 66 | delete pObj; | 73 | delete pObj; |
| 67 | } | 74 | } |
| 68 | 75 | ||
| 69 | void FileWidget::delRootItem() | 76 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef FILE_WIDGET_H | 8 | #ifndef FILE_WIDGET_H |
| 2 | #define FILE_WIDGET_H | 9 | #define FILE_WIDGET_H |
| 3 | 10 | ||
| @@ -6,22 +13,22 @@ | |||
| 6 | 13 | ||
| 7 | namespace Gats | 14 | namespace Gats |
| 8 | { | 15 | { |
| 9 | class Object; | 16 | class Object; |
| 10 | }; | 17 | }; |
| 11 | 18 | ||
| 12 | class FileWidget : public QWidget, protected Ui::FileWidget, public IoBase | 19 | class FileWidget : public QWidget, protected Ui::FileWidget, public IoBase |
| 13 | { | 20 | { |
| 14 | Q_OBJECT; | 21 | Q_OBJECT; |
| 15 | public: | 22 | public: |
| 16 | FileWidget( QWidget *pParent=NULL ); | 23 | FileWidget( QWidget *pParent=NULL ); |
| 17 | FileWidget( QWidget *pParent, QString sFile ); | 24 | FileWidget( QWidget *pParent, QString sFile ); |
| 18 | virtual ~FileWidget(); | 25 | virtual ~FileWidget(); |
| 19 | 26 | ||
| 20 | virtual void saveTo( const QString &sFile ); | 27 | virtual void saveTo( const QString &sFile ); |
| 21 | 28 | ||
| 22 | public slots: | 29 | public slots: |
| 23 | void addRootItem(); | 30 | void addRootItem(); |
| 24 | void delRootItem(); | 31 | void delRootItem(); |
| 25 | 32 | ||
| 26 | private: | 33 | private: |
| 27 | }; | 34 | }; |
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gatstotree.h" | 8 | #include "gatstotree.h" |
| 2 | 9 | ||
| 3 | #include <gats/types.h> | 10 | #include <gats/types.h> |
| @@ -6,86 +13,86 @@ | |||
| 6 | 13 | ||
| 7 | void gatsToTree( QTreeWidgetItem *p, Gats::Object *pObj ) | 14 | void gatsToTree( QTreeWidgetItem *p, Gats::Object *pObj ) |
| 8 | { | 15 | { |
| 9 | switch( pObj->getType() ) | 16 | switch( pObj->getType() ) |
| 10 | { | 17 | { |
| 11 | case Gats::typeInteger: | 18 | case Gats::typeInteger: |
| 12 | gatsToTree( p, dynamic_cast<Gats::Integer *>( pObj ) ); | 19 | gatsToTree( p, dynamic_cast<Gats::Integer *>( pObj ) ); |
| 13 | break; | 20 | break; |
| 14 | 21 | ||
| 15 | case Gats::typeString: | 22 | case Gats::typeString: |
| 16 | gatsToTree( p, dynamic_cast<Gats::String *>( pObj ) ); | 23 | gatsToTree( p, dynamic_cast<Gats::String *>( pObj ) ); |
| 17 | break; | 24 | break; |
| 18 | 25 | ||
| 19 | case Gats::typeFloat: | 26 | case Gats::typeFloat: |
| 20 | gatsToTree( p, dynamic_cast<Gats::Float *>( pObj ) ); | 27 | gatsToTree( p, dynamic_cast<Gats::Float *>( pObj ) ); |
| 21 | break; | 28 | break; |
| 22 | 29 | ||
| 23 | case Gats::typeBoolean: | 30 | case Gats::typeBoolean: |
| 24 | gatsToTree( p, dynamic_cast<Gats::Boolean *>( pObj ) ); | 31 | gatsToTree( p, dynamic_cast<Gats::Boolean *>( pObj ) ); |
| 25 | break; | 32 | break; |
| 26 | 33 | ||
| 27 | case Gats::typeList: | 34 | case Gats::typeList: |
| 28 | gatsToTree( p, dynamic_cast<Gats::List *>( pObj ) ); | 35 | gatsToTree( p, dynamic_cast<Gats::List *>( pObj ) ); |
| 29 | break; | 36 | break; |
| 30 | 37 | ||
| 31 | case Gats::typeDictionary: | 38 | case Gats::typeDictionary: |
| 32 | gatsToTree( p, dynamic_cast<Gats::Dictionary *>( pObj ) ); | 39 | gatsToTree( p, dynamic_cast<Gats::Dictionary *>( pObj ) ); |
| 33 | break; | 40 | break; |
| 34 | 41 | ||
| 35 | case Gats::typeNull: | 42 | case Gats::typeNull: |
| 36 | gatsToTree( p, dynamic_cast<Gats::Null *>( pObj ) ); | 43 | gatsToTree( p, dynamic_cast<Gats::Null *>( pObj ) ); |
| 37 | break; | 44 | break; |
| 38 | } | 45 | } |
| 39 | } | 46 | } |
| 40 | 47 | ||
| 41 | void gatsToTree( QTreeWidgetItem *p, Gats::Integer *pObj ) | 48 | void gatsToTree( QTreeWidgetItem *p, Gats::Integer *pObj ) |
| 42 | { | 49 | { |
| 43 | p->setText( 1, "int"); | 50 | p->setText( 1, "int"); |
| 44 | p->setText( 2, QString("%1").arg( pObj->getValue() ) ); | 51 | p->setText( 2, QString("%1").arg( pObj->getValue() ) ); |
| 45 | } | 52 | } |
| 46 | 53 | ||
| 47 | void gatsToTree( QTreeWidgetItem *p, Gats::String *pObj ) | 54 | void gatsToTree( QTreeWidgetItem *p, Gats::String *pObj ) |
| 48 | { | 55 | { |
| 49 | p->setText( 1, "str"); | 56 | p->setText( 1, "str"); |
| 50 | p->setText( 2, QString("%1").arg( pObj->getStr() ) ); | 57 | p->setText( 2, QString("%1").arg( pObj->getStr() ) ); |
| 51 | } | 58 | } |
| 52 | 59 | ||
| 53 | void gatsToTree( QTreeWidgetItem *p, Gats::Float *pObj ) | 60 | void gatsToTree( QTreeWidgetItem *p, Gats::Float *pObj ) |
| 54 | { | 61 | { |
| 55 | p->setText( 1, "float"); | 62 | p->setText( 1, "float"); |
| 56 | p->setText( 2, QString("%1").arg( pObj->getValue() ) ); | 63 | p->setText( 2, QString("%1").arg( pObj->getValue() ) ); |
| 57 | } | 64 | } |
| 58 | 65 | ||
| 59 | void gatsToTree( QTreeWidgetItem *p, Gats::Boolean *pObj ) | 66 | void gatsToTree( QTreeWidgetItem *p, Gats::Boolean *pObj ) |
| 60 | { | 67 | { |
| 61 | p->setText( 1, "bool"); | 68 | p->setText( 1, "bool"); |
| 62 | p->setText( 2, pObj->getValue()?"true":"false" ); | 69 | p->setText( 2, pObj->getValue()?"true":"false" ); |
| 63 | } | 70 | } |
| 64 | 71 | ||
| 65 | void gatsToTree( QTreeWidgetItem *p, Gats::List *pObj ) | 72 | void gatsToTree( QTreeWidgetItem *p, Gats::List *pObj ) |
| 66 | { | 73 | { |
| 67 | p->setText( 1, "list"); | 74 | p->setText( 1, "list"); |
| 68 | int j = 0; | 75 | int j = 0; |
| 69 | for( Gats::List::iterator i = pObj->begin(); i; i++ ) | 76 | for( Gats::List::iterator i = pObj->begin(); i; i++ ) |
| 70 | { | 77 | { |
| 71 | QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); | 78 | QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); |
| 72 | pIt->setText( 0, QString("%1").arg( j++ ) ); | 79 | pIt->setText( 0, QString("%1").arg( j++ ) ); |
| 73 | gatsToTree( pIt, *i ); | 80 | gatsToTree( pIt, *i ); |
| 74 | } | 81 | } |
| 75 | } | 82 | } |
| 76 | 83 | ||
| 77 | void gatsToTree( QTreeWidgetItem *p, Gats::Dictionary *pObj ) | 84 | void gatsToTree( QTreeWidgetItem *p, Gats::Dictionary *pObj ) |
| 78 | { | 85 | { |
| 79 | p->setText( 1, "dict"); | 86 | p->setText( 1, "dict"); |
| 80 | for( Gats::Dictionary::iterator i = pObj->begin(); i; i++ ) | 87 | for( Gats::Dictionary::iterator i = pObj->begin(); i; i++ ) |
| 81 | { | 88 | { |
| 82 | QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); | 89 | QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); |
| 83 | pIt->setText( 0, QString( i.getKey().getStr() ) ); | 90 | pIt->setText( 0, QString( i.getKey().getStr() ) ); |
| 84 | gatsToTree( pIt, *i ); | 91 | gatsToTree( pIt, *i ); |
| 85 | } | 92 | } |
| 86 | } | 93 | } |
| 87 | 94 | ||
| 88 | void gatsToTree( QTreeWidgetItem *p, Gats::Null *pObj ) | 95 | void gatsToTree( QTreeWidgetItem *p, Gats::Null *pObj ) |
| 89 | { | 96 | { |
| 90 | p->setText( 1, "null"); | 97 | p->setText( 1, "null"); |
| 91 | } | 98 | } |
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef GATS_TO_TREE_H | 8 | #ifndef GATS_TO_TREE_H |
| 2 | #define GATS_TO_TREE_H | 9 | #define GATS_TO_TREE_H |
| 3 | 10 | ||
| @@ -5,13 +12,13 @@ class QTreeWidgetItem; | |||
| 5 | 12 | ||
| 6 | namespace Gats | 13 | namespace Gats |
| 7 | { | 14 | { |
| 8 | class Integer; | 15 | class Integer; |
| 9 | class String; | 16 | class String; |
| 10 | class Float; | 17 | class Float; |
| 11 | class Boolean; | 18 | class Boolean; |
| 12 | class List; | 19 | class List; |
| 13 | class Dictionary; | 20 | class Dictionary; |
| 14 | class Object; | 21 | class Object; |
| 15 | }; | 22 | }; |
| 16 | 23 | ||
| 17 | #include <gats/types.h> | 24 | #include <gats/types.h> |
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "iobase.h" | 8 | #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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef IO_BASE_H | 8 | #ifndef IO_BASE_H |
| 2 | #define IO_BASE_H | 9 | #define IO_BASE_H |
| 3 | 10 | ||
| 4 | class IoBase | 11 | class IoBase |
| 5 | { | 12 | { |
| 6 | public: | 13 | public: |
| 7 | virtual void saveTo( const class QString &sFile )=0; | 14 | virtual void saveTo( const class QString &sFile )=0; |
| 8 | }; | 15 | }; |
| 9 | 16 | ||
| 10 | #endif | 17 | #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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "mainwnd.h" | 8 | #include "mainwnd.h" |
| 2 | #include <QApplication> | 9 | #include <QApplication> |
| 3 | 10 | ||
| 4 | int main( int argc, char *argv[] ) | 11 | int main( int argc, char *argv[] ) |
| 5 | { | 12 | { |
| 6 | QApplication app( argc, argv ); | 13 | QApplication app( argc, argv ); |
| 7 | 14 | ||
| 8 | MainWnd wnd; | 15 | MainWnd wnd; |
| 9 | wnd.show(); | 16 | wnd.show(); |
| 10 | 17 | ||
| 11 | return app.exec(); | 18 | return app.exec(); |
| 12 | } | 19 | } |
| 13 | 20 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "mainwnd.h" | 8 | #include "mainwnd.h" |
| 2 | 9 | ||
| 3 | #include "clientwidget.h" | 10 | #include "clientwidget.h" |
| @@ -12,10 +19,10 @@ | |||
| 12 | 19 | ||
| 13 | MainWnd::MainWnd() | 20 | MainWnd::MainWnd() |
| 14 | { | 21 | { |
| 15 | setupUi( this ); | 22 | setupUi( this ); |
| 16 | 23 | ||
| 17 | pMode = new QLabel( "Idle", this ); | 24 | pMode = new QLabel( "Idle", this ); |
| 18 | statusBar()->addPermanentWidget( pMode ); | 25 | statusBar()->addPermanentWidget( pMode ); |
| 19 | } | 26 | } |
| 20 | 27 | ||
| 21 | MainWnd::~MainWnd() | 28 | MainWnd::~MainWnd() |
| @@ -24,96 +31,96 @@ MainWnd::~MainWnd() | |||
| 24 | 31 | ||
| 25 | void MainWnd::connect() | 32 | void MainWnd::connect() |
| 26 | { | 33 | { |
| 27 | ConnectDlg dlg( this ); | 34 | ConnectDlg dlg( this ); |
| 28 | if( dlg.exec() == QDialog::Accepted ) | 35 | if( dlg.exec() == QDialog::Accepted ) |
| 29 | { | 36 | { |
| 30 | sCurFile.clear(); | 37 | sCurFile.clear(); |
| 31 | setCentralWidget( | 38 | setCentralWidget( |
| 32 | new ClientWidget( | 39 | new ClientWidget( |
| 33 | this, dlg.getHostname(), dlg.getPort() | 40 | this, dlg.getHostname(), dlg.getPort() |
| 34 | ) | 41 | ) |
| 35 | ); | 42 | ); |
| 36 | pMode->setText( | 43 | pMode->setText( |
| 37 | QString("Client Mode: %1:%2").arg( QString(dlg.getHostname()) ). | 44 | QString("Client Mode: %1:%2").arg( QString(dlg.getHostname()) ). |
| 38 | arg( dlg.getPort() ) | 45 | arg( dlg.getPort() ) |
| 39 | ); | 46 | ); |
| 40 | } | 47 | } |
| 41 | } | 48 | } |
| 42 | 49 | ||
| 43 | void MainWnd::proxy() | 50 | void MainWnd::proxy() |
| 44 | { | 51 | { |
| 45 | SetupProxyDlg dlg( this ); | 52 | SetupProxyDlg dlg( this ); |
| 46 | 53 | ||
| 47 | if( dlg.exec() == QDialog::Accepted ) | 54 | if( dlg.exec() == QDialog::Accepted ) |
| 48 | { | 55 | { |
| 49 | sCurFile.clear(); | 56 | sCurFile.clear(); |
| 50 | setCentralWidget( | 57 | setCentralWidget( |
| 51 | new ProxyWidget( | 58 | new ProxyWidget( |
| 52 | this, dlg.getPortIn(), dlg.getHostOut(), dlg.getPortOut() | 59 | this, dlg.getPortIn(), dlg.getHostOut(), dlg.getPortOut() |
| 53 | ) | 60 | ) |
| 54 | ); | 61 | ); |
| 55 | pMode->setText( | 62 | pMode->setText( |
| 56 | QString("Proxy Mode: :%1 -> %2:%3").arg( dlg.getPortIn() ). | 63 | QString("Proxy Mode: :%1 -> %2:%3").arg( dlg.getPortIn() ). |
| 57 | arg( QString(dlg.getHostOut()) ). | 64 | arg( QString(dlg.getHostOut()) ). |
| 58 | arg( dlg.getPortOut() ) | 65 | arg( dlg.getPortOut() ) |
| 59 | ); | 66 | ); |
| 60 | } | 67 | } |
| 61 | } | 68 | } |
| 62 | 69 | ||
| 63 | void MainWnd::open() | 70 | void MainWnd::open() |
| 64 | { | 71 | { |
| 65 | QString sFile = QFileDialog::getOpenFileName( | 72 | QString sFile = QFileDialog::getOpenFileName( |
| 66 | this, "Gats Console - open gats file" | 73 | this, "Gats Console - open gats file" |
| 67 | ); | 74 | ); |
| 68 | if( sFile.isEmpty() ) | 75 | if( sFile.isEmpty() ) |
| 69 | return; | 76 | return; |
| 70 | 77 | ||
| 71 | sCurFile = sFile; | 78 | sCurFile = sFile; |
| 72 | setCentralWidget( | 79 | setCentralWidget( |
| 73 | new FileWidget( this, sFile ) | 80 | new FileWidget( this, sFile ) |
| 74 | ); | 81 | ); |
| 75 | pMode->setText( QString("File mode: %1").arg( sCurFile ) ); | 82 | pMode->setText( QString("File mode: %1").arg( sCurFile ) ); |
| 76 | } | 83 | } |
| 77 | 84 | ||
| 78 | void MainWnd::newFile() | 85 | void MainWnd::newFile() |
| 79 | { | 86 | { |
| 80 | sCurFile.clear(); | 87 | sCurFile.clear(); |
| 81 | setCentralWidget( | 88 | setCentralWidget( |
| 82 | new FileWidget( this ) | 89 | new FileWidget( this ) |
| 83 | ); | 90 | ); |
| 84 | pMode->setText( QString("File mode: <untitled>") ); | 91 | pMode->setText( QString("File mode: <untitled>") ); |
| 85 | } | 92 | } |
| 86 | 93 | ||
| 87 | void MainWnd::save() | 94 | void MainWnd::save() |
| 88 | { | 95 | { |
| 89 | if( sCurFile.isEmpty() ) | 96 | if( sCurFile.isEmpty() ) |
| 90 | { | 97 | { |
| 91 | saveAs(); | 98 | saveAs(); |
| 92 | } | 99 | } |
| 93 | else | 100 | else |
| 94 | { | 101 | { |
| 95 | IoBase *pIo = dynamic_cast<IoBase *>(centralWidget()); | 102 | IoBase *pIo = dynamic_cast<IoBase *>(centralWidget()); |
| 96 | if( !pIo ) | 103 | if( !pIo ) |
| 97 | return; | 104 | return; |
| 98 | 105 | ||
| 99 | pIo->saveTo( sCurFile ); | 106 | pIo->saveTo( sCurFile ); |
| 100 | } | 107 | } |
| 101 | } | 108 | } |
| 102 | 109 | ||
| 103 | void MainWnd::saveAs() | 110 | void MainWnd::saveAs() |
| 104 | { | 111 | { |
| 105 | IoBase *pIo = dynamic_cast<IoBase *>(centralWidget()); | 112 | IoBase *pIo = dynamic_cast<IoBase *>(centralWidget()); |
| 106 | if( !pIo ) | 113 | if( !pIo ) |
| 107 | return; | 114 | return; |
| 108 | 115 | ||
| 109 | QString sFile = QFileDialog::getSaveFileName( | 116 | QString sFile = QFileDialog::getSaveFileName( |
| 110 | this, "Gats Console - save gats file" | 117 | this, "Gats Console - save gats file" |
| 111 | ); | 118 | ); |
| 112 | if( sFile.isEmpty() ) | 119 | if( sFile.isEmpty() ) |
| 113 | return; | 120 | return; |
| 114 | 121 | ||
| 115 | pIo->saveTo( sFile ); | 122 | pIo->saveTo( sFile ); |
| 116 | 123 | ||
| 117 | sCurFile = sFile; | 124 | sCurFile = sFile; |
| 118 | } | 125 | } |
| 119 | 126 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef MAIN_WND_H | 8 | #ifndef MAIN_WND_H |
| 2 | #define MAIN_WND_H | 9 | #define MAIN_WND_H |
| 3 | 10 | ||
| @@ -5,22 +12,22 @@ | |||
| 5 | 12 | ||
| 6 | class MainWnd : public QMainWindow, protected Ui::MainWnd | 13 | class MainWnd : public QMainWindow, protected Ui::MainWnd |
| 7 | { | 14 | { |
| 8 | Q_OBJECT; | 15 | Q_OBJECT; |
| 9 | public: | 16 | public: |
| 10 | MainWnd(); | 17 | MainWnd(); |
| 11 | virtual ~MainWnd(); | 18 | virtual ~MainWnd(); |
| 12 | 19 | ||
| 13 | public slots: | 20 | public slots: |
| 14 | void connect(); | 21 | void connect(); |
| 15 | void proxy(); | 22 | void proxy(); |
| 16 | void open(); | 23 | void open(); |
| 17 | void newFile(); | 24 | void newFile(); |
| 18 | void save(); | 25 | void save(); |
| 19 | void saveAs(); | 26 | void saveAs(); |
| 20 | 27 | ||
| 21 | private: | 28 | private: |
| 22 | QString sCurFile; | 29 | QString sCurFile; |
| 23 | class QLabel *pMode; | 30 | class QLabel *pMode; |
| 24 | }; | 31 | }; |
| 25 | 32 | ||
| 26 | #endif | 33 | #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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "proxythread.h" | 8 | #include "proxythread.h" |
| 2 | 9 | ||
| 3 | #include <gats/types.h> | 10 | #include <gats/types.h> |
| @@ -10,15 +17,15 @@ | |||
| 10 | using namespace Bu; | 17 | using namespace Bu; |
| 11 | 18 | ||
| 12 | ProxyThread::ProxyThread( QObject *pParent, int iPortIn, | 19 | ProxyThread::ProxyThread( QObject *pParent, int iPortIn, |
| 13 | const QByteArray &baHostOut, int iPortOut ) : | 20 | const QByteArray &baHostOut, int iPortOut ) : |
| 14 | QThread( pParent ), | 21 | QThread( pParent ), |
| 15 | pHost( NULL ), | 22 | pHost( NULL ), |
| 16 | iPortIn( iPortIn ), | 23 | iPortIn( iPortIn ), |
| 17 | baHostOut( baHostOut ), | 24 | baHostOut( baHostOut ), |
| 18 | iPortOut( iPortOut ), | 25 | iPortOut( iPortOut ), |
| 19 | gsCli( ssCli ) | 26 | gsCli( ssCli ) |
| 20 | { | 27 | { |
| 21 | pHost = new ProxyHostThread( pParent, this ); | 28 | pHost = new ProxyHostThread( pParent, this ); |
| 22 | } | 29 | } |
| 23 | 30 | ||
| 24 | ProxyThread::~ProxyThread() | 31 | ProxyThread::~ProxyThread() |
| @@ -27,52 +34,52 @@ ProxyThread::~ProxyThread() | |||
| 27 | 34 | ||
| 28 | void ProxyThread::send( Gats::Object *pObj ) | 35 | void ProxyThread::send( Gats::Object *pObj ) |
| 29 | { | 36 | { |
| 30 | MemBuf bg; | 37 | MemBuf bg; |
| 31 | Gats::GatsStream gs( bg ); | 38 | Gats::GatsStream gs( bg ); |
| 32 | gs.writeObject( pObj ); | 39 | gs.writeObject( pObj ); |
| 33 | ssCli.write( bg.getString().getStr(), bg.getString().getSize() ); | 40 | ssCli.write( bg.getString().getStr(), bg.getString().getSize() ); |
| 34 | } | 41 | } |
| 35 | 42 | ||
| 36 | void ProxyThread::run() | 43 | void ProxyThread::run() |
| 37 | { | 44 | { |
| 38 | int iSockIn; | 45 | int iSockIn; |
| 39 | 46 | ||
| 40 | { | 47 | { |
| 41 | TcpServerSocket tsIn( iPortIn ); | 48 | TcpServerSocket tsIn( iPortIn ); |
| 42 | do | 49 | do |
| 43 | { | 50 | { |
| 44 | iSockIn = tsIn.accept( 5 ); | 51 | iSockIn = tsIn.accept( 5 ); |
| 45 | } while( iSockIn < 0 ); | 52 | } while( iSockIn < 0 ); |
| 46 | } | 53 | } |
| 47 | 54 | ||
| 48 | emit gotConnection(); | 55 | emit gotConnection(); |
| 49 | 56 | ||
| 50 | ssCli.setStream( new TcpSocket( iSockIn ) ); | 57 | ssCli.setStream( new TcpSocket( iSockIn ) ); |
| 51 | ssCli.setBlocking( true ); | 58 | ssCli.setBlocking( true ); |
| 52 | 59 | ||
| 53 | pHost->setStream( | 60 | pHost->setStream( |
| 54 | new TcpSocket( baHostOut.constData(), iPortOut ) | 61 | new TcpSocket( baHostOut.constData(), iPortOut ) |
| 55 | ); | 62 | ); |
| 56 | 63 | ||
| 57 | pHost->start(); | 64 | pHost->start(); |
| 58 | 65 | ||
| 59 | while( !ssCli.isEos() ) | 66 | while( !ssCli.isEos() ) |
| 60 | { | 67 | { |
| 61 | Gats::Object *pObj = gsCli.readObject(); | 68 | Gats::Object *pObj = gsCli.readObject(); |
| 62 | if( pObj == NULL ) | 69 | if( pObj == NULL ) |
| 63 | continue; | 70 | continue; |
| 64 | 71 | ||
| 65 | pHost->send( pObj ); | 72 | pHost->send( pObj ); |
| 66 | emit recv( pObj ); | 73 | emit recv( pObj ); |
| 67 | } | 74 | } |
| 68 | 75 | ||
| 69 | } | 76 | } |
| 70 | 77 | ||
| 71 | ProxyHostThread::ProxyHostThread( QObject *pParent, ProxyThread *pClient ) : | 78 | ProxyHostThread::ProxyHostThread( QObject *pParent, ProxyThread *pClient ) : |
| 72 | QThread( pParent ), | 79 | QThread( pParent ), |
| 73 | pClient( pClient ), | 80 | pClient( pClient ), |
| 74 | ssHst(), | 81 | ssHst(), |
| 75 | gsHst( ssHst ) | 82 | gsHst( ssHst ) |
| 76 | { | 83 | { |
| 77 | } | 84 | } |
| 78 | 85 | ||
| @@ -82,27 +89,27 @@ ProxyHostThread::~ProxyHostThread() | |||
| 82 | 89 | ||
| 83 | void ProxyHostThread::send( Gats::Object *pObj ) | 90 | void ProxyHostThread::send( Gats::Object *pObj ) |
| 84 | { | 91 | { |
| 85 | MemBuf bg; | 92 | MemBuf bg; |
| 86 | Gats::GatsStream gs( bg ); | 93 | Gats::GatsStream gs( bg ); |
| 87 | gs.writeObject( pObj ); | 94 | gs.writeObject( pObj ); |
| 88 | ssHst.write( bg.getString().getStr(), bg.getString().getSize() ); | 95 | ssHst.write( bg.getString().getStr(), bg.getString().getSize() ); |
| 89 | } | 96 | } |
| 90 | 97 | ||
| 91 | void ProxyHostThread::setStream( Bu::Stream *pStr ) | 98 | void ProxyHostThread::setStream( Bu::Stream *pStr ) |
| 92 | { | 99 | { |
| 93 | ssHst.setStream( pStr ); | 100 | ssHst.setStream( pStr ); |
| 94 | } | 101 | } |
| 95 | 102 | ||
| 96 | void ProxyHostThread::run() | 103 | void ProxyHostThread::run() |
| 97 | { | 104 | { |
| 98 | while( !ssHst.isEos() ) | 105 | while( !ssHst.isEos() ) |
| 99 | { | 106 | { |
| 100 | Gats::Object *pObj = gsHst.readObject(); | 107 | Gats::Object *pObj = gsHst.readObject(); |
| 101 | if( pObj == NULL ) | 108 | if( pObj == NULL ) |
| 102 | continue; | 109 | continue; |
| 103 | 110 | ||
| 104 | pClient->send( pObj ); | 111 | pClient->send( pObj ); |
| 105 | emit recv( pObj ); | 112 | emit recv( pObj ); |
| 106 | } | 113 | } |
| 107 | } | 114 | } |
| 108 | 115 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef PROXY_THREAD_H | 8 | #ifndef PROXY_THREAD_H |
| 2 | #define PROXY_THREAD_H | 9 | #define PROXY_THREAD_H |
| 3 | 10 | ||
| @@ -8,53 +15,53 @@ | |||
| 8 | 15 | ||
| 9 | class ProxyThread : public QThread | 16 | class ProxyThread : public QThread |
| 10 | { | 17 | { |
| 11 | Q_OBJECT; | 18 | Q_OBJECT; |
| 12 | public: | 19 | public: |
| 13 | ProxyThread( QObject *pParent, int iPortIn, const QByteArray &baHostOut, | 20 | ProxyThread( QObject *pParent, int iPortIn, const QByteArray &baHostOut, |
| 14 | int iPortOut ); | 21 | int iPortOut ); |
| 15 | virtual ~ProxyThread(); | 22 | virtual ~ProxyThread(); |
| 16 | 23 | ||
| 17 | class ProxyHostThread *pHost; | 24 | class ProxyHostThread *pHost; |
| 18 | 25 | ||
| 19 | void send( Gats::Object *pObj ); | 26 | void send( Gats::Object *pObj ); |
| 20 | 27 | ||
| 21 | signals: | 28 | signals: |
| 22 | void recv( Gats::Object *pObj ); | 29 | void recv( Gats::Object *pObj ); |
| 23 | void gotConnection(); | 30 | void gotConnection(); |
| 24 | 31 | ||
| 25 | protected: | 32 | protected: |
| 26 | virtual void run(); | 33 | virtual void run(); |
| 27 | 34 | ||
| 28 | private: | 35 | private: |
| 29 | int iPortIn; | 36 | int iPortIn; |
| 30 | QByteArray baHostOut; | 37 | QByteArray baHostOut; |
| 31 | int iPortOut; | 38 | int iPortOut; |
| 32 | 39 | ||
| 33 | Bu::StreamStack ssCli; | 40 | Bu::StreamStack ssCli; |
| 34 | Gats::GatsStream gsCli; | 41 | Gats::GatsStream gsCli; |
| 35 | }; | 42 | }; |
| 36 | 43 | ||
| 37 | class ProxyHostThread : public QThread | 44 | class ProxyHostThread : public QThread |
| 38 | { | 45 | { |
| 39 | Q_OBJECT; | 46 | Q_OBJECT; |
| 40 | public: | 47 | public: |
| 41 | ProxyHostThread( QObject *pParent, ProxyThread *pClient ); | 48 | ProxyHostThread( QObject *pParent, ProxyThread *pClient ); |
| 42 | virtual ~ProxyHostThread(); | 49 | virtual ~ProxyHostThread(); |
| 43 | 50 | ||
| 44 | void send( Gats::Object *pObj ); | 51 | void send( Gats::Object *pObj ); |
| 45 | 52 | ||
| 46 | void setStream( Bu::Stream *pStr ); | 53 | void setStream( Bu::Stream *pStr ); |
| 47 | 54 | ||
| 48 | signals: | 55 | signals: |
| 49 | void recv( Gats::Object *pObj ); | 56 | void recv( Gats::Object *pObj ); |
| 50 | 57 | ||
| 51 | protected: | 58 | protected: |
| 52 | virtual void run(); | 59 | virtual void run(); |
| 53 | 60 | ||
| 54 | private: | 61 | private: |
| 55 | ProxyThread *pClient; | 62 | ProxyThread *pClient; |
| 56 | Bu::StreamStack ssHst; | 63 | Bu::StreamStack ssHst; |
| 57 | Gats::GatsStream gsHst; | 64 | Gats::GatsStream gsHst; |
| 58 | }; | 65 | }; |
| 59 | 66 | ||
| 60 | #endif | 67 | #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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "proxywidget.h" | 8 | #include "proxywidget.h" |
| 2 | #include "proxythread.h" | 9 | #include "proxythread.h" |
| 3 | 10 | ||
| @@ -14,22 +21,22 @@ | |||
| 14 | using namespace Bu; | 21 | using namespace Bu; |
| 15 | 22 | ||
| 16 | ProxyWidget::ProxyWidget( QWidget *pParent, int iPortIn, | 23 | ProxyWidget::ProxyWidget( QWidget *pParent, int iPortIn, |
| 17 | const QByteArray baHost, int iPortOut ) : | 24 | const QByteArray baHost, int iPortOut ) : |
| 18 | QWidget( pParent ), | 25 | QWidget( pParent ), |
| 19 | pPrx( NULL ) | 26 | pPrx( NULL ) |
| 20 | { | 27 | { |
| 21 | setupUi( this ); | 28 | setupUi( this ); |
| 22 | 29 | ||
| 23 | pPrx = new ProxyThread( this, iPortIn, baHost, iPortOut ); | 30 | pPrx = new ProxyThread( this, iPortIn, baHost, iPortOut ); |
| 24 | 31 | ||
| 25 | connect( pPrx, SIGNAL(gotConnection()), | 32 | connect( pPrx, SIGNAL(gotConnection()), |
| 26 | this, SLOT(gotConnection()), Qt::QueuedConnection ); | 33 | this, SLOT(gotConnection()), Qt::QueuedConnection ); |
| 27 | connect( pPrx, SIGNAL(recv( Gats::Object *)), | 34 | connect( pPrx, SIGNAL(recv( Gats::Object *)), |
| 28 | this, SLOT(clientRecv(Gats::Object *)), Qt::QueuedConnection ); | 35 | this, SLOT(clientRecv(Gats::Object *)), Qt::QueuedConnection ); |
| 29 | connect( pPrx->pHost, SIGNAL(recv( Gats::Object *)), | 36 | connect( pPrx->pHost, SIGNAL(recv( Gats::Object *)), |
| 30 | this, SLOT(hostRecv(Gats::Object *)), Qt::QueuedConnection ); | 37 | this, SLOT(hostRecv(Gats::Object *)), Qt::QueuedConnection ); |
| 31 | 38 | ||
| 32 | pPrx->start(); | 39 | pPrx->start(); |
| 33 | } | 40 | } |
| 34 | 41 | ||
| 35 | ProxyWidget::~ProxyWidget() | 42 | ProxyWidget::~ProxyWidget() |
| @@ -38,94 +45,94 @@ ProxyWidget::~ProxyWidget() | |||
| 38 | 45 | ||
| 39 | void ProxyWidget::saveTo( const QString &sFile ) | 46 | void ProxyWidget::saveTo( const QString &sFile ) |
| 40 | { | 47 | { |
| 41 | File fOut( sFile.toAscii().constData(), File::WriteNew ); | 48 | File fOut( sFile.toAscii().constData(), File::WriteNew ); |
| 42 | Gats::GatsStream gsOut( fOut ); | 49 | Gats::GatsStream gsOut( fOut ); |
| 43 | QTreeWidgetItem *pRoot = twHistory->invisibleRootItem(); | 50 | QTreeWidgetItem *pRoot = twHistory->invisibleRootItem(); |
| 44 | for( int j = 0; j < pRoot->childCount(); j++ ) | 51 | for( int j = 0; j < pRoot->childCount(); j++ ) |
| 45 | { | 52 | { |
| 46 | Gats::Object *pObj = treeToGats( pRoot->child( j ) ); | 53 | Gats::Object *pObj = treeToGats( pRoot->child( j ) ); |
| 47 | gsOut.writeObject( pObj ); | 54 | gsOut.writeObject( pObj ); |
| 48 | delete pObj; | 55 | delete pObj; |
| 49 | } | 56 | } |
| 50 | } | 57 | } |
| 51 | 58 | ||
| 52 | void ProxyWidget::sendToClient() | 59 | void ProxyWidget::sendToClient() |
| 53 | { | 60 | { |
| 54 | try | 61 | try |
| 55 | { | 62 | { |
| 56 | Gats::Object *pObj = Gats::Object::strToGats( | 63 | Gats::Object *pObj = Gats::Object::strToGats( |
| 57 | leGats->text().toAscii().constData() | 64 | leGats->text().toAscii().constData() |
| 58 | ); | 65 | ); |
| 59 | sio << "Send: " << *pObj << sio.nl; | 66 | sio << "Send: " << *pObj << sio.nl; |
| 60 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | 67 | QTreeWidgetItem *pIt = new QTreeWidgetItem( |
| 61 | twHistory->invisibleRootItem() | 68 | twHistory->invisibleRootItem() |
| 62 | ); | 69 | ); |
| 63 | pIt->setText( 0, "proxy -> client" ); | 70 | pIt->setText( 0, "proxy -> client" ); |
| 64 | gatsToTree( pIt, pObj ); | 71 | gatsToTree( pIt, pObj ); |
| 65 | pPrx->send( pObj ); | 72 | pPrx->send( pObj ); |
| 66 | delete pObj; | 73 | delete pObj; |
| 67 | 74 | ||
| 68 | leGats->setText(""); | 75 | leGats->setText(""); |
| 69 | leGats->setFocus(); | 76 | leGats->setFocus(); |
| 70 | } | 77 | } |
| 71 | catch( Bu::ExceptionBase &e ) | 78 | catch( Bu::ExceptionBase &e ) |
| 72 | { | 79 | { |
| 73 | QMessageBox::critical( this, "Gats Console - Error", e.what() ); | 80 | QMessageBox::critical( this, "Gats Console - Error", e.what() ); |
| 74 | } | 81 | } |
| 75 | } | 82 | } |
| 76 | 83 | ||
| 77 | void ProxyWidget::sendToServer() | 84 | void ProxyWidget::sendToServer() |
| 78 | { | 85 | { |
| 79 | try | 86 | try |
| 80 | { | 87 | { |
| 81 | Gats::Object *pObj = Gats::Object::strToGats( | 88 | Gats::Object *pObj = Gats::Object::strToGats( |
| 82 | leGats->text().toAscii().constData() | 89 | leGats->text().toAscii().constData() |
| 83 | ); | 90 | ); |
| 84 | sio << "Send: " << *pObj << sio.nl; | 91 | sio << "Send: " << *pObj << sio.nl; |
| 85 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | 92 | QTreeWidgetItem *pIt = new QTreeWidgetItem( |
| 86 | twHistory->invisibleRootItem() | 93 | twHistory->invisibleRootItem() |
| 87 | ); | 94 | ); |
| 88 | pIt->setText( 0, "proxy -> host" ); | 95 | pIt->setText( 0, "proxy -> host" ); |
| 89 | gatsToTree( pIt, pObj ); | 96 | gatsToTree( pIt, pObj ); |
| 90 | pPrx->pHost->send( pObj ); | 97 | pPrx->pHost->send( pObj ); |
| 91 | delete pObj; | 98 | delete pObj; |
| 92 | 99 | ||
| 93 | leGats->setText(""); | 100 | leGats->setText(""); |
| 94 | leGats->setFocus(); | 101 | leGats->setFocus(); |
| 95 | } | 102 | } |
| 96 | catch( Bu::ExceptionBase &e ) | 103 | catch( Bu::ExceptionBase &e ) |
| 97 | { | 104 | { |
| 98 | QMessageBox::critical( this, "Gats Console - Error", e.what() ); | 105 | QMessageBox::critical( this, "Gats Console - Error", e.what() ); |
| 99 | } | 106 | } |
| 100 | } | 107 | } |
| 101 | 108 | ||
| 102 | void ProxyWidget::clientRecv( Gats::Object *pObj ) | 109 | void ProxyWidget::clientRecv( Gats::Object *pObj ) |
| 103 | { | 110 | { |
| 104 | sio << "Recv: " << *pObj << sio.nl; | 111 | sio << "Recv: " << *pObj << sio.nl; |
| 105 | 112 | ||
| 106 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | 113 | QTreeWidgetItem *pIt = new QTreeWidgetItem( |
| 107 | twHistory->invisibleRootItem() | 114 | twHistory->invisibleRootItem() |
| 108 | ); | 115 | ); |
| 109 | pIt->setText( 0, "client -> host" ); | 116 | pIt->setText( 0, "client -> host" ); |
| 110 | gatsToTree( pIt, pObj ); | 117 | gatsToTree( pIt, pObj ); |
| 111 | delete pObj; | 118 | delete pObj; |
| 112 | } | 119 | } |
| 113 | 120 | ||
| 114 | void ProxyWidget::hostRecv( Gats::Object *pObj ) | 121 | void ProxyWidget::hostRecv( Gats::Object *pObj ) |
| 115 | { | 122 | { |
| 116 | sio << "Recv: " << *pObj << sio.nl; | 123 | sio << "Recv: " << *pObj << sio.nl; |
| 117 | 124 | ||
| 118 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | 125 | QTreeWidgetItem *pIt = new QTreeWidgetItem( |
| 119 | twHistory->invisibleRootItem() | 126 | twHistory->invisibleRootItem() |
| 120 | ); | 127 | ); |
| 121 | pIt->setText( 0, "host -> client" ); | 128 | pIt->setText( 0, "host -> client" ); |
| 122 | gatsToTree( pIt, pObj ); | 129 | gatsToTree( pIt, pObj ); |
| 123 | delete pObj; | 130 | delete pObj; |
| 124 | } | 131 | } |
| 125 | 132 | ||
| 126 | void ProxyWidget::gotConnection() | 133 | void ProxyWidget::gotConnection() |
| 127 | { | 134 | { |
| 128 | lwConnect->stop(); | 135 | lwConnect->stop(); |
| 129 | swRoot->setCurrentIndex( 1 ); | 136 | swRoot->setCurrentIndex( 1 ); |
| 130 | } | 137 | } |
| 131 | 138 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef PROXY_WIDGET_H | 8 | #ifndef PROXY_WIDGET_H |
| 2 | #define PROXY_WIDGET_H | 9 | #define PROXY_WIDGET_H |
| 3 | 10 | ||
| @@ -6,28 +13,28 @@ | |||
| 6 | 13 | ||
| 7 | namespace Gats | 14 | namespace Gats |
| 8 | { | 15 | { |
| 9 | class Object; | 16 | class Object; |
| 10 | }; | 17 | }; |
| 11 | 18 | ||
| 12 | class ProxyWidget : public QWidget, protected Ui::ProxyWidget, public IoBase | 19 | class ProxyWidget : public QWidget, protected Ui::ProxyWidget, public IoBase |
| 13 | { | 20 | { |
| 14 | Q_OBJECT; | 21 | Q_OBJECT; |
| 15 | public: | 22 | public: |
| 16 | ProxyWidget( QWidget *pParent, int iPortIn, const QByteArray baHost, | 23 | ProxyWidget( QWidget *pParent, int iPortIn, const QByteArray baHost, |
| 17 | int iPortOut ); | 24 | int iPortOut ); |
| 18 | virtual ~ProxyWidget(); | 25 | virtual ~ProxyWidget(); |
| 19 | 26 | ||
| 20 | virtual void saveTo( const QString &sFile ); | 27 | virtual void saveTo( const QString &sFile ); |
| 21 | 28 | ||
| 22 | public slots: | 29 | public slots: |
| 23 | void sendToClient(); | 30 | void sendToClient(); |
| 24 | void sendToServer(); | 31 | void sendToServer(); |
| 25 | void clientRecv( Gats::Object *pObj ); | 32 | void clientRecv( Gats::Object *pObj ); |
| 26 | void hostRecv( Gats::Object *pObj ); | 33 | void hostRecv( Gats::Object *pObj ); |
| 27 | void gotConnection(); | 34 | void gotConnection(); |
| 28 | 35 | ||
| 29 | private: | 36 | private: |
| 30 | class ProxyThread *pPrx; | 37 | class ProxyThread *pPrx; |
| 31 | }; | 38 | }; |
| 32 | 39 | ||
| 33 | #endif | 40 | #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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "setupproxydlg.h" | 8 | #include "setupproxydlg.h" |
| 2 | 9 | ||
| 3 | SetupProxyDlg::SetupProxyDlg( QWidget *pParent ) : | 10 | SetupProxyDlg::SetupProxyDlg( QWidget *pParent ) : |
| 4 | QDialog( pParent ) | 11 | QDialog( pParent ) |
| 5 | { | 12 | { |
| 6 | setupUi( this ); | 13 | setupUi( this ); |
| 7 | } | 14 | } |
| 8 | 15 | ||
| 9 | SetupProxyDlg::~SetupProxyDlg() | 16 | SetupProxyDlg::~SetupProxyDlg() |
| @@ -12,16 +19,16 @@ SetupProxyDlg::~SetupProxyDlg() | |||
| 12 | 19 | ||
| 13 | int SetupProxyDlg::getPortIn() const | 20 | int SetupProxyDlg::getPortIn() const |
| 14 | { | 21 | { |
| 15 | return sbPortIn->value(); | 22 | return sbPortIn->value(); |
| 16 | } | 23 | } |
| 17 | 24 | ||
| 18 | QByteArray SetupProxyDlg::getHostOut() const | 25 | QByteArray SetupProxyDlg::getHostOut() const |
| 19 | { | 26 | { |
| 20 | return leHostOut->text().toAscii(); | 27 | return leHostOut->text().toAscii(); |
| 21 | } | 28 | } |
| 22 | 29 | ||
| 23 | int SetupProxyDlg::getPortOut() const | 30 | int SetupProxyDlg::getPortOut() const |
| 24 | { | 31 | { |
| 25 | return sbPortOut->value(); | 32 | return sbPortOut->value(); |
| 26 | } | 33 | } |
| 27 | 34 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef SETUP_PROXY_DLG_H | 8 | #ifndef SETUP_PROXY_DLG_H |
| 2 | #define SETUP_PROXY_DLG_H | 9 | #define SETUP_PROXY_DLG_H |
| 3 | 10 | ||
| @@ -5,14 +12,14 @@ | |||
| 5 | 12 | ||
| 6 | class SetupProxyDlg : public QDialog, protected Ui::SetupProxyDlg | 13 | class SetupProxyDlg : public QDialog, protected Ui::SetupProxyDlg |
| 7 | { | 14 | { |
| 8 | Q_OBJECT; | 15 | Q_OBJECT; |
| 9 | public: | 16 | public: |
| 10 | SetupProxyDlg( QWidget *pParent=NULL ); | 17 | SetupProxyDlg( QWidget *pParent=NULL ); |
| 11 | virtual ~SetupProxyDlg(); | 18 | virtual ~SetupProxyDlg(); |
| 12 | 19 | ||
| 13 | int getPortIn() const; | 20 | int getPortIn() const; |
| 14 | QByteArray getHostOut() const; | 21 | QByteArray getHostOut() const; |
| 15 | int getPortOut() const; | 22 | int getPortOut() const; |
| 16 | }; | 23 | }; |
| 17 | 24 | ||
| 18 | #endif | 25 | #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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "treetogats.h" | 8 | #include "treetogats.h" |
| 2 | 9 | ||
| 3 | #include <QTreeWidgetItem> | 10 | #include <QTreeWidgetItem> |
| @@ -6,47 +13,47 @@ | |||
| 6 | 13 | ||
| 7 | Gats::Object *treeToGats( QTreeWidgetItem *pRoot ) | 14 | Gats::Object *treeToGats( QTreeWidgetItem *pRoot ) |
| 8 | { | 15 | { |
| 9 | QString sType = pRoot->text( 1 ); | 16 | QString sType = pRoot->text( 1 ); |
| 10 | QByteArray baDat = pRoot->text( 2 ).toAscii(); | 17 | QByteArray baDat = pRoot->text( 2 ).toAscii(); |
| 11 | if( sType == "int" ) | 18 | if( sType == "int" ) |
| 12 | { | 19 | { |
| 13 | return new Gats::Integer( strtoll( baDat.constData(), NULL, 10 ) ); | 20 | return new Gats::Integer( strtoll( baDat.constData(), NULL, 10 ) ); |
| 14 | } | 21 | } |
| 15 | else if( sType == "str" ) | 22 | else if( sType == "str" ) |
| 16 | { | 23 | { |
| 17 | return new Gats::String( baDat.constData(), baDat.size() ); | 24 | return new Gats::String( baDat.constData(), baDat.size() ); |
| 18 | } | 25 | } |
| 19 | else if( sType == "float" ) | 26 | else if( sType == "float" ) |
| 20 | { | 27 | { |
| 21 | return new Gats::Float( strtod( baDat.constData(), NULL ) ); | 28 | return new Gats::Float( strtod( baDat.constData(), NULL ) ); |
| 22 | } | 29 | } |
| 23 | else if( sType == "bool" ) | 30 | else if( sType == "bool" ) |
| 24 | { | 31 | { |
| 25 | return new Gats::Boolean( baDat == "true" ); | 32 | return new Gats::Boolean( baDat == "true" ); |
| 26 | } | 33 | } |
| 27 | else if( sType == "list" ) | 34 | else if( sType == "list" ) |
| 28 | { | 35 | { |
| 29 | Gats::List *pRet = new Gats::List(); | 36 | Gats::List *pRet = new Gats::List(); |
| 30 | for( int j = 0; j < pRoot->childCount(); j++ ) | 37 | for( int j = 0; j < pRoot->childCount(); j++ ) |
| 31 | { | 38 | { |
| 32 | pRet->append( treeToGats( pRoot->child( j ) ) ); | 39 | pRet->append( treeToGats( pRoot->child( j ) ) ); |
| 33 | } | 40 | } |
| 34 | return pRet; | 41 | return pRet; |
| 35 | } | 42 | } |
| 36 | else if( sType == "dict" ) | 43 | else if( sType == "dict" ) |
| 37 | { | 44 | { |
| 38 | Gats::Dictionary *pRet = new Gats::Dictionary(); | 45 | Gats::Dictionary *pRet = new Gats::Dictionary(); |
| 39 | for( int j = 0; j < pRoot->childCount(); j++ ) | 46 | for( int j = 0; j < pRoot->childCount(); j++ ) |
| 40 | { | 47 | { |
| 41 | QTreeWidgetItem *pChild = pRoot->child( j ); | 48 | QTreeWidgetItem *pChild = pRoot->child( j ); |
| 42 | pRet->insert( | 49 | pRet->insert( |
| 43 | pChild->text( 0 ).toAscii().constData(), | 50 | pChild->text( 0 ).toAscii().constData(), |
| 44 | treeToGats( pChild ) | 51 | treeToGats( pChild ) |
| 45 | ); | 52 | ); |
| 46 | } | 53 | } |
| 47 | return pRet; | 54 | return pRet; |
| 48 | } | 55 | } |
| 49 | 56 | ||
| 50 | throw Bu::ExceptionBase("Unhandled type found."); | 57 | throw Bu::ExceptionBase("Unhandled type found."); |
| 51 | } | 58 | } |
| 52 | 59 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef TREE_TO_GATS_H | 8 | #ifndef TREE_TO_GATS_H |
| 2 | #define TREE_TO_GATS_H | 9 | #define TREE_TO_GATS_H |
| 3 | 10 | ||
| @@ -5,7 +12,7 @@ class QTreeWidgetItem; | |||
| 5 | 12 | ||
| 6 | namespace Gats | 13 | namespace Gats |
| 7 | { | 14 | { |
| 8 | class Object; | 15 | class Object; |
| 9 | }; | 16 | }; |
| 10 | 17 | ||
| 11 | Gats::Object *treeToGats( QTreeWidgetItem *pRoot ); | 18 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/gatsstream.h" | 8 | #include "gats/gatsstream.h" |
| 2 | #include "gats/object.h" | 9 | #include "gats/object.h" |
| 3 | 10 | ||
| @@ -6,7 +13,7 @@ | |||
| 6 | // using namespace Bu; | 13 | // using namespace Bu; |
| 7 | 14 | ||
| 8 | Gats::GatsStream::GatsStream( Bu::Stream &rStream ) : | 15 | Gats::GatsStream::GatsStream( Bu::Stream &rStream ) : |
| 9 | rStream( rStream ) | 16 | rStream( rStream ) |
| 10 | { | 17 | { |
| 11 | } | 18 | } |
| 12 | 19 | ||
| @@ -16,93 +23,93 @@ Gats::GatsStream::~GatsStream() | |||
| 16 | 23 | ||
| 17 | Gats::Object *Gats::GatsStream::readObject() | 24 | Gats::Object *Gats::GatsStream::readObject() |
| 18 | { | 25 | { |
| 19 | char buf[1500]; | 26 | char buf[1500]; |
| 20 | 27 | ||
| 21 | // sio << "Gats::GatsStream::readObject(): Scanning for object header." << sio.nl; | 28 | // sio << "Gats::GatsStream::readObject(): Scanning for object header." << sio.nl; |
| 22 | do | 29 | do |
| 23 | { | 30 | { |
| 24 | if( qbRead.getSize() < 5 ) | 31 | if( qbRead.getSize() < 5 ) |
| 25 | { | 32 | { |
| 26 | // sio << "Gats::GatsStream::readObject(): reading header data, need 5b, have " << qbRead.getSize() << "b." << sio.nl; | 33 | // sio << "Gats::GatsStream::readObject(): reading header data, need 5b, have " << qbRead.getSize() << "b." << sio.nl; |
| 27 | int iRead = rStream.read( buf, 5-qbRead.getSize() ); | 34 | int iRead = rStream.read( buf, 5-qbRead.getSize() ); |
| 28 | qbRead.write( buf, iRead ); | 35 | qbRead.write( buf, iRead ); |
| 29 | 36 | ||
| 30 | if( qbRead.getSize() < 5 ) | 37 | if( qbRead.getSize() < 5 ) |
| 31 | return NULL; | 38 | return NULL; |
| 32 | } | 39 | } |
| 33 | } while( !skipReadNulls() ); | 40 | } while( !skipReadNulls() ); |
| 34 | 41 | ||
| 35 | uint8_t uVer; | 42 | uint8_t uVer; |
| 36 | qbRead.peek( &uVer, 1 ); | 43 | qbRead.peek( &uVer, 1 ); |
| 37 | // sio << "Gats::GatsStream::readObject(): Packet version: " << (int)uVer << sio.nl; | 44 | // sio << "Gats::GatsStream::readObject(): Packet version: " << (int)uVer << sio.nl; |
| 38 | 45 | ||
| 39 | int32_t iSize; | 46 | int32_t iSize; |
| 40 | qbRead.peek( &iSize, 4, 1 ); | 47 | qbRead.peek( &iSize, 4, 1 ); |
| 41 | iSize = be32toh( iSize ); | 48 | iSize = be32toh( iSize ); |
| 42 | // sio << "Gats::GatsStream::readObject(): Header read, looking for " << iSize << "b, we have " << qbRead.getSize() << "b." << sio.nl; | 49 | // sio << "Gats::GatsStream::readObject(): Header read, looking for " << iSize << "b, we have " << qbRead.getSize() << "b." << sio.nl; |
| 43 | while( qbRead.getSize() < iSize ) | 50 | while( qbRead.getSize() < iSize ) |
| 44 | { | 51 | { |
| 45 | int32_t iRead = iSize - qbRead.getSize(); | 52 | int32_t iRead = iSize - qbRead.getSize(); |
| 46 | if( iRead > 1500 ) | 53 | if( iRead > 1500 ) |
| 47 | iRead = 1500; | 54 | iRead = 1500; |
| 48 | // sio << "Gats::GatsStream::readObject(): Attempting to read " << iRead << "b." << sio.nl; | 55 | // sio << "Gats::GatsStream::readObject(): Attempting to read " << iRead << "b." << sio.nl; |
| 49 | int32_t iReal = rStream.read( buf, iRead ); | 56 | int32_t iReal = rStream.read( buf, iRead ); |
| 50 | // sio << "Gats::GatsStream::readObject(): Read " << iReal << "b." << sio.nl; | 57 | // sio << "Gats::GatsStream::readObject(): Read " << iReal << "b." << sio.nl; |
| 51 | qbRead.write( buf, iReal ); | 58 | qbRead.write( buf, iReal ); |
| 52 | if( iReal < iRead ) | 59 | if( iReal < iRead ) |
| 53 | { | 60 | { |
| 54 | // sio << "Gats::GatsStream::readObject(): Insufficient data read in block, bailing on read." << sio.nl; | 61 | // sio << "Gats::GatsStream::readObject(): Insufficient data read in block, bailing on read." << sio.nl; |
| 55 | return NULL; | 62 | return NULL; |
| 56 | } | 63 | } |
| 57 | } | 64 | } |
| 58 | 65 | ||
| 59 | if( qbRead.getSize() < iSize ) | 66 | if( qbRead.getSize() < iSize ) |
| 60 | { | 67 | { |
| 61 | // sio << "Gats::GatsStream::readObject(): Somehow, we still don't have enough data, bailing." << sio.nl; | 68 | // sio << "Gats::GatsStream::readObject(): Somehow, we still don't have enough data, bailing." << sio.nl; |
| 62 | return NULL; | 69 | return NULL; |
| 63 | } | 70 | } |
| 64 | 71 | ||
| 65 | // sio << "Gats::GatsStream::readObject(): We have " << qbRead.getSize() << "b of " << iSize << "b, time to read the object." << sio.nl; | 72 | // sio << "Gats::GatsStream::readObject(): We have " << qbRead.getSize() << "b of " << iSize << "b, time to read the object." << sio.nl; |
| 66 | 73 | ||
| 67 | qbRead.seek( 5 ); | 74 | qbRead.seek( 5 ); |
| 68 | Gats::Object *pObj = Gats::Object::read( qbRead ); | 75 | Gats::Object *pObj = Gats::Object::read( qbRead ); |
| 69 | 76 | ||
| 70 | // sio << "Gats::GatsStream::readObject(): Read completed, there are " << qbRead.getSize() << "b left in the buffer." << sio.nl; | 77 | // sio << "Gats::GatsStream::readObject(): Read completed, there are " << qbRead.getSize() << "b left in the buffer." << sio.nl; |
| 71 | return pObj; | 78 | return pObj; |
| 72 | } | 79 | } |
| 73 | 80 | ||
| 74 | void Gats::GatsStream::writeObject( Gats::Object *pObject ) | 81 | void Gats::GatsStream::writeObject( Gats::Object *pObject ) |
| 75 | { | 82 | { |
| 76 | Bu::NullStream ns; | 83 | Bu::NullStream ns; |
| 77 | pObject->write( ns ); | 84 | pObject->write( ns ); |
| 78 | 85 | ||
| 79 | uint8_t uBuf = 1; | 86 | uint8_t uBuf = 1; |
| 80 | int32_t iSize = htobe32( ns.tell()+5 ); | 87 | int32_t iSize = htobe32( ns.tell()+5 ); |
| 81 | rStream.write( &uBuf, 1 ); | 88 | rStream.write( &uBuf, 1 ); |
| 82 | rStream.write( &iSize, 4 ); | 89 | rStream.write( &iSize, 4 ); |
| 83 | pObject->write( rStream ); | 90 | pObject->write( rStream ); |
| 84 | 91 | ||
| 85 | // sio << "Object consumed " << ns.tell() << "b." << sio.nl; | 92 | // sio << "Object consumed " << ns.tell() << "b." << sio.nl; |
| 86 | } | 93 | } |
| 87 | 94 | ||
| 88 | bool Gats::GatsStream::skipReadNulls() | 95 | bool Gats::GatsStream::skipReadNulls() |
| 89 | { | 96 | { |
| 90 | char buf; | 97 | char buf; |
| 91 | 98 | ||
| 92 | // sio << "Gats::GatsStream::skipReadNulls(): Scanning for nulls, " << qbRead.getSize() << "b." << sio.nl; | 99 | // sio << "Gats::GatsStream::skipReadNulls(): Scanning for nulls, " << qbRead.getSize() << "b." << sio.nl; |
| 93 | bool bHaveSeeked = false; | 100 | bool bHaveSeeked = false; |
| 94 | for(;;) | 101 | for(;;) |
| 95 | { | 102 | { |
| 96 | if( qbRead.peek( &buf, 1 ) == 0 ) | 103 | if( qbRead.peek( &buf, 1 ) == 0 ) |
| 97 | return false; | 104 | return false; |
| 98 | if( buf != 0 ) | 105 | if( buf != 0 ) |
| 99 | return !bHaveSeeked; //true; | 106 | return !bHaveSeeked; //true; |
| 100 | else | 107 | else |
| 101 | { | 108 | { |
| 102 | // sio << "Gats::GatsStream::skipReadNulls(): Null byte read, not header yet..." << sio.nl; | 109 | // sio << "Gats::GatsStream::skipReadNulls(): Null byte read, not header yet..." << sio.nl; |
| 103 | qbRead.seek( 1 ); | 110 | qbRead.seek( 1 ); |
| 104 | bHaveSeeked = true; | 111 | bHaveSeeked = true; |
| 105 | } | 112 | } |
| 106 | } | 113 | } |
| 107 | } | 114 | } |
| 108 | 115 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef GATS_STREAM_H | 8 | #ifndef GATS_STREAM_H |
| 2 | #define GATS_STREAM_H | 9 | #define GATS_STREAM_H |
| 3 | 10 | ||
| @@ -6,51 +13,51 @@ | |||
| 6 | 13 | ||
| 7 | namespace Gats | 14 | namespace Gats |
| 8 | { | 15 | { |
| 9 | class Object; | 16 | class Object; |
| 10 | 17 | ||
| 11 | class GatsStream | 18 | class GatsStream |
| 12 | { | 19 | { |
| 13 | public: | 20 | public: |
| 14 | GatsStream( Bu::Stream &rStream ); | 21 | GatsStream( Bu::Stream &rStream ); |
| 15 | virtual ~GatsStream(); | 22 | virtual ~GatsStream(); |
| 16 | 23 | ||
| 17 | /** | 24 | /** |
| 18 | * Read an object packet from the assosiated stream. This will make | 25 | * Read an object packet from the assosiated stream. This will make |
| 19 | * every effort to only read exactly enough data to describe one packet, | 26 | * every effort to only read exactly enough data to describe one packet, |
| 20 | * in case you want to do other things with your stream. It will | 27 | * in case you want to do other things with your stream. It will |
| 21 | * automatically skip NULL byte spacing between packets, which makes | 28 | * automatically skip NULL byte spacing between packets, which makes |
| 22 | * a convinient padding method for encrypted data streams. Since | 29 | * a convinient padding method for encrypted data streams. Since |
| 23 | * sizing information is available in the packet header exact amounts | 30 | * sizing information is available in the packet header exact amounts |
| 24 | * of data can be read, however this function doesn't assume that it | 31 | * of data can be read, however this function doesn't assume that it |
| 25 | * can read the entire object in one operation. If it fails to read | 32 | * can read the entire object in one operation. If it fails to read |
| 26 | * a complete packet in one call, it will keep the data it's read so | 33 | * a complete packet in one call, it will keep the data it's read so |
| 27 | * far buffered and return NULL, ready for another attempt. You can | 34 | * far buffered and return NULL, ready for another attempt. You can |
| 28 | * use the function hasReadBuffer() to deterimne if readObject() | 35 | * use the function hasReadBuffer() to deterimne if readObject() |
| 29 | * has read part of an object packet or not. If readObject returns | 36 | * has read part of an object packet or not. If readObject returns |
| 30 | * non-null then hasReadBuffer should return false on it's next call. | 37 | * non-null then hasReadBuffer should return false on it's next call. |
| 31 | */ | 38 | */ |
| 32 | Gats::Object *readObject(); | 39 | Gats::Object *readObject(); |
| 33 | 40 | ||
| 34 | /** | 41 | /** |
| 35 | * Write an object | 42 | * Write an object |
| 36 | */ | 43 | */ |
| 37 | void writeObject( Gats::Object *pObject ); | 44 | void writeObject( Gats::Object *pObject ); |
| 38 | 45 | ||
| 39 | /** | 46 | /** |
| 40 | * Tells you if there is data still in the read buffer, i.e. that a | 47 | * Tells you if there is data still in the read buffer, i.e. that a |
| 41 | * packet is part way through being read. If readObject has returned | 48 | * packet is part way through being read. If readObject has returned |
| 42 | * non-null in the most recent call, this should always be false. | 49 | * non-null in the most recent call, this should always be false. |
| 43 | */ | 50 | */ |
| 44 | bool hasReadBuffer() { return qbRead.getSize() > 0; } | 51 | bool hasReadBuffer() { return qbRead.getSize() > 0; } |
| 45 | int getReadBufferSize() { return qbRead.getSize(); } | 52 | int getReadBufferSize() { return qbRead.getSize(); } |
| 46 | 53 | ||
| 47 | private: | 54 | private: |
| 48 | bool skipReadNulls(); | 55 | bool skipReadNulls(); |
| 49 | 56 | ||
| 50 | private: | 57 | private: |
| 51 | Bu::Stream &rStream; | 58 | Bu::Stream &rStream; |
| 52 | Bu::QueueBuf qbRead; | 59 | Bu::QueueBuf qbRead; |
| 53 | }; | 60 | }; |
| 54 | }; | 61 | }; |
| 55 | 62 | ||
| 56 | #endif | 63 | #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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/integer.h" | 8 | #include "gats/integer.h" |
| 2 | 9 | ||
| 3 | #include <bu/formatter.h> | 10 | #include <bu/formatter.h> |
| 4 | 11 | ||
| 5 | Gats::Integer::Integer() : | 12 | Gats::Integer::Integer() : |
| 6 | iVal( 0 ) | 13 | iVal( 0 ) |
| 7 | { | 14 | { |
| 8 | } | 15 | } |
| 9 | 16 | ||
| 10 | Gats::Integer::Integer( int64_t iVal ) : | 17 | Gats::Integer::Integer( int64_t iVal ) : |
| 11 | iVal( iVal ) | 18 | iVal( iVal ) |
| 12 | { | 19 | { |
| 13 | } | 20 | } |
| 14 | 21 | ||
| @@ -18,22 +25,22 @@ Gats::Integer::~Integer() | |||
| 18 | 25 | ||
| 19 | Gats::Object *Gats::Integer::clone() const | 26 | Gats::Object *Gats::Integer::clone() const |
| 20 | { | 27 | { |
| 21 | return new Gats::Integer( iVal ); | 28 | return new Gats::Integer( iVal ); |
| 22 | } | 29 | } |
| 23 | 30 | ||
| 24 | void Gats::Integer::write( Bu::Stream &rOut ) const | 31 | void Gats::Integer::write( Bu::Stream &rOut ) const |
| 25 | { | 32 | { |
| 26 | rOut.write("i", 1 ); | 33 | rOut.write("i", 1 ); |
| 27 | writePackedInt( rOut, iVal ); | 34 | writePackedInt( rOut, iVal ); |
| 28 | } | 35 | } |
| 29 | 36 | ||
| 30 | void Gats::Integer::read( Bu::Stream &rIn, char cType ) | 37 | void Gats::Integer::read( Bu::Stream &rIn, char cType ) |
| 31 | { | 38 | { |
| 32 | readPackedInt( rIn, iVal ); | 39 | readPackedInt( rIn, iVal ); |
| 33 | } | 40 | } |
| 34 | 41 | ||
| 35 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ) | 42 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ) |
| 36 | { | 43 | { |
| 37 | return f << "(int) " << i.getValue(); | 44 | return f << "(int) " << i.getValue(); |
| 38 | } | 45 | } |
| 39 | 46 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef GATS_INTEGER_H | 8 | #ifndef GATS_INTEGER_H |
| 2 | #define GATS_INTEGER_H | 9 | #define GATS_INTEGER_H |
| 3 | 10 | ||
| @@ -9,76 +16,76 @@ | |||
| 9 | 16 | ||
| 10 | namespace Gats | 17 | namespace Gats |
| 11 | { | 18 | { |
| 12 | class Integer : public Gats::Object | 19 | class Integer : public Gats::Object |
| 13 | { | 20 | { |
| 14 | public: | 21 | public: |
| 15 | Integer(); | 22 | Integer(); |
| 16 | Integer( int64_t iVal ); | 23 | Integer( int64_t iVal ); |
| 17 | virtual ~Integer(); | 24 | virtual ~Integer(); |
| 18 | 25 | ||
| 19 | virtual Object *clone() const; | 26 | virtual Object *clone() const; |
| 20 | 27 | ||
| 21 | virtual Type getType() const { return typeInteger; } | 28 | virtual Type getType() const { return typeInteger; } |
| 22 | int64_t getValue() const { return iVal; } | 29 | int64_t getValue() const { return iVal; } |
| 23 | 30 | ||
| 24 | virtual void write( Bu::Stream &rOut ) const; | 31 | virtual void write( Bu::Stream &rOut ) const; |
| 25 | virtual void read( Bu::Stream &rIn, char cType ); | 32 | virtual void read( Bu::Stream &rIn, char cType ); |
| 26 | 33 | ||
| 27 | template<typename itype> | 34 | template<typename itype> |
| 28 | static void readPackedInt( Bu::Stream &rStream, itype &rOut ) | 35 | static void readPackedInt( Bu::Stream &rStream, itype &rOut ) |
| 29 | { | 36 | { |
| 30 | int8_t b; | 37 | int8_t b; |
| 31 | rOut = 0; | 38 | rOut = 0; |
| 32 | bool bNeg; | 39 | bool bNeg; |
| 33 | 40 | ||
| 34 | rStream.read( &b, 1 ); | 41 | rStream.read( &b, 1 ); |
| 35 | bNeg = ( b&0x40 ); | 42 | bNeg = ( b&0x40 ); |
| 36 | rOut |= (itype(b&0x3F)); | 43 | rOut |= (itype(b&0x3F)); |
| 37 | int c = 0; | 44 | int c = 0; |
| 38 | while( (b&0x80) ) | 45 | while( (b&0x80) ) |
| 39 | { | 46 | { |
| 40 | rStream.read( &b, 1 ); | 47 | rStream.read( &b, 1 ); |
| 41 | rOut |= (itype(b&0x7F)) << (6+7*(c++)); | 48 | rOut |= (itype(b&0x7F)) << (6+7*(c++)); |
| 42 | } | 49 | } |
| 43 | if( bNeg ) rOut = -rOut; | 50 | if( bNeg ) rOut = -rOut; |
| 44 | } | 51 | } |
| 45 | 52 | ||
| 46 | template<typename itype> | 53 | template<typename itype> |
| 47 | static void writePackedInt( Bu::Stream &rStream, itype iIn ) | 54 | static void writePackedInt( Bu::Stream &rStream, itype iIn ) |
| 48 | { | 55 | { |
| 49 | uint8_t b; | 56 | uint8_t b; |
| 50 | 57 | ||
| 51 | if( iIn < 0 ) | 58 | if( iIn < 0 ) |
| 52 | { | 59 | { |
| 53 | iIn = -iIn; | 60 | iIn = -iIn; |
| 54 | b = (iIn&0x3F); | 61 | b = (iIn&0x3F); |
| 55 | if( iIn > b ) | 62 | if( iIn > b ) |
| 56 | b |= 0x80 | 0x40; | 63 | b |= 0x80 | 0x40; |
| 57 | else | 64 | else |
| 58 | b |= 0x40; | 65 | b |= 0x40; |
| 59 | } | 66 | } |
| 60 | else | 67 | else |
| 61 | { | 68 | { |
| 62 | b = (iIn&0x3F); | 69 | b = (iIn&0x3F); |
| 63 | if( iIn > b ) | 70 | if( iIn > b ) |
| 64 | b |= 0x80; | 71 | b |= 0x80; |
| 65 | } | 72 | } |
| 66 | rStream.write( &b, 1 ); | 73 | rStream.write( &b, 1 ); |
| 67 | iIn = iIn >> 6; | 74 | iIn = iIn >> 6; |
| 68 | 75 | ||
| 69 | while( iIn ) | 76 | while( iIn ) |
| 70 | { | 77 | { |
| 71 | b = (iIn&0x7F); | 78 | b = (iIn&0x7F); |
| 72 | if( iIn > b ) | 79 | if( iIn > b ) |
| 73 | b |= 0x80; | 80 | b |= 0x80; |
| 74 | rStream.write( &b, 1 ); | 81 | rStream.write( &b, 1 ); |
| 75 | iIn = iIn >> 7; | 82 | iIn = iIn >> 7; |
| 76 | } | 83 | } |
| 77 | } | 84 | } |
| 78 | 85 | ||
| 79 | private: | 86 | private: |
| 80 | int64_t iVal; | 87 | int64_t iVal; |
| 81 | }; | 88 | }; |
| 82 | }; | 89 | }; |
| 83 | 90 | ||
| 84 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); | 91 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/list.h" | 8 | #include "gats/list.h" |
| 2 | 9 | ||
| 3 | #include "gats/string.h" | 10 | #include "gats/string.h" |
| @@ -15,191 +22,191 @@ Gats::List::List() | |||
| 15 | 22 | ||
| 16 | Gats::List::~List() | 23 | Gats::List::~List() |
| 17 | { | 24 | { |
| 18 | for( iterator i = begin(); i; i++ ) | 25 | for( iterator i = begin(); i; i++ ) |
| 19 | { | 26 | { |
| 20 | delete *i; | 27 | delete *i; |
| 21 | } | 28 | } |
| 22 | } | 29 | } |
| 23 | 30 | ||
| 24 | Gats::Object *Gats::List::clone() const | 31 | Gats::Object *Gats::List::clone() const |
| 25 | { | 32 | { |
| 26 | Gats::List *pClone = new Gats::List; | 33 | Gats::List *pClone = new Gats::List; |
| 27 | for( const_iterator i = begin(); i; i++ ) | 34 | for( const_iterator i = begin(); i; i++ ) |
| 28 | { | 35 | { |
| 29 | pClone->append( (*i)->clone() ); | 36 | pClone->append( (*i)->clone() ); |
| 30 | } | 37 | } |
| 31 | return pClone; | 38 | return pClone; |
| 32 | } | 39 | } |
| 33 | 40 | ||
| 34 | void Gats::List::write( Bu::Stream &rOut ) const | 41 | void Gats::List::write( Bu::Stream &rOut ) const |
| 35 | { | 42 | { |
| 36 | rOut.write("l", 1 ); | 43 | rOut.write("l", 1 ); |
| 37 | for( const_iterator i = begin(); i; i++ ) | 44 | for( const_iterator i = begin(); i; i++ ) |
| 38 | { | 45 | { |
| 39 | (*i)->write( rOut ); | 46 | (*i)->write( rOut ); |
| 40 | } | 47 | } |
| 41 | rOut.write("e", 1 ); | 48 | rOut.write("e", 1 ); |
| 42 | } | 49 | } |
| 43 | 50 | ||
| 44 | void Gats::List::read( Bu::Stream &rIn, char cType ) | 51 | void Gats::List::read( Bu::Stream &rIn, char cType ) |
| 45 | { | 52 | { |
| 46 | for(;;) | 53 | for(;;) |
| 47 | { | 54 | { |
| 48 | Gats::Object *pObj = Gats::Object::read( rIn ); | 55 | Gats::Object *pObj = Gats::Object::read( rIn ); |
| 49 | if( pObj == NULL ) | 56 | if( pObj == NULL ) |
| 50 | break; | 57 | break; |
| 51 | append( pObj ); | 58 | append( pObj ); |
| 52 | } | 59 | } |
| 53 | } | 60 | } |
| 54 | 61 | ||
| 55 | void Gats::List::append( const char *s ) | 62 | void Gats::List::append( const char *s ) |
| 56 | { | 63 | { |
| 57 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); | 64 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); |
| 58 | } | 65 | } |
| 59 | 66 | ||
| 60 | void Gats::List::append( const Bu::String &s ) | 67 | void Gats::List::append( const Bu::String &s ) |
| 61 | { | 68 | { |
| 62 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); | 69 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); |
| 63 | } | 70 | } |
| 64 | 71 | ||
| 65 | void Gats::List::append( int32_t i ) | 72 | void Gats::List::append( int32_t i ) |
| 66 | { | 73 | { |
| 67 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); | 74 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); |
| 68 | } | 75 | } |
| 69 | 76 | ||
| 70 | void Gats::List::append( int64_t i ) | 77 | void Gats::List::append( int64_t i ) |
| 71 | { | 78 | { |
| 72 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); | 79 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); |
| 73 | } | 80 | } |
| 74 | 81 | ||
| 75 | void Gats::List::append( double d ) | 82 | void Gats::List::append( double d ) |
| 76 | { | 83 | { |
| 77 | Bu::List<Gats::Object *>::append( new Gats::Float( d ) ); | 84 | Bu::List<Gats::Object *>::append( new Gats::Float( d ) ); |
| 78 | } | 85 | } |
| 79 | 86 | ||
| 80 | void Gats::List::appendStr( const Bu::String &s ) | 87 | void Gats::List::appendStr( const Bu::String &s ) |
| 81 | { | 88 | { |
| 82 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); | 89 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); |
| 83 | } | 90 | } |
| 84 | 91 | ||
| 85 | void Gats::List::appendInt( int64_t i ) | 92 | void Gats::List::appendInt( int64_t i ) |
| 86 | { | 93 | { |
| 87 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); | 94 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); |
| 88 | } | 95 | } |
| 89 | 96 | ||
| 90 | void Gats::List::appendFloat( double d ) | 97 | void Gats::List::appendFloat( double d ) |
| 91 | { | 98 | { |
| 92 | Bu::List<Gats::Object *>::append( new Gats::Float( d ) ); | 99 | Bu::List<Gats::Object *>::append( new Gats::Float( d ) ); |
| 93 | } | 100 | } |
| 94 | 101 | ||
| 95 | void Gats::List::appendBool( bool b ) | 102 | void Gats::List::appendBool( bool b ) |
| 96 | { | 103 | { |
| 97 | Bu::List<Gats::Object *>::append( new Gats::Boolean( b ) ); | 104 | Bu::List<Gats::Object *>::append( new Gats::Boolean( b ) ); |
| 98 | } | 105 | } |
| 99 | 106 | ||
| 100 | void Gats::List::appendList( Gats::List *pL ) | 107 | void Gats::List::appendList( Gats::List *pL ) |
| 101 | { | 108 | { |
| 102 | Bu::List<Gats::Object *>::append( pL ); | 109 | Bu::List<Gats::Object *>::append( pL ); |
| 103 | } | 110 | } |
| 104 | 111 | ||
| 105 | void Gats::List::appendDict( Gats::Dictionary *pD ) | 112 | void Gats::List::appendDict( Gats::Dictionary *pD ) |
| 106 | { | 113 | { |
| 107 | Bu::List<Gats::Object *>::append( pD ); | 114 | Bu::List<Gats::Object *>::append( pD ); |
| 108 | } | 115 | } |
| 109 | 116 | ||
| 110 | Gats::List *Gats::List::appendList() | 117 | Gats::List *Gats::List::appendList() |
| 111 | { | 118 | { |
| 112 | Gats::List *pLst = new Gats::List(); | 119 | Gats::List *pLst = new Gats::List(); |
| 113 | appendList( pLst ); | 120 | appendList( pLst ); |
| 114 | return pLst; | 121 | return pLst; |
| 115 | } | 122 | } |
| 116 | 123 | ||
| 117 | Gats::Dictionary *Gats::List::appendDict() | 124 | Gats::Dictionary *Gats::List::appendDict() |
| 118 | { | 125 | { |
| 119 | Gats::Dictionary *pDict = new Gats::Dictionary(); | 126 | Gats::Dictionary *pDict = new Gats::Dictionary(); |
| 120 | appendDict( pDict ); | 127 | appendDict( pDict ); |
| 121 | return pDict; | 128 | return pDict; |
| 122 | } | 129 | } |
| 123 | 130 | ||
| 124 | void Gats::List::prepend( const char *s ) | 131 | void Gats::List::prepend( const char *s ) |
| 125 | { | 132 | { |
| 126 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); | 133 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); |
| 127 | } | 134 | } |
| 128 | 135 | ||
| 129 | void Gats::List::prepend( const Bu::String &s ) | 136 | void Gats::List::prepend( const Bu::String &s ) |
| 130 | { | 137 | { |
| 131 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); | 138 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); |
| 132 | } | 139 | } |
| 133 | 140 | ||
| 134 | void Gats::List::prepend( int32_t i ) | 141 | void Gats::List::prepend( int32_t i ) |
| 135 | { | 142 | { |
| 136 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); | 143 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); |
| 137 | } | 144 | } |
| 138 | 145 | ||
| 139 | void Gats::List::prepend( int64_t i ) | 146 | void Gats::List::prepend( int64_t i ) |
| 140 | { | 147 | { |
| 141 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); | 148 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); |
| 142 | } | 149 | } |
| 143 | 150 | ||
| 144 | void Gats::List::prepend( double d ) | 151 | void Gats::List::prepend( double d ) |
| 145 | { | 152 | { |
| 146 | Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) ); | 153 | Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) ); |
| 147 | } | 154 | } |
| 148 | 155 | ||
| 149 | void Gats::List::prependStr( const Bu::String &s ) | 156 | void Gats::List::prependStr( const Bu::String &s ) |
| 150 | { | 157 | { |
| 151 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); | 158 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); |
| 152 | } | 159 | } |
| 153 | 160 | ||
| 154 | void Gats::List::prependInt( int64_t i ) | 161 | void Gats::List::prependInt( int64_t i ) |
| 155 | { | 162 | { |
| 156 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); | 163 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); |
| 157 | } | 164 | } |
| 158 | 165 | ||
| 159 | void Gats::List::prependFloat( double d ) | 166 | void Gats::List::prependFloat( double d ) |
| 160 | { | 167 | { |
| 161 | Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) ); | 168 | Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) ); |
| 162 | } | 169 | } |
| 163 | 170 | ||
| 164 | void Gats::List::prependBool( bool b ) | 171 | void Gats::List::prependBool( bool b ) |
| 165 | { | 172 | { |
| 166 | Bu::List<Gats::Object *>::prepend( new Gats::Boolean( b ) ); | 173 | Bu::List<Gats::Object *>::prepend( new Gats::Boolean( b ) ); |
| 167 | } | 174 | } |
| 168 | 175 | ||
| 169 | void Gats::List::prependList( Gats::List *pL ) | 176 | void Gats::List::prependList( Gats::List *pL ) |
| 170 | { | 177 | { |
| 171 | Bu::List<Gats::Object *>::prepend( pL ); | 178 | Bu::List<Gats::Object *>::prepend( pL ); |
| 172 | } | 179 | } |
| 173 | 180 | ||
| 174 | void Gats::List::prependDict( Gats::Dictionary *pD ) | 181 | void Gats::List::prependDict( Gats::Dictionary *pD ) |
| 175 | { | 182 | { |
| 176 | Bu::List<Gats::Object *>::prepend( pD ); | 183 | Bu::List<Gats::Object *>::prepend( pD ); |
| 177 | } | 184 | } |
| 178 | 185 | ||
| 179 | Gats::List *Gats::List::prependList() | 186 | Gats::List *Gats::List::prependList() |
| 180 | { | 187 | { |
| 181 | Gats::List *pLst = new Gats::List(); | 188 | Gats::List *pLst = new Gats::List(); |
| 182 | prependList( pLst ); | 189 | prependList( pLst ); |
| 183 | return pLst; | 190 | return pLst; |
| 184 | } | 191 | } |
| 185 | 192 | ||
| 186 | Gats::Dictionary *Gats::List::prependDict() | 193 | Gats::Dictionary *Gats::List::prependDict() |
| 187 | { | 194 | { |
| 188 | Gats::Dictionary *pDict = new Gats::Dictionary(); | 195 | Gats::Dictionary *pDict = new Gats::Dictionary(); |
| 189 | prependDict( pDict ); | 196 | prependDict( pDict ); |
| 190 | return pDict; | 197 | return pDict; |
| 191 | } | 198 | } |
| 192 | 199 | ||
| 193 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ) | 200 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ) |
| 194 | { | 201 | { |
| 195 | f << "(list) ["; | 202 | f << "(list) ["; |
| 196 | f.incIndent(); | 203 | f.incIndent(); |
| 197 | for( Gats::List::const_iterator i = l.begin(); i; i++ ) | 204 | for( Gats::List::const_iterator i = l.begin(); i; i++ ) |
| 198 | { | 205 | { |
| 199 | f << f.nl << **i; | 206 | f << f.nl << **i; |
| 200 | } | 207 | } |
| 201 | f.decIndent(); | 208 | f.decIndent(); |
| 202 | f << f.nl << "]"; | 209 | f << f.nl << "]"; |
| 203 | return f; | 210 | return f; |
| 204 | } | 211 | } |
| 205 | 212 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef GATS_LIST_H | 8 | #ifndef GATS_LIST_H |
| 2 | #define GATS_LIST_H | 9 | #define GATS_LIST_H |
| 3 | 10 | ||
| @@ -7,50 +14,50 @@ | |||
| 7 | 14 | ||
| 8 | namespace Gats | 15 | namespace Gats |
| 9 | { | 16 | { |
| 10 | class Dictionary; | 17 | class Dictionary; |
| 11 | 18 | ||
| 12 | class List : public Gats::Object, public Bu::List<Gats::Object *> | 19 | class List : public Gats::Object, public Bu::List<Gats::Object *> |
| 13 | { | 20 | { |
| 14 | public: | 21 | public: |
| 15 | List(); | 22 | List(); |
| 16 | virtual ~List(); | 23 | virtual ~List(); |
| 17 | 24 | ||
| 18 | virtual Object *clone() const; | 25 | virtual Object *clone() const; |
| 19 | virtual Type getType() const { return typeList; } | 26 | virtual Type getType() const { return typeList; } |
| 20 | 27 | ||
| 21 | virtual void write( Bu::Stream &rOut ) const; | 28 | virtual void write( Bu::Stream &rOut ) const; |
| 22 | virtual void read( Bu::Stream &rIn, char cType ); | 29 | virtual void read( Bu::Stream &rIn, char cType ); |
| 23 | 30 | ||
| 24 | void append( const char *s ); | 31 | void append( const char *s ); |
| 25 | void append( const Bu::String &s ); | 32 | void append( const Bu::String &s ); |
| 26 | void append( int32_t i ); | 33 | void append( int32_t i ); |
| 27 | void append( int64_t i ); | 34 | void append( int64_t i ); |
| 28 | void append( double d ); | 35 | void append( double d ); |
| 29 | using Bu::List<Gats::Object *>::append; | 36 | using Bu::List<Gats::Object *>::append; |
| 30 | void appendStr( const Bu::String &s ); | 37 | void appendStr( const Bu::String &s ); |
| 31 | void appendInt( int64_t i ); | 38 | void appendInt( int64_t i ); |
| 32 | void appendFloat( double d ); | 39 | void appendFloat( double d ); |
| 33 | void appendBool( bool b ); | 40 | void appendBool( bool b ); |
| 34 | void appendList( Gats::List *pL ); | 41 | void appendList( Gats::List *pL ); |
| 35 | void appendDict( Gats::Dictionary *pD ); | 42 | void appendDict( Gats::Dictionary *pD ); |
| 36 | Gats::List *appendList(); | 43 | Gats::List *appendList(); |
| 37 | Gats::Dictionary *appendDict(); | 44 | Gats::Dictionary *appendDict(); |
| 38 | 45 | ||
| 39 | void prepend( const char *s ); | 46 | void prepend( const char *s ); |
| 40 | void prepend( const Bu::String &s ); | 47 | void prepend( const Bu::String &s ); |
| 41 | void prepend( int32_t i ); | 48 | void prepend( int32_t i ); |
| 42 | void prepend( int64_t i ); | 49 | void prepend( int64_t i ); |
| 43 | void prepend( double d ); | 50 | void prepend( double d ); |
| 44 | using Bu::List<Gats::Object *>::prepend; | 51 | using Bu::List<Gats::Object *>::prepend; |
| 45 | void prependStr( const Bu::String &s ); | 52 | void prependStr( const Bu::String &s ); |
| 46 | void prependInt( int64_t i ); | 53 | void prependInt( int64_t i ); |
| 47 | void prependFloat( double d ); | 54 | void prependFloat( double d ); |
| 48 | void prependBool( bool b ); | 55 | void prependBool( bool b ); |
| 49 | void prependList( Gats::List *pL ); | 56 | void prependList( Gats::List *pL ); |
| 50 | void prependDict( Gats::Dictionary *pD ); | 57 | void prependDict( Gats::Dictionary *pD ); |
| 51 | Gats::List *prependList(); | 58 | Gats::List *prependList(); |
| 52 | Gats::Dictionary *prependDict(); | 59 | Gats::Dictionary *prependDict(); |
| 53 | }; | 60 | }; |
| 54 | }; | 61 | }; |
| 55 | 62 | ||
| 56 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ); | 63 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/null.h" | 8 | #include "gats/null.h" |
| 2 | 9 | ||
| 3 | #include <bu/formatter.h> | 10 | #include <bu/formatter.h> |
| @@ -13,21 +20,21 @@ Gats::Null::~Null() | |||
| 13 | 20 | ||
| 14 | Gats::Object *Gats::Null::clone() const | 21 | Gats::Object *Gats::Null::clone() const |
| 15 | { | 22 | { |
| 16 | return new Gats::Null(); | 23 | return new Gats::Null(); |
| 17 | } | 24 | } |
| 18 | 25 | ||
| 19 | void Gats::Null::write( Bu::Stream &rOut ) const | 26 | void Gats::Null::write( Bu::Stream &rOut ) const |
| 20 | { | 27 | { |
| 21 | rOut.write("n", 1 ); | 28 | rOut.write("n", 1 ); |
| 22 | } | 29 | } |
| 23 | 30 | ||
| 24 | void Gats::Null::read( Bu::Stream &rIn, char cType ) | 31 | void Gats::Null::read( Bu::Stream &rIn, char cType ) |
| 25 | { | 32 | { |
| 26 | // Nothing to do... | 33 | // Nothing to do... |
| 27 | } | 34 | } |
| 28 | 35 | ||
| 29 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ) | 36 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ) |
| 30 | { | 37 | { |
| 31 | return f << "(null)"; | 38 | return f << "(null)"; |
| 32 | } | 39 | } |
| 33 | 40 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef GATS_NULL_H | 8 | #ifndef GATS_NULL_H |
| 2 | #define GATS_NULL_H | 9 | #define GATS_NULL_H |
| 3 | 10 | ||
| @@ -5,18 +12,18 @@ | |||
| 5 | 12 | ||
| 6 | namespace Gats | 13 | namespace Gats |
| 7 | { | 14 | { |
| 8 | class Null : public Gats::Object | 15 | class Null : public Gats::Object |
| 9 | { | 16 | { |
| 10 | public: | 17 | public: |
| 11 | Null(); | 18 | Null(); |
| 12 | virtual ~Null(); | 19 | virtual ~Null(); |
| 13 | 20 | ||
| 14 | virtual Type getType() const { return typeNull; } | 21 | virtual Type getType() const { return typeNull; } |
| 15 | virtual Object *clone() const; | 22 | virtual Object *clone() const; |
| 16 | 23 | ||
| 17 | virtual void write( Bu::Stream &rOut ) const; | 24 | virtual void write( Bu::Stream &rOut ) const; |
| 18 | virtual void read( Bu::Stream &rIn, char cType ); | 25 | virtual void read( Bu::Stream &rIn, char cType ); |
| 19 | }; | 26 | }; |
| 20 | }; | 27 | }; |
| 21 | 28 | ||
| 22 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ); | 29 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/object.h" | 8 | #include "gats/object.h" |
| 2 | 9 | ||
| 3 | #include "gats/integer.h" | 10 | #include "gats/integer.h" |
| @@ -26,137 +33,137 @@ Gats::Object::~Object() | |||
| 26 | 33 | ||
| 27 | Gats::Object *Gats::Object::read( Bu::Stream &rIn ) | 34 | Gats::Object *Gats::Object::read( Bu::Stream &rIn ) |
| 28 | { | 35 | { |
| 29 | char buf; | 36 | char buf; |
| 30 | rIn.read( &buf, 1 ); | 37 | rIn.read( &buf, 1 ); |
| 31 | Object *pObj = NULL; | 38 | Object *pObj = NULL; |
| 32 | switch( buf ) | 39 | switch( buf ) |
| 33 | { | 40 | { |
| 34 | case 'i': | 41 | case 'i': |
| 35 | pObj = new Gats::Integer(); | 42 | pObj = new Gats::Integer(); |
| 36 | break; | 43 | break; |
| 37 | 44 | ||
| 38 | case 's': | 45 | case 's': |
| 39 | pObj = new Gats::String(); | 46 | pObj = new Gats::String(); |
| 40 | break; | 47 | break; |
| 41 | 48 | ||
| 42 | case '0': | 49 | case '0': |
| 43 | case '1': | 50 | case '1': |
| 44 | pObj = new Gats::Boolean(); | 51 | pObj = new Gats::Boolean(); |
| 45 | break; | 52 | break; |
| 46 | 53 | ||
| 47 | case 'l': | 54 | case 'l': |
| 48 | pObj = new Gats::List(); | 55 | pObj = new Gats::List(); |
| 49 | break; | 56 | break; |
| 50 | 57 | ||
| 51 | case 'd': | 58 | case 'd': |
| 52 | pObj = new Gats::Dictionary(); | 59 | pObj = new Gats::Dictionary(); |
| 53 | break; | 60 | break; |
| 54 | 61 | ||
| 55 | case 'f': // Normal floats | 62 | case 'f': // Normal floats |
| 56 | case 'F': // Special float values | 63 | case 'F': // Special float values |
| 57 | pObj = new Gats::Float(); | 64 | pObj = new Gats::Float(); |
| 58 | break; | 65 | break; |
| 59 | 66 | ||
| 60 | case 'n': | 67 | case 'n': |
| 61 | pObj = new Gats::Null(); | 68 | pObj = new Gats::Null(); |
| 62 | break; | 69 | break; |
| 63 | 70 | ||
| 64 | case 'e': | 71 | case 'e': |
| 65 | return NULL; | 72 | return NULL; |
| 66 | 73 | ||
| 67 | default: | 74 | default: |
| 68 | throw Bu::ExceptionBase("Invalid Gats type discovered: %c.", buf ); | 75 | throw Bu::ExceptionBase("Invalid Gats type discovered: %c.", buf ); |
| 69 | } | 76 | } |
| 70 | 77 | ||
| 71 | pObj->read( rIn, buf ); | 78 | pObj->read( rIn, buf ); |
| 72 | 79 | ||
| 73 | return pObj; | 80 | return pObj; |
| 74 | } | 81 | } |
| 75 | 82 | ||
| 76 | void Gats::Object::skipWs( Bu::String::const_iterator &i ) | 83 | void Gats::Object::skipWs( Bu::String::const_iterator &i ) |
| 77 | { | 84 | { |
| 78 | for(; *i == ' ' || *i == '\t' || *i == '\r' || *i == '\n'; i++ ) { } | 85 | for(; *i == ' ' || *i == '\t' || *i == '\r' || *i == '\n'; i++ ) { } |
| 79 | } | 86 | } |
| 80 | 87 | ||
| 81 | Bu::String Gats::Object::token( Bu::String::const_iterator &i ) | 88 | Bu::String Gats::Object::token( Bu::String::const_iterator &i ) |
| 82 | { | 89 | { |
| 83 | Bu::String sRet; | 90 | Bu::String sRet; |
| 84 | if( *i == '\"' ) | 91 | if( *i == '\"' ) |
| 85 | { | 92 | { |
| 86 | for( i++; i && *i != '\"' ; i++ ) | 93 | for( i++; i && *i != '\"' ; i++ ) |
| 87 | { | 94 | { |
| 88 | if( *i == '\\' ) | 95 | if( *i == '\\' ) |
| 89 | i++; | 96 | i++; |
| 90 | sRet += i; | 97 | sRet += i; |
| 91 | } | 98 | } |
| 92 | i++; | 99 | i++; |
| 93 | } | 100 | } |
| 94 | else | 101 | else |
| 95 | { | 102 | { |
| 96 | for(; i && *i != ' ' && *i != '\t' && *i != '\r' && *i != '\n' && | 103 | for(; i && *i != ' ' && *i != '\t' && *i != '\r' && *i != '\n' && |
| 97 | *i != ',' && *i != ']' && *i != '}' && *i != '[' && | 104 | *i != ',' && *i != ']' && *i != '}' && *i != '[' && |
| 98 | *i != '{'; i++ ) | 105 | *i != '{'; i++ ) |
| 99 | { | 106 | { |
| 100 | sRet += i; | 107 | sRet += i; |
| 101 | } | 108 | } |
| 102 | } | 109 | } |
| 103 | 110 | ||
| 104 | return sRet; | 111 | return sRet; |
| 105 | } | 112 | } |
| 106 | 113 | ||
| 107 | Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i ) | 114 | Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i ) |
| 108 | { | 115 | { |
| 109 | skipWs( i ); | 116 | skipWs( i ); |
| 110 | 117 | ||
| 111 | switch( *i ) | 118 | switch( *i ) |
| 112 | { | 119 | { |
| 113 | case '[': | 120 | case '[': |
| 114 | { | 121 | { |
| 115 | Gats::List *pLst = new Gats::List(); | 122 | Gats::List *pLst = new Gats::List(); |
| 116 | i++; | 123 | i++; |
| 117 | for(;;) | 124 | for(;;) |
| 118 | { | 125 | { |
| 119 | skipWs( i ); | 126 | skipWs( i ); |
| 120 | if( *i == ']' ) | 127 | if( *i == ']' ) |
| 121 | { | 128 | { |
| 122 | i++; | 129 | i++; |
| 123 | return pLst; | 130 | return pLst; |
| 124 | } | 131 | } |
| 125 | Gats::Object *pObj = strToGats( i ); | 132 | Gats::Object *pObj = strToGats( i ); |
| 126 | if( !pObj ) | 133 | if( !pObj ) |
| 127 | break; | 134 | break; |
| 128 | pLst->append( pObj ); | 135 | pLst->append( pObj ); |
| 129 | skipWs( i ); | 136 | skipWs( i ); |
| 130 | switch( *i ) | 137 | switch( *i ) |
| 131 | { | 138 | { |
| 132 | case ',': | 139 | case ',': |
| 133 | i++; | 140 | i++; |
| 134 | break; | 141 | break; |
| 135 | 142 | ||
| 136 | case ']': | 143 | case ']': |
| 137 | i++; | 144 | i++; |
| 138 | return pLst; | 145 | return pLst; |
| 139 | 146 | ||
| 140 | default: | 147 | default: |
| 141 | throw Bu::ExceptionBase("Invalid character found."); | 148 | throw Bu::ExceptionBase("Invalid character found."); |
| 142 | } | 149 | } |
| 143 | } | 150 | } |
| 144 | } | 151 | } |
| 145 | break; | 152 | break; |
| 146 | 153 | ||
| 147 | case '{': | 154 | case '{': |
| 148 | { | 155 | { |
| 149 | Gats::Dictionary *pDict = new Gats::Dictionary(); | 156 | Gats::Dictionary *pDict = new Gats::Dictionary(); |
| 150 | i++; | 157 | i++; |
| 151 | for(;;) | 158 | for(;;) |
| 152 | { | 159 | { |
| 153 | skipWs( i ); | 160 | skipWs( i ); |
| 154 | if( *i == '}' ) | 161 | if( *i == '}' ) |
| 155 | { | 162 | { |
| 156 | i++; | 163 | i++; |
| 157 | return pDict; | 164 | return pDict; |
| 158 | } | 165 | } |
| 159 | if( *i != '\"' ) | 166 | if( *i != '\"' ) |
| 160 | throw Bu::ExceptionBase("Keys must be quoted strings."); | 167 | throw Bu::ExceptionBase("Keys must be quoted strings."); |
| 161 | Bu::String sKey = token( i ); | 168 | Bu::String sKey = token( i ); |
| 162 | skipWs( i ); | 169 | skipWs( i ); |
| @@ -187,153 +194,153 @@ Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i ) | |||
| 187 | break; | 194 | break; |
| 188 | 195 | ||
| 189 | case '\"': | 196 | case '\"': |
| 190 | return new Gats::String( token( i ) ); | 197 | return new Gats::String( token( i ) ); |
| 191 | break; | 198 | break; |
| 192 | 199 | ||
| 193 | case '0': | 200 | case '0': |
| 194 | case '1': | 201 | case '1': |
| 195 | case '2': | 202 | case '2': |
| 196 | case '3': | 203 | case '3': |
| 197 | case '4': | 204 | case '4': |
| 198 | case '5': | 205 | case '5': |
| 199 | case '6': | 206 | case '6': |
| 200 | case '7': | 207 | case '7': |
| 201 | case '8': | 208 | case '8': |
| 202 | case '9': | 209 | case '9': |
| 203 | case '.': | 210 | case '.': |
| 204 | case '+': | 211 | case '+': |
| 205 | case '-': | 212 | case '-': |
| 206 | { | 213 | { |
| 207 | Bu::String s = token( i ); | 214 | Bu::String s = token( i ); |
| 208 | int iSize = s.getSize(); | 215 | int iSize = s.getSize(); |
| 209 | if( s[iSize-1] == 'i' ) | 216 | if( s[iSize-1] == 'i' ) |
| 210 | { | 217 | { |
| 211 | return new Gats::Integer( | 218 | return new Gats::Integer( |
| 212 | strtoll( s.getStr(), NULL, 10 ) | 219 | strtoll( s.getStr(), NULL, 10 ) |
| 213 | ); | 220 | ); |
| 214 | } | 221 | } |
| 215 | else if( s[iSize-1] == 'f' ) | 222 | else if( s[iSize-1] == 'f' ) |
| 216 | { | 223 | { |
| 217 | return new Gats::Float( | 224 | return new Gats::Float( |
| 218 | strtod( s.getStr(), NULL ) | 225 | strtod( s.getStr(), NULL ) |
| 219 | ); | 226 | ); |
| 220 | } | 227 | } |
| 221 | else | 228 | else |
| 222 | { | 229 | { |
| 223 | for( Bu::String::iterator i = s.begin(); i; i++ ) | 230 | for( Bu::String::iterator i = s.begin(); i; i++ ) |
| 224 | { | 231 | { |
| 225 | if( *i == '.' ) | 232 | if( *i == '.' ) |
| 226 | return new Gats::Float( | 233 | return new Gats::Float( |
| 227 | strtod( s.getStr(), NULL ) | 234 | strtod( s.getStr(), NULL ) |
| 228 | ); | 235 | ); |
| 229 | } | 236 | } |
| 230 | return new Gats::Integer( | 237 | return new Gats::Integer( |
| 231 | strtoll( s.getStr(), NULL, 10 ) | 238 | strtoll( s.getStr(), NULL, 10 ) |
| 232 | ); | 239 | ); |
| 233 | } | 240 | } |
| 234 | } | 241 | } |
| 235 | break; | 242 | break; |
| 236 | 243 | ||
| 237 | default: | 244 | default: |
| 238 | { | 245 | { |
| 239 | Bu::String s = token( i ); | 246 | Bu::String s = token( i ); |
| 240 | int iSize = s.getSize(); | 247 | int iSize = s.getSize(); |
| 241 | // Test for explicit types first | 248 | // Test for explicit types first |
| 242 | if( iSize > 2 ) | 249 | if( iSize > 2 ) |
| 243 | { | 250 | { |
| 244 | if( (s[0] >= '0' && s[0] <= '9') || s[0] == '+' || s[0] == '-' ) | 251 | if( (s[0] >= '0' && s[0] <= '9') || s[0] == '+' || s[0] == '-' ) |
| 245 | { | 252 | { |
| 246 | } | 253 | } |
| 247 | else | 254 | else |
| 248 | { | 255 | { |
| 249 | Bu::String st = s.toLower(); | 256 | Bu::String st = s.toLower(); |
| 250 | if( st == "true" ) | 257 | if( st == "true" ) |
| 251 | { | 258 | { |
| 252 | return new Gats::Boolean( true ); | 259 | return new Gats::Boolean( true ); |
| 253 | } | 260 | } |
| 254 | else if( st == "false" ) | 261 | else if( st == "false" ) |
| 255 | { | 262 | { |
| 256 | return new Gats::Boolean( false ); | 263 | return new Gats::Boolean( false ); |
| 257 | } | 264 | } |
| 258 | else if( st == "null" ) | 265 | else if( st == "null" ) |
| 259 | { | 266 | { |
| 260 | return new Gats::Null(); | 267 | return new Gats::Null(); |
| 261 | } | 268 | } |
| 262 | } | 269 | } |
| 263 | } | 270 | } |
| 264 | } | 271 | } |
| 265 | break; | 272 | break; |
| 266 | } | 273 | } |
| 267 | 274 | ||
| 268 | return NULL; | 275 | return NULL; |
| 269 | } | 276 | } |
| 270 | 277 | ||
| 271 | Gats::Object *Gats::Object::strToGats( const Bu::String &sStr ) | 278 | Gats::Object *Gats::Object::strToGats( const Bu::String &sStr ) |
| 272 | { | 279 | { |
| 273 | Bu::String::const_iterator i = sStr.begin(); | 280 | Bu::String::const_iterator i = sStr.begin(); |
| 274 | 281 | ||
| 275 | return strToGats( i ); | 282 | return strToGats( i ); |
| 276 | } | 283 | } |
| 277 | 284 | ||
| 278 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ) | 285 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ) |
| 279 | { | 286 | { |
| 280 | switch( obj.getType() ) | 287 | switch( obj.getType() ) |
| 281 | { | 288 | { |
| 282 | case Gats::typeDictionary: | 289 | case Gats::typeDictionary: |
| 283 | return f << dynamic_cast<const Gats::Dictionary &>(obj); | 290 | return f << dynamic_cast<const Gats::Dictionary &>(obj); |
| 284 | 291 | ||
| 285 | case Gats::typeList: | 292 | case Gats::typeList: |
| 286 | return f << dynamic_cast<const Gats::List &>(obj); | 293 | return f << dynamic_cast<const Gats::List &>(obj); |
| 287 | 294 | ||
| 288 | case Gats::typeString: | 295 | case Gats::typeString: |
| 289 | return f << dynamic_cast<const Gats::String &>(obj); | 296 | return f << dynamic_cast<const Gats::String &>(obj); |
| 290 | 297 | ||
| 291 | case Gats::typeInteger: | 298 | case Gats::typeInteger: |
| 292 | return f << dynamic_cast<const Gats::Integer &>(obj); | 299 | return f << dynamic_cast<const Gats::Integer &>(obj); |
| 293 | 300 | ||
| 294 | case Gats::typeFloat: | 301 | case Gats::typeFloat: |
| 295 | return f << dynamic_cast<const Gats::Float &>(obj); | 302 | return f << dynamic_cast<const Gats::Float &>(obj); |
| 296 | 303 | ||
| 297 | case Gats::typeBoolean: | 304 | case Gats::typeBoolean: |
| 298 | return f << dynamic_cast<const Gats::Boolean &>(obj); | 305 | return f << dynamic_cast<const Gats::Boolean &>(obj); |
| 299 | 306 | ||
| 300 | case Gats::typeNull: | 307 | case Gats::typeNull: |
| 301 | return f << dynamic_cast<const Gats::Null &>(obj); | 308 | return f << dynamic_cast<const Gats::Null &>(obj); |
| 302 | 309 | ||
| 303 | default: | 310 | default: |
| 304 | return f << "***ERROR: Bad Gats type***"; | 311 | return f << "***ERROR: Bad Gats type***"; |
| 305 | } | 312 | } |
| 306 | } | 313 | } |
| 307 | 314 | ||
| 308 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ) | 315 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ) |
| 309 | { | 316 | { |
| 310 | switch( t ) | 317 | switch( t ) |
| 311 | { | 318 | { |
| 312 | case Gats::typeDictionary: return f << "dictionary"; | 319 | case Gats::typeDictionary: return f << "dictionary"; |
| 313 | case Gats::typeList: return f << "list"; | 320 | case Gats::typeList: return f << "list"; |
| 314 | case Gats::typeString: return f << "string"; | 321 | case Gats::typeString: return f << "string"; |
| 315 | case Gats::typeInteger: return f << "integer"; | 322 | case Gats::typeInteger: return f << "integer"; |
| 316 | case Gats::typeFloat: return f << "float"; | 323 | case Gats::typeFloat: return f << "float"; |
| 317 | case Gats::typeBoolean: return f << "boolean"; | 324 | case Gats::typeBoolean: return f << "boolean"; |
| 318 | case Gats::typeNull: return f << "null"; | 325 | case Gats::typeNull: return f << "null"; |
| 319 | } | 326 | } |
| 320 | 327 | ||
| 321 | return f << "***unknown***"; | 328 | return f << "***unknown***"; |
| 322 | } | 329 | } |
| 323 | 330 | ||
| 324 | const char *Gats::typeToStr( Gats::Type t ) | 331 | const char *Gats::typeToStr( Gats::Type t ) |
| 325 | { | 332 | { |
| 326 | switch( t ) | 333 | switch( t ) |
| 327 | { | 334 | { |
| 328 | case Gats::typeDictionary: return "dictionary"; | 335 | case Gats::typeDictionary: return "dictionary"; |
| 329 | case Gats::typeList: return "list"; | 336 | case Gats::typeList: return "list"; |
| 330 | case Gats::typeString: return "string"; | 337 | case Gats::typeString: return "string"; |
| 331 | case Gats::typeInteger: return "integer"; | 338 | case Gats::typeInteger: return "integer"; |
| 332 | case Gats::typeFloat: return "float"; | 339 | case Gats::typeFloat: return "float"; |
| 333 | case Gats::typeBoolean: return "boolean"; | 340 | case Gats::typeBoolean: return "boolean"; |
| 334 | case Gats::typeNull: return "null"; | 341 | case Gats::typeNull: return "null"; |
| 335 | } | 342 | } |
| 336 | 343 | ||
| 337 | return "***unknown***"; | 344 | return "***unknown***"; |
| 338 | } | 345 | } |
| 339 | 346 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef GATS_OBJECT_H | 8 | #ifndef GATS_OBJECT_H |
| 2 | #define GATS_OBJECT_H | 9 | #define GATS_OBJECT_H |
| 3 | 10 | ||
| @@ -5,48 +12,48 @@ | |||
| 5 | 12 | ||
| 6 | namespace Bu | 13 | namespace Bu |
| 7 | { | 14 | { |
| 8 | class Stream; | 15 | class Stream; |
| 9 | class Formatter; | 16 | class Formatter; |
| 10 | }; | 17 | }; |
| 11 | 18 | ||
| 12 | namespace Gats | 19 | namespace Gats |
| 13 | { | 20 | { |
| 14 | enum Type | 21 | enum Type |
| 15 | { | 22 | { |
| 16 | typeDictionary, | 23 | typeDictionary, |
| 17 | typeList, | 24 | typeList, |
| 18 | typeString, | 25 | typeString, |
| 19 | typeInteger, | 26 | typeInteger, |
| 20 | typeFloat, | 27 | typeFloat, |
| 21 | typeBoolean, | 28 | typeBoolean, |
| 22 | typeNull | 29 | typeNull |
| 23 | }; | 30 | }; |
| 24 | 31 | ||
| 25 | /** | 32 | /** |
| 26 | * The baseclass for every type that can be stored in a packet. | 33 | * The baseclass for every type that can be stored in a packet. |
| 27 | */ | 34 | */ |
| 28 | class Object | 35 | class Object |
| 29 | { | 36 | { |
| 30 | public: | 37 | public: |
| 31 | Object(); | 38 | Object(); |
| 32 | virtual ~Object(); | 39 | virtual ~Object(); |
| 33 | 40 | ||
| 34 | virtual Type getType() const =0; | 41 | virtual Type getType() const =0; |
| 35 | 42 | ||
| 36 | virtual void write( Bu::Stream &rOut ) const=0; | 43 | virtual void write( Bu::Stream &rOut ) const=0; |
| 37 | virtual void read( Bu::Stream &rIn, char cType )=0; | 44 | virtual void read( Bu::Stream &rIn, char cType )=0; |
| 38 | virtual Object *clone() const=0; | 45 | virtual Object *clone() const=0; |
| 39 | 46 | ||
| 40 | static Object *read( Bu::Stream &rIn ); | 47 | static Object *read( Bu::Stream &rIn ); |
| 41 | static Object *strToGats( const Bu::String &sStr ); | 48 | static Object *strToGats( const Bu::String &sStr ); |
| 42 | 49 | ||
| 43 | private: | 50 | private: |
| 44 | static Object *strToGats( Bu::String::const_iterator &i ); | 51 | static Object *strToGats( Bu::String::const_iterator &i ); |
| 45 | static Bu::String token( Bu::String::const_iterator &i ); | 52 | static Bu::String token( Bu::String::const_iterator &i ); |
| 46 | static void skipWs( Bu::String::const_iterator &i ); | 53 | static void skipWs( Bu::String::const_iterator &i ); |
| 47 | }; | 54 | }; |
| 48 | 55 | ||
| 49 | const char *typeToStr( Type t ); | 56 | const char *typeToStr( Type t ); |
| 50 | }; | 57 | }; |
| 51 | 58 | ||
| 52 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ); | 59 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/protocolgats.h" | 8 | #include "gats/protocolgats.h" |
| 2 | #include "gats/gatsstream.h" | 9 | #include "gats/gatsstream.h" |
| 3 | 10 | ||
| @@ -7,50 +14,50 @@ | |||
| 7 | using namespace Bu; | 14 | using namespace Bu; |
| 8 | 15 | ||
| 9 | Gats::ProtocolGats::ProtocolGats() : | 16 | Gats::ProtocolGats::ProtocolGats() : |
| 10 | pStream( NULL ), | 17 | pStream( NULL ), |
| 11 | pUsedClient( NULL ) | 18 | pUsedClient( NULL ) |
| 12 | { | 19 | { |
| 13 | } | 20 | } |
| 14 | 21 | ||
| 15 | Gats::ProtocolGats::~ProtocolGats() | 22 | Gats::ProtocolGats::~ProtocolGats() |
| 16 | { | 23 | { |
| 17 | delete pStream; | 24 | delete pStream; |
| 18 | pStream = NULL; | 25 | pStream = NULL; |
| 19 | } | 26 | } |
| 20 | 27 | ||
| 21 | void Gats::ProtocolGats::onNewConnection( Bu::Client *pClient ) | 28 | void Gats::ProtocolGats::onNewConnection( Bu::Client *pClient ) |
| 22 | { | 29 | { |
| 23 | if( pStream == NULL ) | 30 | if( pStream == NULL ) |
| 24 | { | 31 | { |
| 25 | pStream = new Gats::GatsStream( *pClient ); | 32 | pStream = new Gats::GatsStream( *pClient ); |
| 26 | pUsedClient = pClient; | 33 | pUsedClient = pClient; |
| 27 | } | 34 | } |
| 28 | } | 35 | } |
| 29 | 36 | ||
| 30 | void Gats::ProtocolGats::onNewData( Bu::Client *pClient ) | 37 | void Gats::ProtocolGats::onNewData( Bu::Client *pClient ) |
| 31 | { | 38 | { |
| 32 | if( pStream == NULL ) | 39 | if( pStream == NULL ) |
| 33 | { | 40 | { |
| 34 | pStream = new Gats::GatsStream( *pClient ); | 41 | pStream = new Gats::GatsStream( *pClient ); |
| 35 | pUsedClient = pClient; | 42 | pUsedClient = pClient; |
| 36 | } | 43 | } |
| 37 | else if( pClient != pUsedClient ) | 44 | else if( pClient != pUsedClient ) |
| 38 | { | 45 | { |
| 39 | throw Bu::ExceptionBase("ProtocolGats requires that you maintain a " | 46 | throw Bu::ExceptionBase("ProtocolGats requires that you maintain a " |
| 40 | "1:1 relationship between client and protocol objects."); | 47 | "1:1 relationship between client and protocol objects."); |
| 41 | } | 48 | } |
| 42 | 49 | ||
| 43 | for(;;) | 50 | for(;;) |
| 44 | { | 51 | { |
| 45 | Gats::Object *pObj = pStream->readObject(); | 52 | Gats::Object *pObj = pStream->readObject(); |
| 46 | if( pObj == NULL ) | 53 | if( pObj == NULL ) |
| 47 | break; | 54 | break; |
| 48 | onNewObject( pClient, pObj ); | 55 | onNewObject( pClient, pObj ); |
| 49 | } | 56 | } |
| 50 | } | 57 | } |
| 51 | 58 | ||
| 52 | void Gats::ProtocolGats::writeObject( Gats::Object *pObj ) | 59 | void Gats::ProtocolGats::writeObject( Gats::Object *pObj ) |
| 53 | { | 60 | { |
| 54 | pStream->writeObject( pObj ); | 61 | pStream->writeObject( pObj ); |
| 55 | } | 62 | } |
| 56 | 63 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef GATS_PROTOCOL_GATS_H | 8 | #ifndef GATS_PROTOCOL_GATS_H |
| 2 | #define GATS_PROTOCOL_GATS_H | 9 | #define GATS_PROTOCOL_GATS_H |
| 3 | 10 | ||
| @@ -5,26 +12,26 @@ | |||
| 5 | 12 | ||
| 6 | namespace Gats | 13 | namespace Gats |
| 7 | { | 14 | { |
| 8 | class Object; | 15 | class Object; |
| 9 | class GatsStream; | 16 | class GatsStream; |
| 10 | 17 | ||
| 11 | class ProtocolGats : public Bu::Protocol | 18 | class ProtocolGats : public Bu::Protocol |
| 12 | { | 19 | { |
| 13 | public: | 20 | public: |
| 14 | ProtocolGats(); | 21 | ProtocolGats(); |
| 15 | virtual ~ProtocolGats(); | 22 | virtual ~ProtocolGats(); |
| 16 | 23 | ||
| 17 | virtual void onNewConnection( Bu::Client *pClient ); | 24 | virtual void onNewConnection( Bu::Client *pClient ); |
| 18 | virtual void onNewData( Bu::Client *pClient ); | 25 | virtual void onNewData( Bu::Client *pClient ); |
| 19 | 26 | ||
| 20 | virtual void onNewObject( Bu::Client *pClient, Gats::Object *pObj )=0; | 27 | virtual void onNewObject( Bu::Client *pClient, Gats::Object *pObj )=0; |
| 21 | 28 | ||
| 22 | void writeObject( Gats::Object *pObj ); | 29 | void writeObject( Gats::Object *pObj ); |
| 23 | 30 | ||
| 24 | private: | 31 | private: |
| 25 | Gats::GatsStream *pStream; | 32 | Gats::GatsStream *pStream; |
| 26 | Bu::Client *pUsedClient; | 33 | Bu::Client *pUsedClient; |
| 27 | }; | 34 | }; |
| 28 | }; | 35 | }; |
| 29 | 36 | ||
| 30 | #endif | 37 | #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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/string.h" | 8 | #include "gats/string.h" |
| 2 | 9 | ||
| 3 | #include "gats/integer.h" | 10 | #include "gats/integer.h" |
| @@ -9,27 +16,27 @@ Gats::String::String() | |||
| 9 | } | 16 | } |
| 10 | 17 | ||
| 11 | Gats::String::String( const char *s ) : | 18 | Gats::String::String( const char *s ) : |
| 12 | Bu::String( s ) | 19 | Bu::String( s ) |
| 13 | { | 20 | { |
| 14 | } | 21 | } |
| 15 | 22 | ||
| 16 | Gats::String::String( const char *s, long iLength ) : | 23 | Gats::String::String( const char *s, long iLength ) : |
| 17 | Bu::String( s, iLength ) | 24 | Bu::String( s, iLength ) |
| 18 | { | 25 | { |
| 19 | } | 26 | } |
| 20 | 27 | ||
| 21 | Gats::String::String( long iLength ) : | 28 | Gats::String::String( long iLength ) : |
| 22 | Bu::String( iLength ) | 29 | Bu::String( iLength ) |
| 23 | { | 30 | { |
| 24 | } | 31 | } |
| 25 | 32 | ||
| 26 | Gats::String::String( const String &s ) : | 33 | Gats::String::String( const String &s ) : |
| 27 | Bu::String( s ) | 34 | Bu::String( s ) |
| 28 | { | 35 | { |
| 29 | } | 36 | } |
| 30 | 37 | ||
| 31 | Gats::String::String( const Bu::String &s ) : | 38 | Gats::String::String( const Bu::String &s ) : |
| 32 | Bu::String( s ) | 39 | Bu::String( s ) |
| 33 | { | 40 | { |
| 34 | } | 41 | } |
| 35 | 42 | ||
| @@ -39,32 +46,32 @@ Gats::String::~String() | |||
| 39 | 46 | ||
| 40 | Gats::Object *Gats::String::clone() const | 47 | Gats::Object *Gats::String::clone() const |
| 41 | { | 48 | { |
| 42 | return new Gats::String( Bu::String::clone() ); | 49 | return new Gats::String( Bu::String::clone() ); |
| 43 | } | 50 | } |
| 44 | 51 | ||
| 45 | void Gats::String::write( Bu::Stream &rOut ) const | 52 | void Gats::String::write( Bu::Stream &rOut ) const |
| 46 | { | 53 | { |
| 47 | rOut.write("s", 1 ); | 54 | rOut.write("s", 1 ); |
| 48 | uint32_t iSize = getSize(); | 55 | uint32_t iSize = getSize(); |
| 49 | Gats::Integer::writePackedInt( rOut, iSize ); | 56 | Gats::Integer::writePackedInt( rOut, iSize ); |
| 50 | rOut.write( getStr(), iSize ); | 57 | rOut.write( getStr(), iSize ); |
| 51 | } | 58 | } |
| 52 | 59 | ||
| 53 | void Gats::String::read( Bu::Stream &rIn, char cType ) | 60 | void Gats::String::read( Bu::Stream &rIn, char cType ) |
| 54 | { | 61 | { |
| 55 | uint32_t iSize; | 62 | uint32_t iSize; |
| 56 | Gats::Integer::readPackedInt( rIn, iSize ); | 63 | Gats::Integer::readPackedInt( rIn, iSize ); |
| 57 | setSize( iSize ); | 64 | setSize( iSize ); |
| 58 | rIn.read( getStr(), iSize ); | 65 | rIn.read( getStr(), iSize ); |
| 59 | } | 66 | } |
| 60 | 67 | ||
| 61 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ) | 68 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ) |
| 62 | { | 69 | { |
| 63 | for( Gats::String::const_iterator i = s.begin(); i; i++ ) | 70 | for( Gats::String::const_iterator i = s.begin(); i; i++ ) |
| 64 | { | 71 | { |
| 65 | if( *i >= 127 || *i <= 31 ) | 72 | if( *i >= 127 || *i <= 31 ) |
| 66 | return f << "(binary str) " << s.getSize() << " bytes"; | 73 | return f << "(binary str) " << s.getSize() << " bytes"; |
| 67 | } | 74 | } |
| 68 | return f << "(str) \"" << dynamic_cast<const Bu::String &>(s) << "\""; | 75 | return f << "(str) \"" << dynamic_cast<const Bu::String &>(s) << "\""; |
| 69 | } | 76 | } |
| 70 | 77 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #ifndef GATS_STRING_H | 8 | #ifndef GATS_STRING_H |
| 2 | #define GATS_STRING_H | 9 | #define GATS_STRING_H |
| 3 | 10 | ||
| @@ -6,25 +13,25 @@ | |||
| 6 | 13 | ||
| 7 | namespace Gats | 14 | namespace Gats |
| 8 | { | 15 | { |
| 9 | class String : public Gats::Object, public Bu::String | 16 | class String : public Gats::Object, public Bu::String |
| 10 | { | 17 | { |
| 11 | public: | 18 | public: |
| 12 | String(); | 19 | String(); |
| 13 | String( const char *s ); | 20 | String( const char *s ); |
| 14 | String( const char *s, long iLength ); | 21 | String( const char *s, long iLength ); |
| 15 | String( long iLength ); | 22 | String( long iLength ); |
| 16 | String( const String &s ); | 23 | String( const String &s ); |
| 17 | String( const Bu::String &s ); | 24 | String( const Bu::String &s ); |
| 18 | virtual ~String(); | 25 | virtual ~String(); |
| 19 | 26 | ||
| 20 | virtual Object *clone() const; | 27 | virtual Object *clone() const; |
| 21 | virtual Type getType() const { return typeString; } | 28 | virtual Type getType() const { return typeString; } |
| 22 | 29 | ||
| 23 | virtual void write( Bu::Stream &rOut ) const; | 30 | virtual void write( Bu::Stream &rOut ) const; |
| 24 | virtual void read( Bu::Stream &rIn, char cType ); | 31 | virtual void read( Bu::Stream &rIn, char cType ); |
| 25 | 32 | ||
| 26 | private: | 33 | private: |
| 27 | }; | 34 | }; |
| 28 | }; | 35 | }; |
| 29 | 36 | ||
| 30 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ); | 37 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/types.h" | 8 | #include "gats/types.h" |
| 2 | 9 | ||
| 3 | #include <bu/sio.h> | 10 | #include <bu/sio.h> |
| @@ -6,17 +13,17 @@ using namespace Bu; | |||
| 6 | 13 | ||
| 7 | int main( int argc, char *argv[] ) | 14 | int main( int argc, char *argv[] ) |
| 8 | { | 15 | { |
| 9 | Gats::Object *pBase = Gats::Object::strToGats("{\"Thing\": 3.14159, \"bool\": true, \"list\":[\"string\",44,{\"Stuff\":{\"list\":[],\"what?\":false}}]}"); | 16 | Gats::Object *pBase = Gats::Object::strToGats("{\"Thing\": 3.14159, \"bool\": true, \"list\":[\"string\",44,{\"Stuff\":{\"list\":[],\"what?\":false}}]}"); |
| 10 | 17 | ||
| 11 | sio << *pBase << sio.nl; | 18 | sio << *pBase << sio.nl; |
| 12 | 19 | ||
| 13 | Gats::Object *pNew = pBase->clone(); | 20 | Gats::Object *pNew = pBase->clone(); |
| 14 | delete pBase; | 21 | delete pBase; |
| 15 | 22 | ||
| 16 | sio << *pNew << sio.nl; | 23 | sio << *pNew << sio.nl; |
| 17 | 24 | ||
| 18 | delete pNew; | 25 | delete pNew; |
| 19 | 26 | ||
| 20 | return 0; | 27 | return 0; |
| 21 | } | 28 | } |
| 22 | 29 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include <bu/sio.h> | 8 | #include <bu/sio.h> |
| 2 | #include <bu/file.h> | 9 | #include <bu/file.h> |
| 3 | #include <gats/gatsstream.h> | 10 | #include <gats/gatsstream.h> |
| @@ -7,24 +14,24 @@ using namespace Bu; | |||
| 7 | 14 | ||
| 8 | int main( int argc, char *argv[] ) | 15 | int main( int argc, char *argv[] ) |
| 9 | { | 16 | { |
| 10 | File fIn( argv[1], File::Read ); | 17 | File fIn( argv[1], File::Read ); |
| 11 | Gats::GatsStream gsIn( fIn ); | 18 | Gats::GatsStream gsIn( fIn ); |
| 12 | 19 | ||
| 13 | for(;;) | 20 | for(;;) |
| 14 | { | 21 | { |
| 15 | sio << "Reading from file position: " << fIn.tell() << sio.nl; | 22 | sio << "Reading from file position: " << fIn.tell() << sio.nl; |
| 16 | Gats::Object *pObj = gsIn.readObject(); | 23 | Gats::Object *pObj = gsIn.readObject(); |
| 17 | if( !pObj ) | 24 | if( !pObj ) |
| 18 | { | 25 | { |
| 19 | if( gsIn.hasReadBuffer() ) | 26 | if( gsIn.hasReadBuffer() ) |
| 20 | { | 27 | { |
| 21 | sio << "Premature end of stream detected, have " | 28 | sio << "Premature end of stream detected, have " |
| 22 | << gsIn.getReadBufferSize() << "b." << sio.nl; | 29 | << gsIn.getReadBufferSize() << "b." << sio.nl; |
| 23 | } | 30 | } |
| 24 | return 0; | 31 | return 0; |
| 25 | } | 32 | } |
| 26 | 33 | ||
| 27 | sio << *pObj << sio.nl; | 34 | sio << *pObj << sio.nl; |
| 28 | } | 35 | } |
| 29 | } | 36 | } |
| 30 | 37 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/integer.h" | 8 | #include "gats/integer.h" |
| 2 | 9 | ||
| 3 | #include <bu/sio.h> | 10 | #include <bu/sio.h> |
| @@ -8,40 +15,40 @@ using namespace Bu; | |||
| 8 | 15 | ||
| 9 | void hexdump( char *dat, int iSize ) | 16 | void hexdump( char *dat, int iSize ) |
| 10 | { | 17 | { |
| 11 | static const char *hex="0123456789ABCDEF"; | 18 | static const char *hex="0123456789ABCDEF"; |
| 12 | printf("----\n"); | 19 | printf("----\n"); |
| 13 | for( int j = 0; j < iSize; j += 8 ) | 20 | for( int j = 0; j < iSize; j += 8 ) |
| 14 | { | 21 | { |
| 15 | for( int k = j; /*k < iSize &&*/ k < j+8; k++ ) | 22 | for( int k = j; /*k < iSize &&*/ k < j+8; k++ ) |
| 16 | printf((k<iSize)?"%c%c ":" ", hex[(dat[k]>>4)&0x0F], hex[dat[k]&0x0F] ); | 23 | printf((k<iSize)?"%c%c ":" ", hex[(dat[k]>>4)&0x0F], hex[dat[k]&0x0F] ); |
| 17 | printf("| "); | 24 | printf("| "); |
| 18 | for( int k = j; k < iSize && k < j+8; k++ ) | 25 | for( int k = j; k < iSize && k < j+8; k++ ) |
| 19 | printf("%c ", (dat[k]>13&&dat[k]<127)?(dat[k]):('.') ); | 26 | printf("%c ", (dat[k]>13&&dat[k]<127)?(dat[k]):('.') ); |
| 20 | printf("\n"); | 27 | printf("\n"); |
| 21 | } | 28 | } |
| 22 | printf("----\n"); | 29 | printf("----\n"); |
| 23 | } | 30 | } |
| 24 | 31 | ||
| 25 | int main( int argc, char *argv[] ) | 32 | int main( int argc, char *argv[] ) |
| 26 | { | 33 | { |
| 27 | for( int j = 1; j < argc; j++ ) | 34 | for( int j = 1; j < argc; j++ ) |
| 28 | { | 35 | { |
| 29 | int64_t i = strtoll( argv[j], NULL, 10 ); | 36 | int64_t i = strtoll( argv[j], NULL, 10 ); |
| 30 | MemBuf mb; | 37 | MemBuf mb; |
| 31 | Gats::Integer::writePackedInt( mb, i ); | 38 | Gats::Integer::writePackedInt( mb, i ); |
| 32 | hexdump( mb.getString().getStr(), mb.getString().getSize() ); | 39 | hexdump( mb.getString().getStr(), mb.getString().getSize() ); |
| 33 | } | 40 | } |
| 34 | /* | 41 | /* |
| 35 | sio << "Before: " << i << sio.nl; | 42 | sio << "Before: " << i << sio.nl; |
| 36 | Gats::Integer::writePackedInt( mb, i ); | 43 | Gats::Integer::writePackedInt( mb, i ); |
| 37 | mb.write("aaa", 3 ); | 44 | mb.write("aaa", 3 ); |
| 38 | mb.setPos( 0 ); | 45 | mb.setPos( 0 ); |
| 39 | Gats::Integer::readPackedInt( mb, i ); | 46 | Gats::Integer::readPackedInt( mb, i ); |
| 40 | sio << "After: " << i << sio.nl; | 47 | sio << "After: " << i << sio.nl; |
| 41 | char buf[4]; | 48 | char buf[4]; |
| 42 | buf[mb.read( buf, 3 )] = '\0'; | 49 | buf[mb.read( buf, 3 )] = '\0'; |
| 43 | sio << "Extra: \"" << buf << "\"" << sio.nl; | 50 | sio << "Extra: \"" << buf << "\"" << sio.nl; |
| 44 | */ | 51 | */ |
| 45 | return 0; | 52 | return 0; |
| 46 | } | 53 | } |
| 47 | 54 | ||
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libgats library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 1 | #include "gats/object.h" | 8 | #include "gats/object.h" |
| 2 | #include "gats/boolean.h" | 9 | #include "gats/boolean.h" |
| 3 | #include "gats/dictionary.h" | 10 | #include "gats/dictionary.h" |
