diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 17:20:11 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 17:20:11 +0000 |
commit | d534a56d95bca7bdd812be024d9eacba4734e2b7 (patch) | |
tree | f9b98ee2b80e645a7b54e7934882be6c9f73c165 | |
parent | 61ccc86fdf06f12cb72a8b7e65286f812cf62154 (diff) | |
download | libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.tar.gz libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.tar.bz2 libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.tar.xz libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.zip |
Many changes: tabconv'd the C++ code, added a license, BSD, and docs.
93 files changed, 3600 insertions, 2838 deletions
@@ -0,0 +1,28 @@ | |||
1 | Copyright (C) 2007-2012 Xagasoft | ||
2 | |||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, | ||
6 | are permitted provided that the following conditions are met: | ||
7 | |||
8 | - Redistributions of source code must retain the above copyright notice, | ||
9 | this list of conditions and the following disclaimer. | ||
10 | |||
11 | - Redistributions in binary form must reproduce the above copyright notice, | ||
12 | this list of conditions and the following disclaimer in the documentation | ||
13 | and/or other materials provided with the distribution. | ||
14 | |||
15 | - Neither the name of Xagasoft nor the names of its contributors | ||
16 | may be used to endorse or promote products derived from this software | ||
17 | without specific prior written permission. | ||
18 | |||
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
diff --git a/README.md b/README.md new file mode 100644 index 0000000..f5302a8 --- /dev/null +++ b/README.md | |||
@@ -0,0 +1,115 @@ | |||
1 | # Generalized Agile Transport System (GATS) | ||
2 | |||
3 | GATS is a data encoding format, as well as a set of libraries for reading and | ||
4 | writing data in that format. It's a structured format reminiscent of a binary | ||
5 | json, but with some extra cool features. | ||
6 | |||
7 | * All numbers (integers and floating point) are stored in an arbitrary | ||
8 | precision format which takes up the least amount of space it can. | ||
9 | * Unlike textual formats (like json, xml, etc.) floating point numbers are | ||
10 | stored exactly, the exact number you write in is the exact number you read | ||
11 | out. | ||
12 | * All formats stored are machine independent, you can read and write them on | ||
13 | any architecture, any endianness and they will always be the same. No more | ||
14 | encoding worries. | ||
15 | * There are a number of data types you can use to make up data structures: | ||
16 | * Dictionaries | ||
17 | * Lists | ||
18 | * Integers | ||
19 | * Floats | ||
20 | * Strings (binary 8-bit strings, perfect for UTF-8) | ||
21 | * Booleans | ||
22 | * Nulls | ||
23 | |||
24 | # License | ||
25 | |||
26 | GATS is distributed under a new-BSD type license. This is fairly permissive, | ||
27 | but if you require other licensing options feel free to contact us. | ||
28 | |||
29 | # Uses | ||
30 | |||
31 | GATS was originally intended for use in internet protocols, and is great for | ||
32 | that purpose. Used correctly it allows you to create efficient yet highly | ||
33 | malleable protocols with very little extra effort. | ||
34 | |||
35 | However, you can certainly use it for other purposes such as serializing data | ||
36 | for storage, and inter-process communication. In fact, with the different | ||
37 | language bindings available, sometimes GATS may be one of the easier ways to | ||
38 | allow, say, a PHP web service to communicate with a custom C++ executable or | ||
39 | python program. | ||
40 | |||
41 | # Languages/Libraries Supported | ||
42 | |||
43 | At the moment we actively maintain libraries for C++, java, php, and python. | ||
44 | Other languages and libraries are welcomed. Here's a little info on each | ||
45 | target directory: | ||
46 | |||
47 | * ''c++-libbu++'' - The original libgats implementation. Works using libbu++ | ||
48 | data types and streams. You need to have libbu++ and Xagasoft build in | ||
49 | order to build this version. | ||
50 | * ''c++-qt'' - A version written using Qt data types. This version builds using | ||
51 | qmake, so if you're using Qt you already have everything you need. Also | ||
52 | features handy signals & slots to make event driven networking even easier! | ||
53 | * ''java'' - A library using the Java native interfaces, everything looks and | ||
54 | works exactly how you would expect it should. There is a Xagasoft Build | ||
55 | script to build a jar file, but it's simple enough that a single javac | ||
56 | command can build it all, or just import the code into your project directly. | ||
57 | This java version has been used on desktops and android devices. | ||
58 | * ''php'' - There are two libraries for working with php, the first defines a | ||
59 | set of classes for fine control over the format, sometimes this is necessary | ||
60 | as php's types are a little loose. The second simply uses php native types | ||
61 | like array() as data transport. The second option is usually the much easier | ||
62 | to use, but doesn't always get the encoding correct for all inputs. | ||
63 | * ''python'' - These work like other serialization mechanisms in Python like | ||
64 | pickle, json, shelve, and marshal. It exposes the functions load, dump, | ||
65 | loads, dumps, and also the handy helpers recv and send for working with | ||
66 | sockets. The Python implementation returns and transmits native Python | ||
67 | data types, which makes life pretty easy. To use this version simply copy | ||
68 | gats.py to your project. | ||
69 | |||
70 | # Basic Operation | ||
71 | |||
72 | The way GATS works is dictated by the format, so it works similarly in every | ||
73 | implementation, although they each have slightly different mechanics. When | ||
74 | encoding GATS you always encode each object in it's own "GATS packet." A GATS | ||
75 | packet has a very simple header which includes the size of the packet to make | ||
76 | parsing fast and efficient. | ||
77 | |||
78 | Each packet can contain a single root object. It can be any type, but for most | ||
79 | protocols a dictionary is a great choice for the root object. | ||
80 | |||
81 | The format is designed to make it very easy to work with various encoding, | ||
82 | packing, and encryption systems. The reader, by default, will skip all leading | ||
83 | zero bytes that come before a valid GATS packet, and will stop processing | ||
84 | precisely at the end of a valid GATS packet. | ||
85 | |||
86 | Skipping leading zeros makes it easy to work in environments where padding may | ||
87 | be required. You can use the simplest of all padding schemes (pad with zeros) | ||
88 | and it will work seamlessly with GATS. | ||
89 | |||
90 | Since the reader always reads exactly the number of bytes it needs, it's very | ||
91 | easy to embed GATS packets in other streams, or read them sequentially as fast | ||
92 | as you can from a socket. | ||
93 | |||
94 | ## A Note About Strings | ||
95 | |||
96 | All strings in GATS are simply sequences of 8-bit bytes. There is no | ||
97 | overarching encoding that is dictated by the format. When using GATS it is | ||
98 | good to specify how you are encoding your text data, we recommend Unicode. | ||
99 | There is a possibility that a future version of GATS will include a separate | ||
100 | Unicode String data type, but for now it's important to remember this. | ||
101 | |||
102 | For this reason, we also recommend making the keys in all dictionaries 7-bit | ||
103 | UTF-8 compatible ASCII/Latin1. This isn't required of course, but it makes | ||
104 | things a bit easier. | ||
105 | |||
106 | # Speed vs Size | ||
107 | |||
108 | GATS objects are, on average, smaller than storing in other binary formats, and | ||
109 | can be much smaller than textual formats by virtue of storing only as many | ||
110 | bytes as necessary for integers and floats. This also means that GATS requires | ||
111 | more processing than fixed field binary formats, but interestingly not quite as | ||
112 | much as text formats like json. The processing we do on floats is actually | ||
113 | roughly comparable in many ways to text processing, although with fewer steps. | ||
114 | |||
115 | |||
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" |
diff --git a/c++-qt/src/boolean.cpp b/c++-qt/src/boolean.cpp index 3973607..1195bae 100644 --- a/c++-qt/src/boolean.cpp +++ b/c++-qt/src/boolean.cpp | |||
@@ -1,14 +1,21 @@ | |||
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-qt/boolean.h" | 8 | #include "gats-qt/boolean.h" |
2 | 9 | ||
3 | #include <QIODevice> | 10 | #include <QIODevice> |
4 | 11 | ||
5 | Gats::Boolean::Boolean() : | 12 | Gats::Boolean::Boolean() : |
6 | bVal( false ) | 13 | bVal( false ) |
7 | { | 14 | { |
8 | } | 15 | } |
9 | 16 | ||
10 | Gats::Boolean::Boolean( bool bVal ) : | 17 | Gats::Boolean::Boolean( bool bVal ) : |
11 | bVal( bVal ) | 18 | bVal( bVal ) |
12 | { | 19 | { |
13 | } | 20 | } |
14 | 21 | ||
@@ -18,35 +25,35 @@ Gats::Boolean::~Boolean() | |||
18 | 25 | ||
19 | Gats::Object *Gats::Boolean::clone() const | 26 | Gats::Object *Gats::Boolean::clone() const |
20 | { | 27 | { |
21 | return new Gats::Boolean( bVal ); | 28 | return new Gats::Boolean( bVal ); |
22 | } | 29 | } |
23 | 30 | ||
24 | void Gats::Boolean::write( QIODevice &rOut ) const | 31 | void Gats::Boolean::write( QIODevice &rOut ) const |
25 | { | 32 | { |
26 | if( bVal ) | 33 | if( bVal ) |
27 | { | 34 | { |
28 | rOut.write("1", 1 ); | 35 | rOut.write("1", 1 ); |
29 | } | 36 | } |
30 | else | 37 | else |
31 | { | 38 | { |
32 | rOut.write("0", 1 ); | 39 | rOut.write("0", 1 ); |
33 | } | 40 | } |
34 | } | 41 | } |
35 | 42 | ||
36 | void Gats::Boolean::read( QIODevice &rIn, char cType ) | 43 | void Gats::Boolean::read( QIODevice &rIn, char cType ) |
37 | { | 44 | { |
38 | if( cType == '1' ) | 45 | if( cType == '1' ) |
39 | { | 46 | { |
40 | bVal = true; | 47 | bVal = true; |
41 | } | 48 | } |
42 | else | 49 | else |
43 | { | 50 | { |
44 | bVal = false; | 51 | bVal = false; |
45 | } | 52 | } |
46 | } | 53 | } |
47 | /* | 54 | /* |
48 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ) | 55 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ) |
49 | { | 56 | { |
50 | return f << "(bool) " << b.getValue(); | 57 | return f << "(bool) " << b.getValue(); |
51 | } | 58 | } |
52 | */ | 59 | */ |
diff --git a/c++-qt/src/boolean.h b/c++-qt/src/boolean.h index d707e4d..7e42981 100644 --- a/c++-qt/src/boolean.h +++ b/c++-qt/src/boolean.h | |||
@@ -1,3 +1,10 @@ | |||
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 | ||
@@ -7,26 +14,26 @@ class QIODevice; | |||
7 | 14 | ||
8 | namespace Gats | 15 | namespace Gats |
9 | { | 16 | { |
10 | class Boolean : public Gats::Object | 17 | class Boolean : public Gats::Object |
11 | { | 18 | { |
12 | Q_OBJECT; | 19 | Q_OBJECT; |
13 | public: | 20 | public: |
14 | Boolean(); | 21 | Boolean(); |
15 | Boolean( bool bVal ); | 22 | Boolean( bool bVal ); |
16 | virtual ~Boolean(); | 23 | virtual ~Boolean(); |
17 | 24 | ||
18 | virtual Object *clone() const; | 25 | virtual Object *clone() const; |
19 | 26 | ||
20 | virtual Type getType() const { return typeBoolean; } | 27 | virtual Type getType() const { return typeBoolean; } |
21 | bool getValue() const { return bVal; } | 28 | bool getValue() const { return bVal; } |
22 | void setValue( bool b ) { bVal = b; } | 29 | void setValue( bool b ) { bVal = b; } |
23 | 30 | ||
24 | virtual void write( QIODevice &rOut ) const; | 31 | virtual void write( QIODevice &rOut ) const; |
25 | virtual void read( QIODevice &rIn, char cType ); | 32 | virtual void read( QIODevice &rIn, char cType ); |
26 | 33 | ||
27 | private: | 34 | private: |
28 | bool bVal; | 35 | bool bVal; |
29 | }; | 36 | }; |
30 | }; | 37 | }; |
31 | 38 | ||
32 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ); | 39 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ); |
diff --git a/c++-qt/src/dictionary.cpp b/c++-qt/src/dictionary.cpp index edcbdb1..b2ef35e 100644 --- a/c++-qt/src/dictionary.cpp +++ b/c++-qt/src/dictionary.cpp | |||
@@ -1,3 +1,10 @@ | |||
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-qt/dictionary.h" | 8 | #include "gats-qt/dictionary.h" |
2 | 9 | ||
3 | #include "gats-qt/boolean.h" | 10 | #include "gats-qt/boolean.h" |
@@ -12,352 +19,352 @@ Gats::Dictionary::Dictionary() | |||
12 | 19 | ||
13 | Gats::Dictionary::~Dictionary() | 20 | Gats::Dictionary::~Dictionary() |
14 | { | 21 | { |
15 | for( iterator i = begin(); i != end(); i++ ) | 22 | for( iterator i = begin(); i != end(); i++ ) |
16 | { | 23 | { |
17 | delete *i; | 24 | delete *i; |
18 | } | 25 | } |
19 | } | 26 | } |
20 | 27 | ||
21 | Gats::Object *Gats::Dictionary::clone() const | 28 | Gats::Object *Gats::Dictionary::clone() const |
22 | { | 29 | { |
23 | Gats::Dictionary *pClone = new Gats::Dictionary; | 30 | Gats::Dictionary *pClone = new Gats::Dictionary; |
24 | 31 | ||
25 | for( const_iterator i = begin(); i != end(); i++ ) | 32 | for( const_iterator i = begin(); i != end(); i++ ) |
26 | { | 33 | { |
27 | QByteArray bKey = i.key(); | 34 | QByteArray bKey = i.key(); |
28 | bKey.detach(); | 35 | bKey.detach(); |
29 | pClone->insert( bKey, (*i)->clone() ); | 36 | pClone->insert( bKey, (*i)->clone() ); |
30 | } | 37 | } |
31 | 38 | ||
32 | return pClone; | 39 | return pClone; |
33 | } | 40 | } |
34 | 41 | ||
35 | void Gats::Dictionary::write( QIODevice &rOut ) const | 42 | void Gats::Dictionary::write( QIODevice &rOut ) const |
36 | { | 43 | { |
37 | rOut.write("d", 1 ); | 44 | rOut.write("d", 1 ); |
38 | for( const_iterator i= begin(); i != end(); i++ ) | 45 | for( const_iterator i= begin(); i != end(); i++ ) |
39 | { | 46 | { |
40 | Gats::String s( i.key() ); | 47 | Gats::String s( i.key() ); |
41 | s.write( rOut ); | 48 | s.write( rOut ); |
42 | (*i)->write( rOut ); | 49 | (*i)->write( rOut ); |
43 | } | 50 | } |
44 | rOut.write("e", 1 ); | 51 | rOut.write("e", 1 ); |
45 | } | 52 | } |
46 | 53 | ||
47 | void Gats::Dictionary::read( QIODevice &rIn, char cType ) | 54 | void Gats::Dictionary::read( QIODevice &rIn, char cType ) |
48 | { | 55 | { |
49 | for(;;) | 56 | for(;;) |
50 | { | 57 | { |
51 | char cNext; | 58 | char cNext; |
52 | rIn.read( &cNext, 1 ); | 59 | rIn.read( &cNext, 1 ); |
53 | if( cNext == 'e' ) | 60 | if( cNext == 'e' ) |
54 | break; | 61 | break; |
55 | if( cNext != 's' ) | 62 | if( cNext != 's' ) |
56 | throw "PUT GOOD EXCEPTION HERE"; | 63 | throw "PUT GOOD EXCEPTION HERE"; |
57 | Gats::String sKey; | 64 | Gats::String sKey; |
58 | sKey.read( rIn, cNext ); | 65 | sKey.read( rIn, cNext ); |
59 | 66 | ||
60 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 67 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
61 | sKey, Gats::Object::read( rIn ) | 68 | sKey, Gats::Object::read( rIn ) |
62 | ); | 69 | ); |
63 | } | 70 | } |
64 | } | 71 | } |
65 | 72 | ||
66 | void Gats::Dictionary::insert( const QByteArray &sKey, char i ) | 73 | void Gats::Dictionary::insert( const QByteArray &sKey, char i ) |
67 | { | 74 | { |
68 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 75 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
69 | sKey, new Gats::Integer( i ) | 76 | sKey, new Gats::Integer( i ) |
70 | ); | 77 | ); |
71 | } | 78 | } |
72 | 79 | ||
73 | void Gats::Dictionary::insert( const QByteArray &sKey, unsigned char i ) | 80 | void Gats::Dictionary::insert( const QByteArray &sKey, unsigned char i ) |
74 | { | 81 | { |
75 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 82 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
76 | sKey, new Gats::Integer( i ) | 83 | sKey, new Gats::Integer( i ) |
77 | ); | 84 | ); |
78 | } | 85 | } |
79 | 86 | ||
80 | void Gats::Dictionary::insert( const QByteArray &sKey, signed char i ) | 87 | void Gats::Dictionary::insert( const QByteArray &sKey, signed char i ) |
81 | { | 88 | { |
82 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 89 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
83 | sKey, new Gats::Integer( i ) | 90 | sKey, new Gats::Integer( i ) |
84 | ); | 91 | ); |
85 | } | 92 | } |
86 | 93 | ||
87 | void Gats::Dictionary::insert( const QByteArray &sKey, unsigned short i ) | 94 | void Gats::Dictionary::insert( const QByteArray &sKey, unsigned short i ) |
88 | { | 95 | { |
89 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 96 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
90 | sKey, new Gats::Integer( i ) | 97 | sKey, new Gats::Integer( i ) |
91 | ); | 98 | ); |
92 | } | 99 | } |
93 | 100 | ||
94 | void Gats::Dictionary::insert( const QByteArray &sKey, signed short i ) | 101 | void Gats::Dictionary::insert( const QByteArray &sKey, signed short i ) |
95 | { | 102 | { |
96 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 103 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
97 | sKey, new Gats::Integer( i ) | 104 | sKey, new Gats::Integer( i ) |
98 | ); | 105 | ); |
99 | } | 106 | } |
100 | 107 | ||
101 | void Gats::Dictionary::insert( const QByteArray &sKey, unsigned int i ) | 108 | void Gats::Dictionary::insert( const QByteArray &sKey, unsigned int i ) |
102 | { | 109 | { |
103 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 110 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
104 | sKey, new Gats::Integer( i ) | 111 | sKey, new Gats::Integer( i ) |
105 | ); | 112 | ); |
106 | } | 113 | } |
107 | 114 | ||
108 | void Gats::Dictionary::insert( const QByteArray &sKey, signed int i ) | 115 | void Gats::Dictionary::insert( const QByteArray &sKey, signed int i ) |
109 | { | 116 | { |
110 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 117 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
111 | sKey, new Gats::Integer( i ) | 118 | sKey, new Gats::Integer( i ) |
112 | ); | 119 | ); |
113 | } | 120 | } |
114 | 121 | ||
115 | void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long i ) | 122 | void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long i ) |
116 | { | 123 | { |
117 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 124 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
118 | sKey, new Gats::Integer( i ) | 125 | sKey, new Gats::Integer( i ) |
119 | ); | 126 | ); |
120 | } | 127 | } |
121 | 128 | ||
122 | void Gats::Dictionary::insert( const QByteArray &sKey, signed long i ) | 129 | void Gats::Dictionary::insert( const QByteArray &sKey, signed long i ) |
123 | { | 130 | { |
124 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 131 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
125 | sKey, new Gats::Integer( i ) | 132 | sKey, new Gats::Integer( i ) |
126 | ); | 133 | ); |
127 | } | 134 | } |
128 | 135 | ||
129 | void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long long i ) | 136 | void Gats::Dictionary::insert( const QByteArray &sKey, unsigned long long i ) |
130 | { | 137 | { |
131 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 138 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
132 | sKey, new Gats::Integer( i ) | 139 | sKey, new Gats::Integer( i ) |
133 | ); | 140 | ); |
134 | } | 141 | } |
135 | 142 | ||
136 | void Gats::Dictionary::insert( const QByteArray &sKey, signed long long i ) | 143 | void Gats::Dictionary::insert( const QByteArray &sKey, signed long long i ) |
137 | { | 144 | { |
138 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( | 145 | ((QHash<QByteArray, Gats::Object *> *)this)->insert( |
139 | sKey, new Gats::Integer( i ) | 146 | sKey, new Gats::Integer( i ) |
140 | ); | 147 | ); |
141 | } | 148 | } |
142 | /* | 149 | /* |
143 | void Gats::Dictionary::insert( const QByteArray &sKey, bool b ) | 150 | void Gats::Dictionary::insert( const QByteArray &sKey, bool b ) |
144 | { | 151 | { |
145 | QHash<QByteArray, Gats::Object *>::insert( | 152 | QHash<QByteArray, Gats::Object *>::insert( |
146 | sKey, new Gats::Boolean( b ) | 153 | sKey, new Gats::Boolean( b ) |
147 | ); | 154 | ); |
148 | }*/ | 155 | }*/ |
149 | 156 | ||
150 | void Gats::Dictionary::insert( const QByteArray &sKey, float d ) | 157 | void Gats::Dictionary::insert( const QByteArray &sKey, float d ) |
151 | { | 158 | { |
152 | QHash<QByteArray, Gats::Object *>::insert( | 159 | QHash<QByteArray, Gats::Object *>::insert( |
153 | sKey, new Gats::Float( d ) | 160 | sKey, new Gats::Float( d ) |
154 | ); | 161 | ); |
155 | } | 162 | } |
156 | 163 | ||
157 | void Gats::Dictionary::insert( const QByteArray &sKey, double d ) | 164 | void Gats::Dictionary::insert( const QByteArray &sKey, double d ) |
158 | { | 165 | { |
159 | QHash<QByteArray, Gats::Object *>::insert( | 166 | QHash<QByteArray, Gats::Object *>::insert( |
160 | sKey, new Gats::Float( d ) | 167 | sKey, new Gats::Float( d ) |
161 | ); | 168 | ); |
162 | } | 169 | } |
163 | 170 | ||
164 | void Gats::Dictionary::insert( const QByteArray &sKey, const char *s ) | 171 | void Gats::Dictionary::insert( const QByteArray &sKey, const char *s ) |
165 | { | 172 | { |
166 | QHash<QByteArray, Gats::Object *>::insert( | 173 | QHash<QByteArray, Gats::Object *>::insert( |
167 | sKey, new Gats::String( s ) | 174 | sKey, new Gats::String( s ) |
168 | ); | 175 | ); |
169 | } | 176 | } |
170 | 177 | ||
171 | void Gats::Dictionary::insert( const QByteArray &sKey, const QByteArray &s ) | 178 | void Gats::Dictionary::insert( const QByteArray &sKey, const QByteArray &s ) |
172 | { | 179 | { |
173 | QHash<QByteArray, Gats::Object *>::insert( | 180 | QHash<QByteArray, Gats::Object *>::insert( |
174 | sKey, new Gats::String( s ) | 181 | sKey, new Gats::String( s ) |
175 | ); | 182 | ); |
176 | } | 183 | } |
177 | 184 | ||
178 | void Gats::Dictionary::insertBool( const QByteArray &sKey, bool b ) | 185 | void Gats::Dictionary::insertBool( const QByteArray &sKey, bool b ) |
179 | { | 186 | { |
180 | QHash<QByteArray, Gats::Object *>::insert( | 187 | QHash<QByteArray, Gats::Object *>::insert( |
181 | sKey, new Gats::Boolean( b ) | 188 | sKey, new Gats::Boolean( b ) |
182 | ); | 189 | ); |
183 | } | 190 | } |
184 | 191 | ||
185 | void Gats::Dictionary::insertInt( const QByteArray &sKey, int64_t i ) | 192 | void Gats::Dictionary::insertInt( const QByteArray &sKey, int64_t i ) |
186 | { | 193 | { |
187 | QHash<QByteArray, Gats::Object *>::insert( | 194 | QHash<QByteArray, Gats::Object *>::insert( |
188 | sKey, new Gats::Integer( i ) | 195 | sKey, new Gats::Integer( i ) |
189 | ); | 196 | ); |
190 | } | 197 | } |
191 | 198 | ||
192 | void Gats::Dictionary::insertFloat( const QByteArray &sKey, double d ) | 199 | void Gats::Dictionary::insertFloat( const QByteArray &sKey, double d ) |
193 | { | 200 | { |
194 | QHash<QByteArray, Gats::Object *>::insert( | 201 | QHash<QByteArray, Gats::Object *>::insert( |
195 | sKey, new Gats::Float( d ) | 202 | sKey, new Gats::Float( d ) |
196 | ); | 203 | ); |
197 | } | 204 | } |
198 | 205 | ||
199 | void Gats::Dictionary::insertStr( const QByteArray &sKey, const QByteArray &s ) | 206 | void Gats::Dictionary::insertStr( const QByteArray &sKey, const QByteArray &s ) |
200 | { | 207 | { |
201 | QHash<QByteArray, Gats::Object *>::insert( | 208 | QHash<QByteArray, Gats::Object *>::insert( |
202 | sKey, new Gats::String( s ) | 209 | sKey, new Gats::String( s ) |
203 | ); | 210 | ); |
204 | } | 211 | } |
205 | 212 | ||
206 | void Gats::Dictionary::insertList( const QByteArray &sKey, Gats::List *pL ) | 213 | void Gats::Dictionary::insertList( const QByteArray &sKey, Gats::List *pL ) |
207 | { | 214 | { |
208 | QHash<QByteArray, Gats::Object *>::insert( | 215 | QHash<QByteArray, Gats::Object *>::insert( |
209 | sKey, pL | 216 | sKey, pL |
210 | ); | 217 | ); |
211 | } | 218 | } |
212 | 219 | ||
213 | void Gats::Dictionary::insertDict( const QByteArray &sKey, | 220 | void Gats::Dictionary::insertDict( const QByteArray &sKey, |
214 | Gats::Dictionary *pD ) | 221 | Gats::Dictionary *pD ) |
215 | { | 222 | { |
216 | QHash<QByteArray, Gats::Object *>::insert( | 223 | QHash<QByteArray, Gats::Object *>::insert( |
217 | sKey, pD | 224 | sKey, pD |
218 | ); | 225 | ); |
219 | } | 226 | } |
220 | 227 | ||
221 | Gats::List *Gats::Dictionary::insertList( const QByteArray &sKey ) | 228 | Gats::List *Gats::Dictionary::insertList( const QByteArray &sKey ) |
222 | { | 229 | { |
223 | Gats::List *pLst = new Gats::List(); | 230 | Gats::List *pLst = new Gats::List(); |
224 | insertList( sKey, pLst ); | 231 | insertList( sKey, pLst ); |
225 | return pLst; | 232 | return pLst; |
226 | } | 233 | } |
227 | 234 | ||
228 | Gats::Dictionary *Gats::Dictionary::insertDict( const QByteArray &sKey ) | 235 | Gats::Dictionary *Gats::Dictionary::insertDict( const QByteArray &sKey ) |
229 | { | 236 | { |
230 | Gats::Dictionary *pDict = new Gats::Dictionary(); | 237 | Gats::Dictionary *pDict = new Gats::Dictionary(); |
231 | insertDict( sKey, pDict ); | 238 | insertDict( sKey, pDict ); |
232 | return pDict; | 239 | return pDict; |
233 | } | 240 | } |
234 | 241 | ||
235 | bool Gats::Dictionary::valueBool( const QByteArray &sKey ) | 242 | bool Gats::Dictionary::valueBool( const QByteArray &sKey ) |
236 | { | 243 | { |
237 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( value( sKey ) ); | 244 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( value( sKey ) ); |
238 | if( !pOb ) | 245 | if( !pOb ) |
239 | throw "PUT GOOD EXCEPTION HERE"; | 246 | throw "PUT GOOD EXCEPTION HERE"; |
240 | 247 | ||
241 | return pOb->getValue(); | 248 | return pOb->getValue(); |
242 | } | 249 | } |
243 | 250 | ||
244 | int64_t Gats::Dictionary::valueInt( const QByteArray &sKey ) | 251 | int64_t Gats::Dictionary::valueInt( const QByteArray &sKey ) |
245 | { | 252 | { |
246 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( value( sKey ) ); | 253 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( value( sKey ) ); |
247 | if( !pOb ) | 254 | if( !pOb ) |
248 | throw "PUT GOOD EXCEPTION HERE"; | 255 | throw "PUT GOOD EXCEPTION HERE"; |
249 | 256 | ||
250 | return pOb->getValue(); | 257 | return pOb->getValue(); |
251 | } | 258 | } |
252 | 259 | ||
253 | double Gats::Dictionary::valueFloat( const QByteArray &sKey ) | 260 | double Gats::Dictionary::valueFloat( const QByteArray &sKey ) |
254 | { | 261 | { |
255 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( value( sKey ) ); | 262 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( value( sKey ) ); |
256 | if( !pOb ) | 263 | if( !pOb ) |
257 | throw "PUT GOOD EXCEPTION HERE"; | 264 | throw "PUT GOOD EXCEPTION HERE"; |
258 | 265 | ||
259 | return pOb->getValue(); | 266 | return pOb->getValue(); |
260 | } | 267 | } |
261 | 268 | ||
262 | QByteArray Gats::Dictionary::valueStr( const QByteArray &sKey ) | 269 | QByteArray Gats::Dictionary::valueStr( const QByteArray &sKey ) |
263 | { | 270 | { |
264 | Gats::String *pOb = dynamic_cast<Gats::String *>( value( sKey ) ); | 271 | Gats::String *pOb = dynamic_cast<Gats::String *>( value( sKey ) ); |
265 | if( !pOb ) | 272 | if( !pOb ) |
266 | throw "PUT GOOD EXCEPTION HERE"; | 273 | throw "PUT GOOD EXCEPTION HERE"; |
267 | 274 | ||
268 | return *pOb; | 275 | return *pOb; |
269 | } | 276 | } |
270 | 277 | ||
271 | Gats::List *Gats::Dictionary::valueList( const QByteArray &sKey ) | 278 | Gats::List *Gats::Dictionary::valueList( const QByteArray &sKey ) |
272 | { | 279 | { |
273 | Gats::List *pOb = dynamic_cast<Gats::List *>( value( sKey ) ); | 280 | Gats::List *pOb = dynamic_cast<Gats::List *>( value( sKey ) ); |
274 | if( !pOb ) | 281 | if( !pOb ) |
275 | throw "PUT GOOD EXCEPTION HERE"; | 282 | throw "PUT GOOD EXCEPTION HERE"; |
276 | 283 | ||
277 | return pOb; | 284 | return pOb; |
278 | } | 285 | } |
279 | 286 | ||
280 | Gats::Dictionary *Gats::Dictionary::valueDict( const QByteArray &sKey ) | 287 | Gats::Dictionary *Gats::Dictionary::valueDict( const QByteArray &sKey ) |
281 | { | 288 | { |
282 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( value( sKey ) ); | 289 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( value( sKey ) ); |
283 | if( !pOb ) | 290 | if( !pOb ) |
284 | throw "PUT GOOD EXCEPTION HERE"; | 291 | throw "PUT GOOD EXCEPTION HERE"; |
285 | 292 | ||
286 | return pOb; | 293 | return pOb; |
287 | } | 294 | } |
288 | 295 | ||
289 | bool Gats::Dictionary::valueBool( const QByteArray &sKey ) const | 296 | bool Gats::Dictionary::valueBool( const QByteArray &sKey ) const |
290 | { | 297 | { |
291 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( value( sKey ) ); | 298 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( value( sKey ) ); |
292 | if( !pOb ) | 299 | if( !pOb ) |
293 | throw "PUT GOOD EXCEPTION HERE"; | 300 | throw "PUT GOOD EXCEPTION HERE"; |
294 | 301 | ||
295 | return pOb->getValue(); | 302 | return pOb->getValue(); |
296 | } | 303 | } |
297 | 304 | ||
298 | int64_t Gats::Dictionary::valueInt( const QByteArray &sKey ) const | 305 | int64_t Gats::Dictionary::valueInt( const QByteArray &sKey ) const |
299 | { | 306 | { |
300 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( value( sKey ) ); | 307 | Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( value( sKey ) ); |
301 | if( !pOb ) | 308 | if( !pOb ) |
302 | throw "PUT GOOD EXCEPTION HERE"; | 309 | throw "PUT GOOD EXCEPTION HERE"; |
303 | 310 | ||
304 | return pOb->getValue(); | 311 | return pOb->getValue(); |
305 | } | 312 | } |
306 | 313 | ||
307 | double Gats::Dictionary::valueFloat( const QByteArray &sKey ) const | 314 | double Gats::Dictionary::valueFloat( const QByteArray &sKey ) const |
308 | { | 315 | { |
309 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( value( sKey ) ); | 316 | Gats::Float *pOb = dynamic_cast<Gats::Float *>( value( sKey ) ); |
310 | if( !pOb ) | 317 | if( !pOb ) |
311 | throw "PUT GOOD EXCEPTION HERE"; | 318 | throw "PUT GOOD EXCEPTION HERE"; |
312 | 319 | ||
313 | return pOb->getValue(); | 320 | return pOb->getValue(); |
314 | } | 321 | } |
315 | 322 | ||
316 | QByteArray Gats::Dictionary::valueStr( const QByteArray &sKey ) const | 323 | QByteArray Gats::Dictionary::valueStr( const QByteArray &sKey ) const |
317 | { | 324 | { |
318 | Gats::String *pOb = dynamic_cast<Gats::String *>( value( sKey ) ); | 325 | Gats::String *pOb = dynamic_cast<Gats::String *>( value( sKey ) ); |
319 | if( !pOb ) | 326 | if( !pOb ) |
320 | throw "PUT GOOD EXCEPTION HERE"; | 327 | throw "PUT GOOD EXCEPTION HERE"; |
321 | 328 | ||
322 | return *pOb; | 329 | return *pOb; |
323 | } | 330 | } |
324 | 331 | ||
325 | Gats::List *Gats::Dictionary::valueList( const QByteArray &sKey ) const | 332 | Gats::List *Gats::Dictionary::valueList( const QByteArray &sKey ) const |
326 | { | 333 | { |
327 | Gats::List *pOb = dynamic_cast<Gats::List *>( value( sKey ) ); | 334 | Gats::List *pOb = dynamic_cast<Gats::List *>( value( sKey ) ); |
328 | if( !pOb ) | 335 | if( !pOb ) |
329 | throw "PUT GOOD EXCEPTION HERE"; | 336 | throw "PUT GOOD EXCEPTION HERE"; |
330 | 337 | ||
331 | return pOb; | 338 | return pOb; |
332 | } | 339 | } |
333 | 340 | ||
334 | Gats::Dictionary *Gats::Dictionary::valueDict( const QByteArray &sKey ) const | 341 | Gats::Dictionary *Gats::Dictionary::valueDict( const QByteArray &sKey ) const |
335 | { | 342 | { |
336 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( value( sKey ) ); | 343 | Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( value( sKey ) ); |
337 | if( !pOb ) | 344 | if( !pOb ) |
338 | throw "PUT GOOD EXCEPTION HERE"; | 345 | throw "PUT GOOD EXCEPTION HERE"; |
339 | 346 | ||
340 | return pOb; | 347 | return pOb; |
341 | } | 348 | } |
342 | /* | 349 | /* |
343 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ) | 350 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ) |
344 | { | 351 | { |
345 | f << "(dict) {"; | 352 | f << "(dict) {"; |
346 | f.incIndent(); | 353 | f.incIndent(); |
347 | int iMax = 0; | 354 | int iMax = 0; |
348 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) | 355 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) |
349 | { | 356 | { |
350 | if( i.valueKey().valueSize() > iMax ) | 357 | if( i.valueKey().valueSize() > iMax ) |
351 | iMax = i.valueKey().valueSize(); | 358 | iMax = i.valueKey().valueSize(); |
352 | } | 359 | } |
353 | iMax += 2; | 360 | iMax += 2; |
354 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) | 361 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) |
355 | { | 362 | { |
356 | f << f.nl << Bu::Fmt( iMax ) << i.valueKey() + ": " << *i.getValue(); | 363 | f << f.nl << Bu::Fmt( iMax ) << i.valueKey() + ": " << *i.getValue(); |
357 | } | 364 | } |
358 | f.decIndent(); | 365 | f.decIndent(); |
359 | f << f.nl << "}"; | 366 | f << f.nl << "}"; |
360 | 367 | ||
361 | return f; | 368 | return f; |
362 | } | 369 | } |
363 | */ | 370 | */ |
diff --git a/c++-qt/src/dictionary.h b/c++-qt/src/dictionary.h index 7f95cf1..af1d436 100644 --- a/c++-qt/src/dictionary.h +++ b/c++-qt/src/dictionary.h | |||
@@ -1,3 +1,10 @@ | |||
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,62 +14,62 @@ | |||
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 QHash<QByteArray, Gats::Object *> | 20 | public QHash<QByteArray, Gats::Object *> |
14 | { | 21 | { |
15 | Q_OBJECT; | 22 | Q_OBJECT; |
16 | public: | 23 | public: |
17 | Dictionary(); | 24 | Dictionary(); |
18 | virtual ~Dictionary(); | 25 | virtual ~Dictionary(); |
19 | 26 | ||
20 | virtual Object *clone() const; | 27 | virtual Object *clone() const; |
21 | 28 | ||
22 | virtual Type getType() const { return typeDictionary; } | 29 | virtual Type getType() const { return typeDictionary; } |
23 | virtual void write( QIODevice &rOut ) const; | 30 | virtual void write( QIODevice &rOut ) const; |
24 | virtual void read( QIODevice &rIn, char cType ); | 31 | virtual void read( QIODevice &rIn, char cType ); |
25 | 32 | ||
26 | void insert( const QByteArray &sKey, const char *s ); | 33 | void insert( const QByteArray &sKey, const char *s ); |
27 | void insert( const QByteArray &sKey, const QByteArray &s ); | 34 | void insert( const QByteArray &sKey, const QByteArray &s ); |
28 | void insert( const QByteArray &sKey, char i ); | 35 | void insert( const QByteArray &sKey, char i ); |
29 | void insert( const QByteArray &sKey, unsigned char i ); | 36 | void insert( const QByteArray &sKey, unsigned char i ); |
30 | void insert( const QByteArray &sKey, signed char i ); | 37 | void insert( const QByteArray &sKey, signed char i ); |
31 | void insert( const QByteArray &sKey, unsigned short i ); | 38 | void insert( const QByteArray &sKey, unsigned short i ); |
32 | void insert( const QByteArray &sKey, signed short i ); | 39 | void insert( const QByteArray &sKey, signed short i ); |
33 | void insert( const QByteArray &sKey, unsigned int i ); | 40 | void insert( const QByteArray &sKey, unsigned int i ); |
34 | void insert( const QByteArray &sKey, signed int i ); | 41 | void insert( const QByteArray &sKey, signed int i ); |
35 | void insert( const QByteArray &sKey, unsigned long i ); | 42 | void insert( const QByteArray &sKey, unsigned long i ); |
36 | void insert( const QByteArray &sKey, signed long i ); | 43 | void insert( const QByteArray &sKey, signed long i ); |
37 | void insert( const QByteArray &sKey, unsigned long long i ); | 44 | void insert( const QByteArray &sKey, unsigned long long i ); |
38 | void insert( const QByteArray &sKey, signed long long i ); | 45 | void insert( const QByteArray &sKey, signed long long i ); |
39 | //void insert( const QByteArray &sKey, bool b ); | 46 | //void insert( const QByteArray &sKey, bool b ); |
40 | void insert( const QByteArray &sKey, float d ); | 47 | void insert( const QByteArray &sKey, float d ); |
41 | void insert( const QByteArray &sKey, double d ); | 48 | void insert( const QByteArray &sKey, double d ); |
42 | using QHash<QByteArray, Gats::Object *>::insert; | 49 | using QHash<QByteArray, Gats::Object *>::insert; |
43 | void insertBool( const QByteArray &sKey, bool b ); | 50 | void insertBool( const QByteArray &sKey, bool b ); |
44 | void insertInt( const QByteArray &sKey, int64_t i ); | 51 | void insertInt( const QByteArray &sKey, int64_t i ); |
45 | void insertFloat( const QByteArray &sKey, double d ); | 52 | void insertFloat( const QByteArray &sKey, double d ); |
46 | void insertStr( const QByteArray &sKey, const QByteArray &s ); | 53 | void insertStr( const QByteArray &sKey, const QByteArray &s ); |
47 | void insertList( const QByteArray &sKey, Gats::List *pL ); | 54 | void insertList( const QByteArray &sKey, Gats::List *pL ); |
48 | void insertDict( const QByteArray &sKey, Gats::Dictionary *pD ); | 55 | void insertDict( const QByteArray &sKey, Gats::Dictionary *pD ); |
49 | Gats::List *insertList( const QByteArray &sKey ); | 56 | Gats::List *insertList( const QByteArray &sKey ); |
50 | Gats::Dictionary *insertDict( const QByteArray &sKey ); | 57 | Gats::Dictionary *insertDict( const QByteArray &sKey ); |
51 | 58 | ||
52 | bool valueBool( const QByteArray &sKey ); | 59 | bool valueBool( const QByteArray &sKey ); |
53 | int64_t valueInt( const QByteArray &sKey ); | 60 | int64_t valueInt( const QByteArray &sKey ); |
54 | double valueFloat( const QByteArray &sKey ); | 61 | double valueFloat( const QByteArray &sKey ); |
55 | QByteArray valueStr( const QByteArray &sKey ); | 62 | QByteArray valueStr( const QByteArray &sKey ); |
56 | Gats::List *valueList( const QByteArray &sKey ); | 63 | Gats::List *valueList( const QByteArray &sKey ); |
57 | Gats::Dictionary *valueDict( const QByteArray &sKey ); | 64 | Gats::Dictionary *valueDict( const QByteArray &sKey ); |
58 | 65 | ||
59 | bool valueBool( const QByteArray &sKey ) const; | 66 | bool valueBool( const QByteArray &sKey ) const; |
60 | int64_t valueInt( const QByteArray &sKey ) const; | 67 | int64_t valueInt( const QByteArray &sKey ) const; |
61 | double valueFloat( const QByteArray &sKey ) const; | 68 | double valueFloat( const QByteArray &sKey ) const; |
62 | QByteArray valueStr( const QByteArray &sKey ) const; | 69 | QByteArray valueStr( const QByteArray &sKey ) const; |
63 | Gats::List *valueList( const QByteArray &sKey ) const; | 70 | Gats::List *valueList( const QByteArray &sKey ) const; |
64 | Gats::Dictionary *valueDict( const QByteArray &sKey ) const; | 71 | Gats::Dictionary *valueDict( const QByteArray &sKey ) const; |
65 | }; | 72 | }; |
66 | }; | 73 | }; |
67 | 74 | ||
68 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ); | 75 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ); |
diff --git a/c++-qt/src/float.cpp b/c++-qt/src/float.cpp index fedecf3..03ff755 100644 --- a/c++-qt/src/float.cpp +++ b/c++-qt/src/float.cpp | |||
@@ -1,15 +1,22 @@ | |||
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-qt/float.h" | 8 | #include "gats-qt/float.h" |
2 | #include "gats-qt/integer.h" | 9 | #include "gats-qt/integer.h" |
3 | 10 | ||
4 | #include <math.h> | 11 | #include <math.h> |
5 | 12 | ||
6 | Gats::Float::Float() : | 13 | Gats::Float::Float() : |
7 | fVal( 0.0 ) | 14 | fVal( 0.0 ) |
8 | { | 15 | { |
9 | } | 16 | } |
10 | 17 | ||
11 | Gats::Float::Float( double f ) : | 18 | Gats::Float::Float( double f ) : |
12 | fVal( f ) | 19 | fVal( f ) |
13 | { | 20 | { |
14 | } | 21 | } |
15 | 22 | ||
@@ -19,109 +26,109 @@ Gats::Float::~Float() | |||
19 | 26 | ||
20 | Gats::Object *Gats::Float::clone() const | 27 | Gats::Object *Gats::Float::clone() const |
21 | { | 28 | { |
22 | return new Gats::Float( fVal ); | 29 | return new Gats::Float( fVal ); |
23 | } | 30 | } |
24 | 31 | ||
25 | void Gats::Float::write( QIODevice &rOut ) const | 32 | void Gats::Float::write( QIODevice &rOut ) const |
26 | { | 33 | { |
27 | if( fVal == 0.0 ) | 34 | if( fVal == 0.0 ) |
28 | { | 35 | { |
29 | if( signbit( fVal ) ) | 36 | if( signbit( fVal ) ) |
30 | rOut.write("FZ", 2 ); | 37 | rOut.write("FZ", 2 ); |
31 | else | 38 | else |
32 | rOut.write("Fz", 2 ); | 39 | rOut.write("Fz", 2 ); |
33 | } | 40 | } |
34 | else if( !isfinite( fVal ) ) | 41 | else if( !isfinite( fVal ) ) |
35 | { | 42 | { |
36 | if( isnan( fVal ) ) | 43 | if( isnan( fVal ) ) |
37 | { | 44 | { |
38 | if( signbit( fVal ) ) | 45 | if( signbit( fVal ) ) |
39 | rOut.write("FN", 2 ); | 46 | rOut.write("FN", 2 ); |
40 | else | 47 | else |
41 | rOut.write("Fn", 2 ); | 48 | rOut.write("Fn", 2 ); |
42 | } | 49 | } |
43 | else | 50 | else |
44 | { | 51 | { |
45 | if( signbit( fVal ) ) | 52 | if( signbit( fVal ) ) |
46 | rOut.write("FI", 2 ); | 53 | rOut.write("FI", 2 ); |
47 | else | 54 | else |
48 | rOut.write("Fi", 2 ); | 55 | rOut.write("Fi", 2 ); |
49 | } | 56 | } |
50 | } | 57 | } |
51 | else | 58 | else |
52 | { | 59 | { |
53 | rOut.write("f", 1 ); | 60 | rOut.write("f", 1 ); |
54 | double d = fVal; | 61 | double d = fVal; |
55 | bool bNeg = false; | 62 | bool bNeg = false; |
56 | int64_t iScale=0; | 63 | int64_t iScale=0; |
57 | if( signbit( d ) ) | 64 | if( signbit( d ) ) |
58 | { | 65 | { |
59 | bNeg = true; | 66 | bNeg = true; |
60 | d = -d; | 67 | d = -d; |
61 | } | 68 | } |
62 | 69 | ||
63 | iScale = log( d ) / 0x1.62e42fefa39efp+2; // log( 256.0 ) | 70 | iScale = log( d ) / 0x1.62e42fefa39efp+2; // log( 256.0 ) |
64 | if( iScale < 0 ) iScale--; | 71 | if( iScale < 0 ) iScale--; |
65 | d /= pow( 256.0, iScale ); | 72 | d /= pow( 256.0, iScale ); |
66 | 73 | ||
67 | QByteArray s; | 74 | QByteArray s; |
68 | s += (uint8_t)(d); | 75 | s += (uint8_t)(d); |
69 | d -= (int)d; | 76 | d -= (int)d; |
70 | for( int j = 0; j < 150 && d; j++ ) | 77 | for( int j = 0; j < 150 && d; j++ ) |
71 | { | 78 | { |
72 | d = d*256.0; | 79 | d = d*256.0; |
73 | s += (uint8_t)d; | 80 | s += (uint8_t)d; |
74 | d -= (int)d; | 81 | d -= (int)d; |
75 | } | 82 | } |
76 | Gats::Integer::writePackedInt( rOut, bNeg?-s.size():s.size() ); | 83 | Gats::Integer::writePackedInt( rOut, bNeg?-s.size():s.size() ); |
77 | rOut.write( s.constData(), s.size() ); | 84 | rOut.write( s.constData(), s.size() ); |
78 | Gats::Integer::writePackedInt( rOut, iScale ); | 85 | Gats::Integer::writePackedInt( rOut, iScale ); |
79 | } | 86 | } |
80 | } | 87 | } |
81 | 88 | ||
82 | void Gats::Float::read( QIODevice &rIn, char cType ) | 89 | void Gats::Float::read( QIODevice &rIn, char cType ) |
83 | { | 90 | { |
84 | if( cType == 'F' ) | 91 | if( cType == 'F' ) |
85 | { | 92 | { |
86 | char buf; | 93 | char buf; |
87 | rIn.read( &buf, 1 ); | 94 | rIn.read( &buf, 1 ); |
88 | switch( buf ) | 95 | switch( buf ) |
89 | { | 96 | { |
90 | case 'N': fVal = -NAN; break; | 97 | case 'N': fVal = -NAN; break; |
91 | case 'n': fVal = NAN; break; | 98 | case 'n': fVal = NAN; break; |
92 | case 'I': fVal = -INFINITY; break; | 99 | case 'I': fVal = -INFINITY; break; |
93 | case 'i': fVal = INFINITY; break; | 100 | case 'i': fVal = INFINITY; break; |
94 | case 'Z': fVal = -0.0; break; | 101 | case 'Z': fVal = -0.0; break; |
95 | case 'z': fVal = 0.0; break; | 102 | case 'z': fVal = 0.0; break; |
96 | } | 103 | } |
97 | } | 104 | } |
98 | else if( cType == 'f' ) | 105 | else if( cType == 'f' ) |
99 | { | 106 | { |
100 | int64_t iStr; | 107 | int64_t iStr; |
101 | Gats::Integer::readPackedInt( rIn, iStr ); | 108 | Gats::Integer::readPackedInt( rIn, iStr ); |
102 | bool bNeg = false; | 109 | bool bNeg = false; |
103 | if( iStr < 0 ) | 110 | if( iStr < 0 ) |
104 | { | 111 | { |
105 | bNeg = true; | 112 | bNeg = true; |
106 | iStr = -iStr; | 113 | iStr = -iStr; |
107 | } | 114 | } |
108 | QByteArray s( iStr, '\0' ); | 115 | QByteArray s( iStr, '\0' ); |
109 | rIn.read( s.data(), iStr ); | 116 | rIn.read( s.data(), iStr ); |
110 | fVal = 0.0; | 117 | fVal = 0.0; |
111 | for( int j = iStr-1; j > 0; j-- ) | 118 | for( int j = iStr-1; j > 0; j-- ) |
112 | { | 119 | { |
113 | fVal = (fVal+(uint8_t)s[j])*0x1p-8; | 120 | fVal = (fVal+(uint8_t)s[j])*0x1p-8; |
114 | } | 121 | } |
115 | fVal += (uint8_t)s[0]; | 122 | fVal += (uint8_t)s[0]; |
116 | int64_t iScale; | 123 | int64_t iScale; |
117 | Gats::Integer::readPackedInt( rIn, iScale ); | 124 | Gats::Integer::readPackedInt( rIn, iScale ); |
118 | fVal *= pow( 256.0, iScale ); | 125 | fVal *= pow( 256.0, iScale ); |
119 | if( bNeg ) fVal = -fVal; | 126 | if( bNeg ) fVal = -fVal; |
120 | } | 127 | } |
121 | } | 128 | } |
122 | /* | 129 | /* |
123 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ) | 130 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ) |
124 | { | 131 | { |
125 | return f << "(float) " << flt.getValue(); | 132 | return f << "(float) " << flt.getValue(); |
126 | }*/ | 133 | }*/ |
127 | 134 | ||
diff --git a/c++-qt/src/float.h b/c++-qt/src/float.h index 93bfe18..6cc9950 100644 --- a/c++-qt/src/float.h +++ b/c++-qt/src/float.h | |||
@@ -1,3 +1,10 @@ | |||
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 | ||
@@ -5,26 +12,26 @@ | |||
5 | 12 | ||
6 | namespace Gats | 13 | namespace Gats |
7 | { | 14 | { |
8 | class Float : public Gats::Object | 15 | class Float : public Gats::Object |
9 | { | 16 | { |
10 | Q_OBJECT; | 17 | Q_OBJECT; |
11 | public: | 18 | public: |
12 | Float(); | 19 | Float(); |
13 | Float( double f ); | 20 | Float( double f ); |
14 | virtual ~Float(); | 21 | virtual ~Float(); |
15 | 22 | ||
16 | virtual Object *clone() const; | 23 | virtual Object *clone() const; |
17 | 24 | ||
18 | virtual Type getType() const { return typeFloat; } | 25 | virtual Type getType() const { return typeFloat; } |
19 | double getValue() const { return fVal; } | 26 | double getValue() const { return fVal; } |
20 | 27 | ||
21 | virtual void write( QIODevice &rOut ) const; | 28 | virtual void write( QIODevice &rOut ) const; |
22 | virtual void read( QIODevice &rIn, char cType ); | 29 | virtual void read( QIODevice &rIn, char cType ); |
23 | 30 | ||
24 | private: | 31 | private: |
25 | double fVal; | 32 | double fVal; |
26 | mutable QByteArray sWriteCache; | 33 | mutable QByteArray sWriteCache; |
27 | }; | 34 | }; |
28 | } | 35 | } |
29 | 36 | ||
30 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ); | 37 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ); |
diff --git a/c++-qt/src/gatsstream.cpp b/c++-qt/src/gatsstream.cpp index 920b2d6..f49fdb5 100644 --- a/c++-qt/src/gatsstream.cpp +++ b/c++-qt/src/gatsstream.cpp | |||
@@ -1,3 +1,10 @@ | |||
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-qt/gatsstream.h" | 8 | #include "gats-qt/gatsstream.h" |
2 | #include "gats-qt/object.h" | 9 | #include "gats-qt/object.h" |
3 | 10 | ||
@@ -10,7 +17,7 @@ | |||
10 | #include <QBuffer> | 17 | #include <QBuffer> |
11 | 18 | ||
12 | Gats::GatsStream::GatsStream( QIODevice &rStream ) : | 19 | Gats::GatsStream::GatsStream( QIODevice &rStream ) : |
13 | rStream( rStream ) | 20 | rStream( rStream ) |
14 | { | 21 | { |
15 | } | 22 | } |
16 | 23 | ||
@@ -20,110 +27,110 @@ Gats::GatsStream::~GatsStream() | |||
20 | 27 | ||
21 | Gats::Object *Gats::GatsStream::readObject() | 28 | Gats::Object *Gats::GatsStream::readObject() |
22 | { | 29 | { |
23 | char buf[1500]; | 30 | char buf[1500]; |
24 | 31 | ||
25 | do | 32 | do |
26 | { | 33 | { |
27 | if( qbRead.size() < 5 ) | 34 | if( qbRead.size() < 5 ) |
28 | { | 35 | { |
29 | int iRead = rStream.read( buf, 5-qbRead.size() ); | 36 | int iRead = rStream.read( buf, 5-qbRead.size() ); |
30 | qbRead.append( buf, iRead ); | 37 | qbRead.append( buf, iRead ); |
31 | 38 | ||
32 | if( qbRead.size() < 5 ) | 39 | if( qbRead.size() < 5 ) |
33 | return NULL; | 40 | return NULL; |
34 | } | 41 | } |
35 | } while( !skipReadNulls() ); | 42 | } while( !skipReadNulls() ); |
36 | 43 | ||
37 | uint8_t uVer; | 44 | uint8_t uVer; |
38 | uVer = qbRead[0]; | 45 | uVer = qbRead[0]; |
39 | 46 | ||
40 | int32_t iSize; | 47 | int32_t iSize; |
41 | memcpy( &iSize, qbRead.constData()+1, 4 ); | 48 | memcpy( &iSize, qbRead.constData()+1, 4 ); |
42 | iSize = ntohl( iSize ); | 49 | iSize = ntohl( iSize ); |
43 | while( qbRead.size() < iSize ) | 50 | while( qbRead.size() < iSize ) |
44 | { | 51 | { |
45 | int32_t iRead = iSize - qbRead.size(); | 52 | int32_t iRead = iSize - qbRead.size(); |
46 | if( iRead > 1500 ) | 53 | if( iRead > 1500 ) |
47 | iRead = 1500; | 54 | iRead = 1500; |
48 | int32_t iReal = rStream.read( buf, iRead ); | 55 | int32_t iReal = rStream.read( buf, iRead ); |
49 | qbRead.append( buf, iReal ); | 56 | qbRead.append( buf, iReal ); |
50 | if( iReal < iRead ) | 57 | if( iReal < iRead ) |
51 | { | 58 | { |
52 | return NULL; | 59 | return NULL; |
53 | } | 60 | } |
54 | } | 61 | } |
55 | 62 | ||
56 | if( qbRead.size() < iSize ) | 63 | if( qbRead.size() < iSize ) |
57 | { | 64 | { |
58 | return NULL; | 65 | return NULL; |
59 | } | 66 | } |
60 | 67 | ||
61 | QBuffer rTmp( &qbRead ); | 68 | QBuffer rTmp( &qbRead ); |
62 | rTmp.open( QIODevice::ReadOnly ); | 69 | rTmp.open( QIODevice::ReadOnly ); |
63 | rTmp.seek( 5 ); | 70 | rTmp.seek( 5 ); |
64 | Gats::Object *pObj = Gats::Object::read( rTmp ); | 71 | Gats::Object *pObj = Gats::Object::read( rTmp ); |
65 | qbRead.clear(); | 72 | qbRead.clear(); |
66 | 73 | ||
67 | emit objectRead( pObj ); | 74 | emit objectRead( pObj ); |
68 | 75 | ||
69 | return pObj; | 76 | return pObj; |
70 | } | 77 | } |
71 | 78 | ||
72 | void Gats::GatsStream::readAllObjects() | 79 | void Gats::GatsStream::readAllObjects() |
73 | { | 80 | { |
74 | while( readObject() ) { } | 81 | while( readObject() ) { } |
75 | } | 82 | } |
76 | 83 | ||
77 | void Gats::GatsStream::writeObject( Gats::Object *pObject ) | 84 | void Gats::GatsStream::writeObject( Gats::Object *pObject ) |
78 | { | 85 | { |
79 | QIODevice *pTmp; | 86 | QIODevice *pTmp; |
80 | if( rStream.isSequential() ) | 87 | if( rStream.isSequential() ) |
81 | { | 88 | { |
82 | pTmp = new QBuffer(); | 89 | pTmp = new QBuffer(); |
83 | pTmp->open( QIODevice::WriteOnly ); | 90 | pTmp->open( QIODevice::WriteOnly ); |
84 | } | 91 | } |
85 | else | 92 | else |
86 | { | 93 | { |
87 | pTmp = &rStream; | 94 | pTmp = &rStream; |
88 | } | 95 | } |
89 | 96 | ||
90 | uint8_t uBuf = 1; | 97 | uint8_t uBuf = 1; |
91 | uint32_t iSize = 0; | 98 | uint32_t iSize = 0; |
92 | pTmp->write( (const char *)&uBuf, 1 ); | 99 | pTmp->write( (const char *)&uBuf, 1 ); |
93 | uint64_t iSizePos = pTmp->pos(); | 100 | uint64_t iSizePos = pTmp->pos(); |
94 | pTmp->write( (const char *)&iSize, 4 ); | 101 | pTmp->write( (const char *)&iSize, 4 ); |
95 | pObject->write( *pTmp ); | 102 | pObject->write( *pTmp ); |
96 | iSize = htonl( pTmp->pos() ); | 103 | iSize = htonl( pTmp->pos() ); |
97 | uint64_t iEndPos = pTmp->pos(); | 104 | uint64_t iEndPos = pTmp->pos(); |
98 | pTmp->seek( iSizePos ); | 105 | pTmp->seek( iSizePos ); |
99 | pTmp->write( (const char *)&iSize, 4 ); | 106 | pTmp->write( (const char *)&iSize, 4 ); |
100 | 107 | ||
101 | if( rStream.isSequential() ) | 108 | if( rStream.isSequential() ) |
102 | { | 109 | { |
103 | pTmp->close(); | 110 | pTmp->close(); |
104 | rStream.write( ((QBuffer *)pTmp)->data() ); | 111 | rStream.write( ((QBuffer *)pTmp)->data() ); |
105 | delete pTmp; | 112 | delete pTmp; |
106 | } | 113 | } |
107 | else | 114 | else |
108 | { | 115 | { |
109 | pTmp->seek( iSizePos ); | 116 | pTmp->seek( iSizePos ); |
110 | } | 117 | } |
111 | } | 118 | } |
112 | 119 | ||
113 | bool Gats::GatsStream::skipReadNulls() | 120 | bool Gats::GatsStream::skipReadNulls() |
114 | { | 121 | { |
115 | bool bHaveSeeked = false; | 122 | bool bHaveSeeked = false; |
116 | for(;;) | 123 | for(;;) |
117 | { | 124 | { |
118 | if( qbRead.size() == 0 ) | 125 | if( qbRead.size() == 0 ) |
119 | return false; | 126 | return false; |
120 | if( qbRead.at(0) != 0 ) | 127 | if( qbRead.at(0) != 0 ) |
121 | return !bHaveSeeked; //true; | 128 | return !bHaveSeeked; //true; |
122 | else | 129 | else |
123 | { | 130 | { |
124 | qbRead.remove( 0, 1 ); | 131 | qbRead.remove( 0, 1 ); |
125 | bHaveSeeked = true; | 132 | bHaveSeeked = true; |
126 | } | 133 | } |
127 | } | 134 | } |
128 | } | 135 | } |
129 | 136 | ||
diff --git a/c++-qt/src/gatsstream.h b/c++-qt/src/gatsstream.h index 90e0514..979ca60 100644 --- a/c++-qt/src/gatsstream.h +++ b/c++-qt/src/gatsstream.h | |||
@@ -1,3 +1,10 @@ | |||
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,67 +13,67 @@ | |||
6 | 13 | ||
7 | namespace Gats | 14 | namespace Gats |
8 | { | 15 | { |
9 | class Object; | 16 | class Object; |
10 | 17 | ||
11 | class GatsStream : public QObject | 18 | class GatsStream : public QObject |
12 | { | 19 | { |
13 | Q_OBJECT; | 20 | Q_OBJECT; |
14 | public: | 21 | public: |
15 | GatsStream( QIODevice &rStream ); | 22 | GatsStream( QIODevice &rStream ); |
16 | virtual ~GatsStream(); | 23 | virtual ~GatsStream(); |
17 | 24 | ||
18 | public slots: | 25 | public slots: |
19 | /** | 26 | /** |
20 | * Read an object packet from the assosiated stream. This will make | 27 | * Read an object packet from the assosiated stream. This will make |
21 | * every effort to only read exactly enough data to describe one packet, | 28 | * every effort to only read exactly enough data to describe one packet, |
22 | * in case you want to do other things with your stream. It will | 29 | * in case you want to do other things with your stream. It will |
23 | * automatically skip NULL byte spacing between packets, which makes | 30 | * automatically skip NULL byte spacing between packets, which makes |
24 | * a convinient padding method for encrypted data streams. Since | 31 | * a convinient padding method for encrypted data streams. Since |
25 | * sizing information is available in the packet header exact amounts | 32 | * sizing information is available in the packet header exact amounts |
26 | * of data can be read, however this function doesn't assume that it | 33 | * of data can be read, however this function doesn't assume that it |
27 | * can read the entire object in one operation. If it fails to read | 34 | * can read the entire object in one operation. If it fails to read |
28 | * a complete packet in one call, it will keep the data it's read so | 35 | * a complete packet in one call, it will keep the data it's read so |
29 | * far buffered and return NULL, ready for another attempt. You can | 36 | * far buffered and return NULL, ready for another attempt. You can |
30 | * use the function hasReadBuffer() to deterimne if readObject() | 37 | * use the function hasReadBuffer() to deterimne if readObject() |
31 | * has read part of an object packet or not. If readObject returns | 38 | * has read part of an object packet or not. If readObject returns |
32 | * non-null then hasReadBuffer should return false on it's next call. | 39 | * non-null then hasReadBuffer should return false on it's next call. |
33 | */ | 40 | */ |
34 | Gats::Object *readObject(); | 41 | Gats::Object *readObject(); |
35 | 42 | ||
36 | /** | 43 | /** |
37 | * Works exactly like readObject, except it reads all pending objects | 44 | * Works exactly like readObject, except it reads all pending objects |
38 | * and emits a objectRead signal for each one read. It doesn't return | 45 | * and emits a objectRead signal for each one read. It doesn't return |
39 | * anything. This is perfect for connecting to a QIODevice's readRead | 46 | * anything. This is perfect for connecting to a QIODevice's readRead |
40 | * signal. | 47 | * signal. |
41 | */ | 48 | */ |
42 | void readAllObjects(); | 49 | void readAllObjects(); |
43 | 50 | ||
44 | public: | 51 | public: |
45 | /** | 52 | /** |
46 | * Write an object | 53 | * Write an object |
47 | */ | 54 | */ |
48 | void writeObject( Gats::Object *pObject ); | 55 | void writeObject( Gats::Object *pObject ); |
49 | 56 | ||
50 | /** | 57 | /** |
51 | * Tells you if there is data still in the read buffer, i.e. that a | 58 | * Tells you if there is data still in the read buffer, i.e. that a |
52 | * packet is part way through being read. If readObject has returned | 59 | * packet is part way through being read. If readObject has returned |
53 | * non-null in the most recent call, this should always be false. | 60 | * non-null in the most recent call, this should always be false. |
54 | */ | 61 | */ |
55 | bool hasReadBuffer() { return qbRead.size() > 0; } | 62 | bool hasReadBuffer() { return qbRead.size() > 0; } |
56 | int getReadBufferSize() { return qbRead.size(); } | 63 | int getReadBufferSize() { return qbRead.size(); } |
57 | 64 | ||
58 | QIODevice &getIODevice() { return rStream; } | 65 | QIODevice &getIODevice() { return rStream; } |
59 | 66 | ||
60 | signals: | 67 | signals: |
61 | void objectRead( Gats::Object *pObj ); | 68 | void objectRead( Gats::Object *pObj ); |
62 | 69 | ||
63 | private: | 70 | private: |
64 | bool skipReadNulls(); | 71 | bool skipReadNulls(); |
65 | 72 | ||
66 | private: | 73 | private: |
67 | QIODevice &rStream; | 74 | QIODevice &rStream; |
68 | QByteArray qbRead; | 75 | QByteArray qbRead; |
69 | }; | 76 | }; |
70 | }; | 77 | }; |
71 | 78 | ||
72 | #endif | 79 | #endif |
diff --git a/c++-qt/src/integer.cpp b/c++-qt/src/integer.cpp index 82727f3..721c434 100644 --- a/c++-qt/src/integer.cpp +++ b/c++-qt/src/integer.cpp | |||
@@ -1,12 +1,19 @@ | |||
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-qt/integer.h" | 8 | #include "gats-qt/integer.h" |
2 | 9 | ||
3 | Gats::Integer::Integer() : | 10 | Gats::Integer::Integer() : |
4 | iVal( 0 ) | 11 | iVal( 0 ) |
5 | { | 12 | { |
6 | } | 13 | } |
7 | 14 | ||
8 | Gats::Integer::Integer( int64_t iVal ) : | 15 | Gats::Integer::Integer( int64_t iVal ) : |
9 | iVal( iVal ) | 16 | iVal( iVal ) |
10 | { | 17 | { |
11 | } | 18 | } |
12 | 19 | ||
@@ -16,22 +23,22 @@ Gats::Integer::~Integer() | |||
16 | 23 | ||
17 | Gats::Object *Gats::Integer::clone() const | 24 | Gats::Object *Gats::Integer::clone() const |
18 | { | 25 | { |
19 | return new Gats::Integer( iVal ); | 26 | return new Gats::Integer( iVal ); |
20 | } | 27 | } |
21 | 28 | ||
22 | void Gats::Integer::write( QIODevice &rOut ) const | 29 | void Gats::Integer::write( QIODevice &rOut ) const |
23 | { | 30 | { |
24 | rOut.write("i", 1 ); | 31 | rOut.write("i", 1 ); |
25 | writePackedInt( rOut, iVal ); | 32 | writePackedInt( rOut, iVal ); |
26 | } | 33 | } |
27 | 34 | ||
28 | void Gats::Integer::read( QIODevice &rIn, char cType ) | 35 | void Gats::Integer::read( QIODevice &rIn, char cType ) |
29 | { | 36 | { |
30 | readPackedInt( rIn, iVal ); | 37 | readPackedInt( rIn, iVal ); |
31 | } | 38 | } |
32 | /* | 39 | /* |
33 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ) | 40 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ) |
34 | { | 41 | { |
35 | return f << "(int) " << i.getValue(); | 42 | return f << "(int) " << i.getValue(); |
36 | } | 43 | } |
37 | */ | 44 | */ |
diff --git a/c++-qt/src/integer.h b/c++-qt/src/integer.h index db36e30..9178796 100644 --- a/c++-qt/src/integer.h +++ b/c++-qt/src/integer.h | |||
@@ -1,3 +1,10 @@ | |||
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,78 +16,78 @@ | |||
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 | Q_OBJECT; | 21 | Q_OBJECT; |
15 | public: | 22 | public: |
16 | Integer(); | 23 | Integer(); |
17 | Integer( int64_t iVal ); | 24 | Integer( int64_t iVal ); |
18 | virtual ~Integer(); | 25 | virtual ~Integer(); |
19 | 26 | ||
20 | virtual Object *clone() const; | 27 | virtual Object *clone() const; |
21 | 28 | ||
22 | virtual Type getType() const { return typeInteger; } | 29 | virtual Type getType() const { return typeInteger; } |
23 | int64_t getValue() const { return iVal; } | 30 | int64_t getValue() const { return iVal; } |
24 | void setValue( int64_t iNewVal ) { iVal = iNewVal; } | 31 | void setValue( int64_t iNewVal ) { iVal = iNewVal; } |
25 | 32 | ||
26 | virtual void write( QIODevice &rOut ) const; | 33 | virtual void write( QIODevice &rOut ) const; |
27 | virtual void read( QIODevice &rIn, char cType ); | 34 | virtual void read( QIODevice &rIn, char cType ); |
28 | 35 | ||
29 | template<typename itype> | 36 | template<typename itype> |
30 | static void readPackedInt( QIODevice &rStream, itype &rOut ) | 37 | static void readPackedInt( QIODevice &rStream, itype &rOut ) |
31 | { | 38 | { |
32 | int8_t b; | 39 | int8_t b; |
33 | rOut = 0; | 40 | rOut = 0; |
34 | bool bNeg; | 41 | bool bNeg; |
35 | 42 | ||
36 | rStream.read( (char *)&b, 1 ); | 43 | rStream.read( (char *)&b, 1 ); |
37 | bNeg = ( b&0x40 ); | 44 | bNeg = ( b&0x40 ); |
38 | rOut |= (itype(b&0x3F)); | 45 | rOut |= (itype(b&0x3F)); |
39 | int c = 0; | 46 | int c = 0; |
40 | while( (b&0x80) ) | 47 | while( (b&0x80) ) |
41 | { | 48 | { |
42 | rStream.read( (char *)&b, 1 ); | 49 | rStream.read( (char *)&b, 1 ); |
43 | rOut |= (itype(b&0x7F)) << (6+7*(c++)); | 50 | rOut |= (itype(b&0x7F)) << (6+7*(c++)); |
44 | } | 51 | } |
45 | if( bNeg ) rOut = -rOut; | 52 | if( bNeg ) rOut = -rOut; |
46 | } | 53 | } |
47 | 54 | ||
48 | template<typename itype> | 55 | template<typename itype> |
49 | static void writePackedInt( QIODevice &rStream, itype iIn ) | 56 | static void writePackedInt( QIODevice &rStream, itype iIn ) |
50 | { | 57 | { |
51 | uint8_t b; | 58 | uint8_t b; |
52 | 59 | ||
53 | if( iIn < 0 ) | 60 | if( iIn < 0 ) |
54 | { | 61 | { |
55 | iIn = -iIn; | 62 | iIn = -iIn; |
56 | b = (iIn&0x3F); | 63 | b = (iIn&0x3F); |
57 | if( iIn > b ) | 64 | if( iIn > b ) |
58 | b |= 0x80 | 0x40; | 65 | b |= 0x80 | 0x40; |
59 | else | 66 | else |
60 | b |= 0x40; | 67 | b |= 0x40; |
61 | } | 68 | } |
62 | else | 69 | else |
63 | { | 70 | { |
64 | b = (iIn&0x3F); | 71 | b = (iIn&0x3F); |
65 | if( iIn > b ) | 72 | if( iIn > b ) |
66 | b |= 0x80; | 73 | b |= 0x80; |
67 | } | 74 | } |
68 | rStream.write( (const char *)&b, 1 ); | 75 | rStream.write( (const char *)&b, 1 ); |
69 | iIn = iIn >> 6; | 76 | iIn = iIn >> 6; |
70 | 77 | ||
71 | while( iIn ) | 78 | while( iIn ) |
72 | { | 79 | { |
73 | b = (iIn&0x7F); | 80 | b = (iIn&0x7F); |
74 | if( iIn > b ) | 81 | if( iIn > b ) |
75 | b |= 0x80; | 82 | b |= 0x80; |
76 | rStream.write( (const char *)&b, 1 ); | 83 | rStream.write( (const char *)&b, 1 ); |
77 | iIn = iIn >> 7; | 84 | iIn = iIn >> 7; |
78 | } | 85 | } |
79 | } | 86 | } |
80 | 87 | ||
81 | private: | 88 | private: |
82 | int64_t iVal; | 89 | int64_t iVal; |
83 | }; | 90 | }; |
84 | }; | 91 | }; |
85 | 92 | ||
86 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); | 93 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); |
diff --git a/c++-qt/src/list.cpp b/c++-qt/src/list.cpp index 8a648e9..158a7c1 100644 --- a/c++-qt/src/list.cpp +++ b/c++-qt/src/list.cpp | |||
@@ -1,3 +1,10 @@ | |||
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-qt/list.h" | 8 | #include "gats-qt/list.h" |
2 | 9 | ||
3 | #include "gats-qt/string.h" | 10 | #include "gats-qt/string.h" |
@@ -12,193 +19,193 @@ Gats::List::List() | |||
12 | 19 | ||
13 | Gats::List::~List() | 20 | Gats::List::~List() |
14 | { | 21 | { |
15 | for( iterator i = begin(); i != end(); i++ ) | 22 | for( iterator i = begin(); i != end(); i++ ) |
16 | { | 23 | { |
17 | delete *i; | 24 | delete *i; |
18 | } | 25 | } |
19 | } | 26 | } |
20 | 27 | ||
21 | Gats::Object *Gats::List::clone() const | 28 | Gats::Object *Gats::List::clone() const |
22 | { | 29 | { |
23 | Gats::List *pClone = new Gats::List; | 30 | Gats::List *pClone = new Gats::List; |
24 | 31 | ||
25 | for( const_iterator i = begin(); i != end(); i++ ) | 32 | for( const_iterator i = begin(); i != end(); i++ ) |
26 | { | 33 | { |
27 | pClone->append( (*i)->clone() ); | 34 | pClone->append( (*i)->clone() ); |
28 | } | 35 | } |
29 | 36 | ||
30 | return pClone; | 37 | return pClone; |
31 | } | 38 | } |
32 | 39 | ||
33 | void Gats::List::write( QIODevice &rOut ) const | 40 | void Gats::List::write( QIODevice &rOut ) const |
34 | { | 41 | { |
35 | rOut.write("l", 1 ); | 42 | rOut.write("l", 1 ); |
36 | for( const_iterator i = begin(); i != end(); i++ ) | 43 | for( const_iterator i = begin(); i != end(); i++ ) |
37 | { | 44 | { |
38 | (*i)->write( rOut ); | 45 | (*i)->write( rOut ); |
39 | } | 46 | } |
40 | rOut.write("e", 1 ); | 47 | rOut.write("e", 1 ); |
41 | } | 48 | } |
42 | 49 | ||
43 | void Gats::List::read( QIODevice &rIn, char cType ) | 50 | void Gats::List::read( QIODevice &rIn, char cType ) |
44 | { | 51 | { |
45 | for(;;) | 52 | for(;;) |
46 | { | 53 | { |
47 | Gats::Object *pObj = Gats::Object::read( rIn ); | 54 | Gats::Object *pObj = Gats::Object::read( rIn ); |
48 | if( pObj == NULL ) | 55 | if( pObj == NULL ) |
49 | break; | 56 | break; |
50 | append( pObj ); | 57 | append( pObj ); |
51 | } | 58 | } |
52 | } | 59 | } |
53 | 60 | ||
54 | void Gats::List::append( const char *s ) | 61 | void Gats::List::append( const char *s ) |
55 | { | 62 | { |
56 | QList<Gats::Object *>::append( new Gats::String( s ) ); | 63 | QList<Gats::Object *>::append( new Gats::String( s ) ); |
57 | } | 64 | } |
58 | 65 | ||
59 | void Gats::List::append( const QByteArray &s ) | 66 | void Gats::List::append( const QByteArray &s ) |
60 | { | 67 | { |
61 | QList<Gats::Object *>::append( new Gats::String( s ) ); | 68 | QList<Gats::Object *>::append( new Gats::String( s ) ); |
62 | } | 69 | } |
63 | 70 | ||
64 | void Gats::List::append( int32_t i ) | 71 | void Gats::List::append( int32_t i ) |
65 | { | 72 | { |
66 | QList<Gats::Object *>::append( new Gats::Integer( i ) ); | 73 | QList<Gats::Object *>::append( new Gats::Integer( i ) ); |
67 | } | 74 | } |
68 | 75 | ||
69 | void Gats::List::append( int64_t i ) | 76 | void Gats::List::append( int64_t i ) |
70 | { | 77 | { |
71 | QList<Gats::Object *>::append( new Gats::Integer( i ) ); | 78 | QList<Gats::Object *>::append( new Gats::Integer( i ) ); |
72 | } | 79 | } |
73 | 80 | ||
74 | void Gats::List::append( double d ) | 81 | void Gats::List::append( double d ) |
75 | { | 82 | { |
76 | QList<Gats::Object *>::append( new Gats::Float( d ) ); | 83 | QList<Gats::Object *>::append( new Gats::Float( d ) ); |
77 | } | 84 | } |
78 | 85 | ||
79 | void Gats::List::appendStr( const QByteArray &s ) | 86 | void Gats::List::appendStr( const QByteArray &s ) |
80 | { | 87 | { |
81 | QList<Gats::Object *>::append( new Gats::String( s ) ); | 88 | QList<Gats::Object *>::append( new Gats::String( s ) ); |
82 | } | 89 | } |
83 | 90 | ||
84 | void Gats::List::appendInt( int64_t i ) | 91 | void Gats::List::appendInt( int64_t i ) |
85 | { | 92 | { |
86 | QList<Gats::Object *>::append( new Gats::Integer( i ) ); | 93 | QList<Gats::Object *>::append( new Gats::Integer( i ) ); |
87 | } | 94 | } |
88 | 95 | ||
89 | void Gats::List::appendFloat( double d ) | 96 | void Gats::List::appendFloat( double d ) |
90 | { | 97 | { |
91 | QList<Gats::Object *>::append( new Gats::Float( d ) ); | 98 | QList<Gats::Object *>::append( new Gats::Float( d ) ); |
92 | } | 99 | } |
93 | 100 | ||
94 | void Gats::List::appendBool( bool b ) | 101 | void Gats::List::appendBool( bool b ) |
95 | { | 102 | { |
96 | QList<Gats::Object *>::append( new Gats::Boolean( b ) ); | 103 | QList<Gats::Object *>::append( new Gats::Boolean( b ) ); |
97 | } | 104 | } |
98 | 105 | ||
99 | void Gats::List::appendList( Gats::List *pL ) | 106 | void Gats::List::appendList( Gats::List *pL ) |
100 | { | 107 | { |
101 | QList<Gats::Object *>::append( pL ); | 108 | QList<Gats::Object *>::append( pL ); |
102 | } | 109 | } |
103 | 110 | ||
104 | void Gats::List::appendDict( Gats::Dictionary *pD ) | 111 | void Gats::List::appendDict( Gats::Dictionary *pD ) |
105 | { | 112 | { |
106 | QList<Gats::Object *>::append( pD ); | 113 | QList<Gats::Object *>::append( pD ); |
107 | } | 114 | } |
108 | 115 | ||
109 | Gats::List *Gats::List::appendList() | 116 | Gats::List *Gats::List::appendList() |
110 | { | 117 | { |
111 | Gats::List *pLst = new Gats::List(); | 118 | Gats::List *pLst = new Gats::List(); |
112 | appendList( pLst ); | 119 | appendList( pLst ); |
113 | return pLst; | 120 | return pLst; |
114 | } | 121 | } |
115 | 122 | ||
116 | Gats::Dictionary *Gats::List::appendDict() | 123 | Gats::Dictionary *Gats::List::appendDict() |
117 | { | 124 | { |
118 | Gats::Dictionary *pDict = new Gats::Dictionary(); | 125 | Gats::Dictionary *pDict = new Gats::Dictionary(); |
119 | appendDict( pDict ); | 126 | appendDict( pDict ); |
120 | return pDict; | 127 | return pDict; |
121 | } | 128 | } |
122 | 129 | ||
123 | void Gats::List::prepend( const char *s ) | 130 | void Gats::List::prepend( const char *s ) |
124 | { | 131 | { |
125 | QList<Gats::Object *>::prepend( new Gats::String( s ) ); | 132 | QList<Gats::Object *>::prepend( new Gats::String( s ) ); |
126 | } | 133 | } |
127 | 134 | ||
128 | void Gats::List::prepend( const QByteArray &s ) | 135 | void Gats::List::prepend( const QByteArray &s ) |
129 | { | 136 | { |
130 | QList<Gats::Object *>::prepend( new Gats::String( s ) ); | 137 | QList<Gats::Object *>::prepend( new Gats::String( s ) ); |
131 | } | 138 | } |
132 | 139 | ||
133 | void Gats::List::prepend( int32_t i ) | 140 | void Gats::List::prepend( int32_t i ) |
134 | { | 141 | { |
135 | QList<Gats::Object *>::prepend( new Gats::Integer( i ) ); | 142 | QList<Gats::Object *>::prepend( new Gats::Integer( i ) ); |
136 | } | 143 | } |
137 | 144 | ||
138 | void Gats::List::prepend( int64_t i ) | 145 | void Gats::List::prepend( int64_t i ) |
139 | { | 146 | { |
140 | QList<Gats::Object *>::prepend( new Gats::Integer( i ) ); | 147 | QList<Gats::Object *>::prepend( new Gats::Integer( i ) ); |
141 | } | 148 | } |
142 | 149 | ||
143 | void Gats::List::prepend( double d ) | 150 | void Gats::List::prepend( double d ) |
144 | { | 151 | { |
145 | QList<Gats::Object *>::prepend( new Gats::Float( d ) ); | 152 | QList<Gats::Object *>::prepend( new Gats::Float( d ) ); |
146 | } | 153 | } |
147 | 154 | ||
148 | void Gats::List::prependStr( const QByteArray &s ) | 155 | void Gats::List::prependStr( const QByteArray &s ) |
149 | { | 156 | { |
150 | QList<Gats::Object *>::prepend( new Gats::String( s ) ); | 157 | QList<Gats::Object *>::prepend( new Gats::String( s ) ); |
151 | } | 158 | } |
152 | 159 | ||
153 | void Gats::List::prependInt( int64_t i ) | 160 | void Gats::List::prependInt( int64_t i ) |
154 | { | 161 | { |
155 | QList<Gats::Object *>::prepend( new Gats::Integer( i ) ); | 162 | QList<Gats::Object *>::prepend( new Gats::Integer( i ) ); |
156 | } | 163 | } |
157 | 164 | ||
158 | void Gats::List::prependFloat( double d ) | 165 | void Gats::List::prependFloat( double d ) |
159 | { | 166 | { |
160 | QList<Gats::Object *>::prepend( new Gats::Float( d ) ); | 167 | QList<Gats::Object *>::prepend( new Gats::Float( d ) ); |
161 | } | 168 | } |
162 | 169 | ||
163 | void Gats::List::prependBool( bool b ) | 170 | void Gats::List::prependBool( bool b ) |
164 | { | 171 | { |
165 | QList<Gats::Object *>::prepend( new Gats::Boolean( b ) ); | 172 | QList<Gats::Object *>::prepend( new Gats::Boolean( b ) ); |
166 | } | 173 | } |
167 | 174 | ||
168 | void Gats::List::prependList( Gats::List *pL ) | 175 | void Gats::List::prependList( Gats::List *pL ) |
169 | { | 176 | { |
170 | QList<Gats::Object *>::prepend( pL ); | 177 | QList<Gats::Object *>::prepend( pL ); |
171 | } | 178 | } |
172 | 179 | ||
173 | void Gats::List::prependDict( Gats::Dictionary *pD ) | 180 | void Gats::List::prependDict( Gats::Dictionary *pD ) |
174 | { | 181 | { |
175 | QList<Gats::Object *>::prepend( pD ); | 182 | QList<Gats::Object *>::prepend( pD ); |
176 | } | 183 | } |
177 | 184 | ||
178 | Gats::List *Gats::List::prependList() | 185 | Gats::List *Gats::List::prependList() |
179 | { | 186 | { |
180 | Gats::List *pLst = new Gats::List(); | 187 | Gats::List *pLst = new Gats::List(); |
181 | prependList( pLst ); | 188 | prependList( pLst ); |
182 | return pLst; | 189 | return pLst; |
183 | } | 190 | } |
184 | 191 | ||
185 | Gats::Dictionary *Gats::List::prependDict() | 192 | Gats::Dictionary *Gats::List::prependDict() |
186 | { | 193 | { |
187 | Gats::Dictionary *pDict = new Gats::Dictionary(); | 194 | Gats::Dictionary *pDict = new Gats::Dictionary(); |
188 | prependDict( pDict ); | 195 | prependDict( pDict ); |
189 | return pDict; | 196 | return pDict; |
190 | } | 197 | } |
191 | /* | 198 | /* |
192 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ) | 199 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ) |
193 | { | 200 | { |
194 | f << "(list) ["; | 201 | f << "(list) ["; |
195 | f.incIndent(); | 202 | f.incIndent(); |
196 | for( Gats::List::const_iterator i = l.begin(); i; i++ ) | 203 | for( Gats::List::const_iterator i = l.begin(); i; i++ ) |
197 | { | 204 | { |
198 | f << f.nl << **i; | 205 | f << f.nl << **i; |
199 | } | 206 | } |
200 | f.decIndent(); | 207 | f.decIndent(); |
201 | f << f.nl << "]"; | 208 | f << f.nl << "]"; |
202 | return f; | 209 | return f; |
203 | } | 210 | } |
204 | */ | 211 | */ |
diff --git a/c++-qt/src/list.h b/c++-qt/src/list.h index 6e5ac56..7577bad 100644 --- a/c++-qt/src/list.h +++ b/c++-qt/src/list.h | |||
@@ -1,3 +1,10 @@ | |||
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 | ||
@@ -6,52 +13,52 @@ | |||
6 | 13 | ||
7 | namespace Gats | 14 | namespace Gats |
8 | { | 15 | { |
9 | class Dictionary; | 16 | class Dictionary; |
10 | 17 | ||
11 | class List : public Gats::Object, public QList<Gats::Object *> | 18 | class List : public Gats::Object, public QList<Gats::Object *> |
12 | { | 19 | { |
13 | Q_OBJECT; | 20 | Q_OBJECT; |
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 | 26 | ||
20 | virtual Type getType() const { return typeList; } | 27 | virtual Type getType() const { return typeList; } |
21 | 28 | ||
22 | virtual void write( QIODevice &rOut ) const; | 29 | virtual void write( QIODevice &rOut ) const; |
23 | virtual void read( QIODevice &rIn, char cType ); | 30 | virtual void read( QIODevice &rIn, char cType ); |
24 | 31 | ||
25 | void append( const char *s ); | 32 | void append( const char *s ); |
26 | void append( const QByteArray &s ); | 33 | void append( const QByteArray &s ); |
27 | void append( int32_t i ); | 34 | void append( int32_t i ); |
28 | void append( int64_t i ); | 35 | void append( int64_t i ); |
29 | void append( double d ); | 36 | void append( double d ); |
30 | using QList<Gats::Object *>::append; | 37 | using QList<Gats::Object *>::append; |
31 | void appendStr( const QByteArray &s ); | 38 | void appendStr( const QByteArray &s ); |
32 | void appendInt( int64_t i ); | 39 | void appendInt( int64_t i ); |
33 | void appendFloat( double d ); | 40 | void appendFloat( double d ); |
34 | void appendBool( bool b ); | 41 | void appendBool( bool b ); |
35 | void appendList( Gats::List *pL ); | 42 | void appendList( Gats::List *pL ); |
36 | void appendDict( Gats::Dictionary *pD ); | 43 | void appendDict( Gats::Dictionary *pD ); |
37 | Gats::List *appendList(); | 44 | Gats::List *appendList(); |
38 | Gats::Dictionary *appendDict(); | 45 | Gats::Dictionary *appendDict(); |
39 | 46 | ||
40 | void prepend( const char *s ); | 47 | void prepend( const char *s ); |
41 | void prepend( const QByteArray &s ); | 48 | void prepend( const QByteArray &s ); |
42 | void prepend( int32_t i ); | 49 | void prepend( int32_t i ); |
43 | void prepend( int64_t i ); | 50 | void prepend( int64_t i ); |
44 | void prepend( double d ); | 51 | void prepend( double d ); |
45 | using QList<Gats::Object *>::prepend; | 52 | using QList<Gats::Object *>::prepend; |
46 | void prependStr( const QByteArray &s ); | 53 | void prependStr( const QByteArray &s ); |
47 | void prependInt( int64_t i ); | 54 | void prependInt( int64_t i ); |
48 | void prependFloat( double d ); | 55 | void prependFloat( double d ); |
49 | void prependBool( bool b ); | 56 | void prependBool( bool b ); |
50 | void prependList( Gats::List *pL ); | 57 | void prependList( Gats::List *pL ); |
51 | void prependDict( Gats::Dictionary *pD ); | 58 | void prependDict( Gats::Dictionary *pD ); |
52 | Gats::List *prependList(); | 59 | Gats::List *prependList(); |
53 | Gats::Dictionary *prependDict(); | 60 | Gats::Dictionary *prependDict(); |
54 | }; | 61 | }; |
55 | }; | 62 | }; |
56 | 63 | ||
57 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ); | 64 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ); |
diff --git a/c++-qt/src/null.cpp b/c++-qt/src/null.cpp index f259887..8d46250 100644 --- a/c++-qt/src/null.cpp +++ b/c++-qt/src/null.cpp | |||
@@ -1,3 +1,10 @@ | |||
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-qt/null.h" | 8 | #include "gats-qt/null.h" |
2 | 9 | ||
3 | #include <QIODevice> | 10 | #include <QIODevice> |
@@ -12,12 +19,12 @@ Gats::Null::~Null() | |||
12 | 19 | ||
13 | Gats::Object *Gats::Null::clone() const | 20 | Gats::Object *Gats::Null::clone() const |
14 | { | 21 | { |
15 | return new Gats::Null(); | 22 | return new Gats::Null(); |
16 | } | 23 | } |
17 | 24 | ||
18 | void Gats::Null::write( QIODevice &rOut ) const | 25 | void Gats::Null::write( QIODevice &rOut ) const |
19 | { | 26 | { |
20 | rOut.write("n", 1 ); | 27 | rOut.write("n", 1 ); |
21 | } | 28 | } |
22 | 29 | ||
23 | void Gats::Null::read( QIODevice &rIn, char cType ) | 30 | void Gats::Null::read( QIODevice &rIn, char cType ) |
@@ -26,6 +33,6 @@ void Gats::Null::read( QIODevice &rIn, char cType ) | |||
26 | /* | 33 | /* |
27 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ) | 34 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ) |
28 | { | 35 | { |
29 | return f << "(bool) " << b.getValue(); | 36 | return f << "(bool) " << b.getValue(); |
30 | } | 37 | } |
31 | */ | 38 | */ |
diff --git a/c++-qt/src/null.h b/c++-qt/src/null.h index 354de12..f3ec45b 100644 --- a/c++-qt/src/null.h +++ b/c++-qt/src/null.h | |||
@@ -1,3 +1,10 @@ | |||
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 | ||
@@ -7,20 +14,20 @@ class QIODevice; | |||
7 | 14 | ||
8 | namespace Gats | 15 | namespace Gats |
9 | { | 16 | { |
10 | class Null : public Gats::Object | 17 | class Null : public Gats::Object |
11 | { | 18 | { |
12 | Q_OBJECT; | 19 | Q_OBJECT; |
13 | public: | 20 | public: |
14 | Null(); | 21 | Null(); |
15 | virtual ~Null(); | 22 | virtual ~Null(); |
16 | 23 | ||
17 | virtual Object *clone() const; | 24 | virtual Object *clone() const; |
18 | 25 | ||
19 | virtual Type getType() const { return typeNull; } | 26 | virtual Type getType() const { return typeNull; } |
20 | 27 | ||
21 | virtual void write( QIODevice &rOut ) const; | 28 | virtual void write( QIODevice &rOut ) const; |
22 | virtual void read( QIODevice &rIn, char cType ); | 29 | virtual void read( QIODevice &rIn, char cType ); |
23 | }; | 30 | }; |
24 | }; | 31 | }; |
25 | 32 | ||
26 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ); | 33 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ); |
diff --git a/c++-qt/src/object.cpp b/c++-qt/src/object.cpp index 4290e17..7c05228 100644 --- a/c++-qt/src/object.cpp +++ b/c++-qt/src/object.cpp | |||
@@ -1,3 +1,10 @@ | |||
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-qt/object.h" | 8 | #include "gats-qt/object.h" |
2 | 9 | ||
3 | #include "gats-qt/integer.h" | 10 | #include "gats-qt/integer.h" |
@@ -22,126 +29,126 @@ Gats::Object::~Object() | |||
22 | 29 | ||
23 | Gats::Object *Gats::Object::read( QIODevice &rIn ) | 30 | Gats::Object *Gats::Object::read( QIODevice &rIn ) |
24 | { | 31 | { |
25 | char buf; | 32 | char buf; |
26 | rIn.read( &buf, 1 ); | 33 | rIn.read( &buf, 1 ); |
27 | Object *pObj = NULL; | 34 | Object *pObj = NULL; |
28 | switch( buf ) | 35 | switch( buf ) |
29 | { | 36 | { |
30 | case 'i': | 37 | case 'i': |
31 | pObj = new Gats::Integer(); | 38 | pObj = new Gats::Integer(); |
32 | break; | 39 | break; |
33 | 40 | ||
34 | case 's': | 41 | case 's': |
35 | pObj = new Gats::String(); | 42 | pObj = new Gats::String(); |
36 | break; | 43 | break; |
37 | 44 | ||
38 | case '0': | 45 | case '0': |
39 | case '1': | 46 | case '1': |
40 | pObj = new Gats::Boolean(); | 47 | pObj = new Gats::Boolean(); |
41 | break; | 48 | break; |
42 | 49 | ||
43 | case 'l': | 50 | case 'l': |
44 | pObj = new Gats::List(); | 51 | pObj = new Gats::List(); |
45 | break; | 52 | break; |
46 | 53 | ||
47 | case 'd': | 54 | case 'd': |
48 | pObj = new Gats::Dictionary(); | 55 | pObj = new Gats::Dictionary(); |
49 | break; | 56 | break; |
50 | 57 | ||
51 | case 'f': // Normal floats | 58 | case 'f': // Normal floats |
52 | case 'F': // Special float values | 59 | case 'F': // Special float values |
53 | pObj = new Gats::Float(); | 60 | pObj = new Gats::Float(); |
54 | break; | 61 | break; |
55 | 62 | ||
56 | case 'n': | 63 | case 'n': |
57 | pObj = new Gats::Null(); | 64 | pObj = new Gats::Null(); |
58 | break; | 65 | break; |
59 | 66 | ||
60 | case 'e': | 67 | case 'e': |
61 | return NULL; | 68 | return NULL; |
62 | 69 | ||
63 | default: | 70 | default: |
64 | throw "Invalid Gats type discovered: "; | 71 | throw "Invalid Gats type discovered: "; |
65 | } | 72 | } |
66 | 73 | ||
67 | pObj->read( rIn, buf ); | 74 | pObj->read( rIn, buf ); |
68 | 75 | ||
69 | return pObj; | 76 | return pObj; |
70 | } | 77 | } |
71 | /* | 78 | /* |
72 | void Gats::Object::skipWs( QByteArray::const_iterator &i ) | 79 | void Gats::Object::skipWs( QByteArray::const_iterator &i ) |
73 | { | 80 | { |
74 | for(; *i == ' ' || *i == '\t' || *i == '\r' || *i == '\n'; i++ ) { } | 81 | for(; *i == ' ' || *i == '\t' || *i == '\r' || *i == '\n'; i++ ) { } |
75 | } | 82 | } |
76 | 83 | ||
77 | QByteArray Gats::Object::token( QByteArray::const_iterator &i ) | 84 | QByteArray Gats::Object::token( QByteArray::const_iterator &i ) |
78 | { | 85 | { |
79 | QByteArray sRet; | 86 | QByteArray sRet; |
80 | if( *i == '\"' ) | 87 | if( *i == '\"' ) |
81 | { | 88 | { |
82 | for( i++; i && *i != '\"' ; i++ ) | 89 | for( i++; i && *i != '\"' ; i++ ) |
83 | { | 90 | { |
84 | if( *i == '\\' ) | 91 | if( *i == '\\' ) |
85 | i++; | 92 | i++; |
86 | sRet += i; | 93 | sRet += i; |
87 | } | 94 | } |
88 | i++; | 95 | i++; |
89 | } | 96 | } |
90 | else | 97 | else |
91 | { | 98 | { |
92 | for(; i && *i != ' ' && *i != '\t' && *i != '\r' && *i != '\n' && | 99 | for(; i && *i != ' ' && *i != '\t' && *i != '\r' && *i != '\n' && |
93 | *i != ',' && *i != ']' && *i != '}' && *i != '[' && | 100 | *i != ',' && *i != ']' && *i != '}' && *i != '[' && |
94 | *i != '{'; i++ ) | 101 | *i != '{'; i++ ) |
95 | { | 102 | { |
96 | sRet += i; | 103 | sRet += i; |
97 | } | 104 | } |
98 | } | 105 | } |
99 | 106 | ||
100 | return sRet; | 107 | return sRet; |
101 | } | 108 | } |
102 | 109 | ||
103 | Gats::Object *Gats::Object::strToGats( QByteArray::const_iterator &i ) | 110 | Gats::Object *Gats::Object::strToGats( QByteArray::const_iterator &i ) |
104 | { | 111 | { |
105 | skipWs( i ); | 112 | skipWs( i ); |
106 | 113 | ||
107 | switch( *i ) | 114 | switch( *i ) |
108 | { | 115 | { |
109 | case '[': | 116 | case '[': |
110 | { | 117 | { |
111 | Gats::List *pLst = new Gats::List(); | 118 | Gats::List *pLst = new Gats::List(); |
112 | i++; | 119 | i++; |
113 | for(;;) | 120 | for(;;) |
114 | { | 121 | { |
115 | Gats::Object *pObj = strToGats( i ); | 122 | Gats::Object *pObj = strToGats( i ); |
116 | if( !pObj ) | 123 | if( !pObj ) |
117 | break; | 124 | break; |
118 | pLst->append( pObj ); | 125 | pLst->append( pObj ); |
119 | skipWs( i ); | 126 | skipWs( i ); |
120 | switch( *i ) | 127 | switch( *i ) |
121 | { | 128 | { |
122 | case ',': | 129 | case ',': |
123 | i++; | 130 | i++; |
124 | break; | 131 | break; |
125 | 132 | ||
126 | case ']': | 133 | case ']': |
127 | i++; | 134 | i++; |
128 | return pLst; | 135 | return pLst; |
129 | 136 | ||
130 | default: | 137 | default: |
131 | throw "PUT GOOD EXCEPTION HERE"; | 138 | throw "PUT GOOD EXCEPTION HERE"; |
132 | } | 139 | } |
133 | } | 140 | } |
134 | } | 141 | } |
135 | break; | 142 | break; |
136 | 143 | ||
137 | case '{': | 144 | case '{': |
138 | { | 145 | { |
139 | Gats::Dictionary *pDict = new Gats::Dictionary(); | 146 | Gats::Dictionary *pDict = new Gats::Dictionary(); |
140 | i++; | 147 | i++; |
141 | for(;;) | 148 | for(;;) |
142 | { | 149 | { |
143 | skipWs( i ); | 150 | skipWs( i ); |
144 | if( *i != '\"' ) | 151 | if( *i != '\"' ) |
145 | throw "PUT GOOD EXCEPTION HERE"; | 152 | throw "PUT GOOD EXCEPTION HERE"; |
146 | QByteArray sKey = token( i ); | 153 | QByteArray sKey = token( i ); |
147 | skipWs( i ); | 154 | skipWs( i ); |
@@ -172,144 +179,144 @@ Gats::Object *Gats::Object::strToGats( QByteArray::const_iterator &i ) | |||
172 | break; | 179 | break; |
173 | 180 | ||
174 | case '\"': | 181 | case '\"': |
175 | return new Gats::String( token( i ) ); | 182 | return new Gats::String( token( i ) ); |
176 | break; | 183 | break; |
177 | 184 | ||
178 | case '0': | 185 | case '0': |
179 | case '1': | 186 | case '1': |
180 | case '2': | 187 | case '2': |
181 | case '3': | 188 | case '3': |
182 | case '4': | 189 | case '4': |
183 | case '5': | 190 | case '5': |
184 | case '6': | 191 | case '6': |
185 | case '7': | 192 | case '7': |
186 | case '8': | 193 | case '8': |
187 | case '9': | 194 | case '9': |
188 | case '.': | 195 | case '.': |
189 | case '+': | 196 | case '+': |
190 | case '-': | 197 | case '-': |
191 | { | 198 | { |
192 | QByteArray s = token( i ); | 199 | QByteArray s = token( i ); |
193 | int iSize = s.getSize(); | 200 | int iSize = s.getSize(); |
194 | if( s[iSize-1] == 'i' ) | 201 | if( s[iSize-1] == 'i' ) |
195 | { | 202 | { |
196 | return new Gats::Integer( | 203 | return new Gats::Integer( |
197 | strtoll( s.getStr(), NULL, 10 ) | 204 | strtoll( s.getStr(), NULL, 10 ) |
198 | ); | 205 | ); |
199 | } | 206 | } |
200 | else if( s[iSize-1] == 'f' ) | 207 | else if( s[iSize-1] == 'f' ) |
201 | { | 208 | { |
202 | return new Gats::Float( | 209 | return new Gats::Float( |
203 | strtod( s.getStr(), NULL ) | 210 | strtod( s.getStr(), NULL ) |
204 | ); | 211 | ); |
205 | } | 212 | } |
206 | else | 213 | else |
207 | { | 214 | { |
208 | for( QByteArray::iterator i = s.begin(); i; i++ ) | 215 | for( QByteArray::iterator i = s.begin(); i; i++ ) |
209 | { | 216 | { |
210 | if( *i == '.' ) | 217 | if( *i == '.' ) |
211 | return new Gats::Float( | 218 | return new Gats::Float( |
212 | strtod( s.getStr(), NULL ) | 219 | strtod( s.getStr(), NULL ) |
213 | ); | 220 | ); |
214 | } | 221 | } |
215 | return new Gats::Integer( | 222 | return new Gats::Integer( |
216 | strtoll( s.getStr(), NULL, 10 ) | 223 | strtoll( s.getStr(), NULL, 10 ) |
217 | ); | 224 | ); |
218 | } | 225 | } |
219 | } | 226 | } |
220 | break; | 227 | break; |
221 | 228 | ||
222 | default: | 229 | default: |
223 | { | 230 | { |
224 | QByteArray s = token( i ); | 231 | QByteArray s = token( i ); |
225 | int iSize = s.getSize(); | 232 | int iSize = s.getSize(); |
226 | // Test for explicit types first | 233 | // Test for explicit types first |
227 | if( iSize > 2 ) | 234 | if( iSize > 2 ) |
228 | { | 235 | { |
229 | if( (s[0] >= '0' && s[0] <= '9') || s[0] == '+' || s[0] == '-' ) | 236 | if( (s[0] >= '0' && s[0] <= '9') || s[0] == '+' || s[0] == '-' ) |
230 | { | 237 | { |
231 | } | 238 | } |
232 | else | 239 | else |
233 | { | 240 | { |
234 | QByteArray st = s.toLower(); | 241 | QByteArray st = s.toLower(); |
235 | if( st == "true" ) | 242 | if( st == "true" ) |
236 | { | 243 | { |
237 | return new Gats::Boolean( true ); | 244 | return new Gats::Boolean( true ); |
238 | } | 245 | } |
239 | else if( st == "false" ) | 246 | else if( st == "false" ) |
240 | { | 247 | { |
241 | return new Gats::Boolean( false ); | 248 | return new Gats::Boolean( false ); |
242 | } | 249 | } |
243 | } | 250 | } |
244 | } | 251 | } |
245 | } | 252 | } |
246 | break; | 253 | break; |
247 | } | 254 | } |
248 | 255 | ||
249 | return NULL; | 256 | return NULL; |
250 | } | 257 | } |
251 | 258 | ||
252 | Gats::Object *Gats::Object::strToGats( const QByteArray &sStr ) | 259 | Gats::Object *Gats::Object::strToGats( const QByteArray &sStr ) |
253 | { | 260 | { |
254 | QByteArray::const_iterator i = sStr.begin(); | 261 | QByteArray::const_iterator i = sStr.begin(); |
255 | 262 | ||
256 | return strToGats( i ); | 263 | return strToGats( i ); |
257 | } | 264 | } |
258 | 265 | ||
259 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ) | 266 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ) |
260 | { | 267 | { |
261 | switch( obj.getType() ) | 268 | switch( obj.getType() ) |
262 | { | 269 | { |
263 | case Gats::typeDictionary: | 270 | case Gats::typeDictionary: |
264 | return f << dynamic_cast<const Gats::Dictionary &>(obj); | 271 | return f << dynamic_cast<const Gats::Dictionary &>(obj); |
265 | 272 | ||
266 | case Gats::typeList: | 273 | case Gats::typeList: |
267 | return f << dynamic_cast<const Gats::List &>(obj); | 274 | return f << dynamic_cast<const Gats::List &>(obj); |
268 | 275 | ||
269 | case Gats::typeString: | 276 | case Gats::typeString: |
270 | return f << dynamic_cast<const Gats::String &>(obj); | 277 | return f << dynamic_cast<const Gats::String &>(obj); |
271 | 278 | ||
272 | case Gats::typeInteger: | 279 | case Gats::typeInteger: |
273 | return f << dynamic_cast<const Gats::Integer &>(obj); | 280 | return f << dynamic_cast<const Gats::Integer &>(obj); |
274 | 281 | ||
275 | case Gats::typeFloat: | 282 | case Gats::typeFloat: |
276 | return f << dynamic_cast<const Gats::Float &>(obj); | 283 | return f << dynamic_cast<const Gats::Float &>(obj); |
277 | 284 | ||
278 | case Gats::typeBoolean: | 285 | case Gats::typeBoolean: |
279 | return f << dynamic_cast<const Gats::Boolean &>(obj); | 286 | return f << dynamic_cast<const Gats::Boolean &>(obj); |
280 | 287 | ||
281 | default: | 288 | default: |
282 | return f << "***ERROR: Bad Gats type***"; | 289 | return f << "***ERROR: Bad Gats type***"; |
283 | } | 290 | } |
284 | } | 291 | } |
285 | 292 | ||
286 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ) | 293 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Type &t ) |
287 | { | 294 | { |
288 | switch( t ) | 295 | switch( t ) |
289 | { | 296 | { |
290 | case Gats::typeDictionary: return f << "dictionary"; | 297 | case Gats::typeDictionary: return f << "dictionary"; |
291 | case Gats::typeList: return f << "list"; | 298 | case Gats::typeList: return f << "list"; |
292 | case Gats::typeString: return f << "string"; | 299 | case Gats::typeString: return f << "string"; |
293 | case Gats::typeInteger: return f << "integer"; | 300 | case Gats::typeInteger: return f << "integer"; |
294 | case Gats::typeFloat: return f << "float"; | 301 | case Gats::typeFloat: return f << "float"; |
295 | case Gats::typeBoolean: return f << "boolean"; | 302 | case Gats::typeBoolean: return f << "boolean"; |
296 | } | 303 | } |
297 | 304 | ||
298 | return f << "***unknown***"; | 305 | return f << "***unknown***"; |
299 | } | 306 | } |
300 | */ | 307 | */ |
301 | const char *Gats::typeToStr( Gats::Type t ) | 308 | const char *Gats::typeToStr( Gats::Type t ) |
302 | { | 309 | { |
303 | switch( t ) | 310 | switch( t ) |
304 | { | 311 | { |
305 | case Gats::typeDictionary: return "dictionary"; | 312 | case Gats::typeDictionary: return "dictionary"; |
306 | case Gats::typeList: return "list"; | 313 | case Gats::typeList: return "list"; |
307 | case Gats::typeString: return "string"; | 314 | case Gats::typeString: return "string"; |
308 | case Gats::typeInteger: return "integer"; | 315 | case Gats::typeInteger: return "integer"; |
309 | case Gats::typeFloat: return "float"; | 316 | case Gats::typeFloat: return "float"; |
310 | case Gats::typeBoolean: return "boolean"; | 317 | case Gats::typeBoolean: return "boolean"; |
311 | } | 318 | } |
312 | 319 | ||
313 | return "***unknown***"; | 320 | return "***unknown***"; |
314 | } | 321 | } |
315 | 322 | ||
diff --git a/c++-qt/src/object.h b/c++-qt/src/object.h index 008ebef..7e12b87 100644 --- a/c++-qt/src/object.h +++ b/c++-qt/src/object.h | |||
@@ -1,3 +1,10 @@ | |||
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 | ||
@@ -8,44 +15,44 @@ class QIODevice; | |||
8 | 15 | ||
9 | namespace Gats | 16 | namespace Gats |
10 | { | 17 | { |
11 | enum Type | 18 | enum Type |
12 | { | 19 | { |
13 | typeDictionary, | 20 | typeDictionary, |
14 | typeList, | 21 | typeList, |
15 | typeString, | 22 | typeString, |
16 | typeInteger, | 23 | typeInteger, |
17 | typeFloat, | 24 | typeFloat, |
18 | typeBoolean, | 25 | typeBoolean, |
19 | typeNull | 26 | typeNull |
20 | }; | 27 | }; |
21 | 28 | ||
22 | /** | 29 | /** |
23 | * The baseclass for every type that can be stored in a packet. | 30 | * The baseclass for every type that can be stored in a packet. |
24 | */ | 31 | */ |
25 | class Object : public QObject | 32 | class Object : public QObject |
26 | { | 33 | { |
27 | Q_OBJECT; | 34 | Q_OBJECT; |
28 | public: | 35 | public: |
29 | Object(); | 36 | Object(); |
30 | virtual ~Object(); | 37 | virtual ~Object(); |
31 | 38 | ||
32 | virtual Object *clone() const=0; | 39 | virtual Object *clone() const=0; |
33 | 40 | ||
34 | virtual Type getType() const =0; | 41 | virtual Type getType() const =0; |
35 | 42 | ||
36 | virtual void write( QIODevice &rOut ) const=0; | 43 | virtual void write( QIODevice &rOut ) const=0; |
37 | virtual void read( QIODevice &rIn, char cType )=0; | 44 | virtual void read( QIODevice &rIn, char cType )=0; |
38 | 45 | ||
39 | static Object *read( QIODevice &rIn ); | 46 | static Object *read( QIODevice &rIn ); |
40 | // static Object *strToGats( const &sStr ); | 47 | // static Object *strToGats( const &sStr ); |
41 | 48 | ||
42 | private: | 49 | private: |
43 | // static Object *strToGats( QByteArray::const_iterator &i ); | 50 | // static Object *strToGats( QByteArray::const_iterator &i ); |
44 | // static QByteArray token( QByteArray::const_iterator &i ); | 51 | // static QByteArray token( QByteArray::const_iterator &i ); |
45 | // static void skipWs( QByteArray::const_iterator &i ); | 52 | // static void skipWs( QByteArray::const_iterator &i ); |
46 | }; | 53 | }; |
47 | 54 | ||
48 | const char *typeToStr( Type t ); | 55 | const char *typeToStr( Type t ); |
49 | }; | 56 | }; |
50 | 57 | ||
51 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ); | 58 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ); |
diff --git a/c++-qt/src/string.cpp b/c++-qt/src/string.cpp index ef23829..7d2d20f 100644 --- a/c++-qt/src/string.cpp +++ b/c++-qt/src/string.cpp | |||
@@ -1,3 +1,10 @@ | |||
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-qt/string.h" | 8 | #include "gats-qt/string.h" |
2 | 9 | ||
3 | #include "gats-qt/integer.h" | 10 | #include "gats-qt/integer.h" |
@@ -7,27 +14,27 @@ Gats::String::String() | |||
7 | } | 14 | } |
8 | 15 | ||
9 | Gats::String::String( const char *s ) : | 16 | Gats::String::String( const char *s ) : |
10 | QByteArray( s ) | 17 | QByteArray( s ) |
11 | { | 18 | { |
12 | } | 19 | } |
13 | 20 | ||
14 | Gats::String::String( const char *s, long iLength ) : | 21 | Gats::String::String( const char *s, long iLength ) : |
15 | QByteArray( s, iLength ) | 22 | QByteArray( s, iLength ) |
16 | { | 23 | { |
17 | } | 24 | } |
18 | 25 | ||
19 | Gats::String::String( long iLength ) : | 26 | Gats::String::String( long iLength ) : |
20 | QByteArray( iLength, '\0' ) | 27 | QByteArray( iLength, '\0' ) |
21 | { | 28 | { |
22 | } | 29 | } |
23 | 30 | ||
24 | Gats::String::String( const String &s ) : | 31 | Gats::String::String( const String &s ) : |
25 | QByteArray( s ) | 32 | QByteArray( s ) |
26 | { | 33 | { |
27 | } | 34 | } |
28 | 35 | ||
29 | Gats::String::String( const QByteArray &s ) : | 36 | Gats::String::String( const QByteArray &s ) : |
30 | QByteArray( s ) | 37 | QByteArray( s ) |
31 | { | 38 | { |
32 | } | 39 | } |
33 | 40 | ||
@@ -37,29 +44,29 @@ Gats::String::~String() | |||
37 | 44 | ||
38 | Gats::Object *Gats::String::clone() const | 45 | Gats::Object *Gats::String::clone() const |
39 | { | 46 | { |
40 | QByteArray baClone = *this; | 47 | QByteArray baClone = *this; |
41 | baClone.detach(); | 48 | baClone.detach(); |
42 | return new Gats::String( baClone ); | 49 | return new Gats::String( baClone ); |
43 | } | 50 | } |
44 | 51 | ||
45 | void Gats::String::write( QIODevice &rOut ) const | 52 | void Gats::String::write( QIODevice &rOut ) const |
46 | { | 53 | { |
47 | rOut.write("s", 1 ); | 54 | rOut.write("s", 1 ); |
48 | uint32_t iSize = size(); | 55 | uint32_t iSize = size(); |
49 | Gats::Integer::writePackedInt( rOut, iSize ); | 56 | Gats::Integer::writePackedInt( rOut, iSize ); |
50 | rOut.write( constData(), iSize ); | 57 | rOut.write( constData(), iSize ); |
51 | } | 58 | } |
52 | 59 | ||
53 | void Gats::String::read( QIODevice &rIn, char cType ) | 60 | void Gats::String::read( QIODevice &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 | fill( '\0', iSize ); | 64 | fill( '\0', iSize ); |
58 | rIn.read( data(), iSize ); | 65 | rIn.read( data(), 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 | return f << "(str) \"" << dynamic_cast<const QByteArray &>(s) << "\""; | 70 | return f << "(str) \"" << dynamic_cast<const QByteArray &>(s) << "\""; |
64 | } | 71 | } |
65 | */ | 72 | */ |
diff --git a/c++-qt/src/string.h b/c++-qt/src/string.h index 9bf6ce3..a679fc0 100644 --- a/c++-qt/src/string.h +++ b/c++-qt/src/string.h | |||
@@ -1,3 +1,10 @@ | |||
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,27 +13,27 @@ | |||
6 | 13 | ||
7 | namespace Gats | 14 | namespace Gats |
8 | { | 15 | { |
9 | class String : public Gats::Object, public QByteArray | 16 | class String : public Gats::Object, public QByteArray |
10 | { | 17 | { |
11 | Q_OBJECT; | 18 | Q_OBJECT; |
12 | public: | 19 | public: |
13 | String(); | 20 | String(); |
14 | String( const char *s ); | 21 | String( const char *s ); |
15 | String( const char *s, long iLength ); | 22 | String( const char *s, long iLength ); |
16 | String( long iLength ); | 23 | String( long iLength ); |
17 | String( const String &s ); | 24 | String( const String &s ); |
18 | String( const QByteArray &s ); | 25 | String( const QByteArray &s ); |
19 | virtual ~String(); | 26 | virtual ~String(); |
20 | 27 | ||
21 | virtual Object *clone() const; | 28 | virtual Object *clone() const; |
22 | 29 | ||
23 | virtual Type getType() const { return typeString; } | 30 | virtual Type getType() const { return typeString; } |
24 | 31 | ||
25 | virtual void write( QIODevice &rOut ) const; | 32 | virtual void write( QIODevice &rOut ) const; |
26 | virtual void read( QIODevice &rIn, char cType ); | 33 | virtual void read( QIODevice &rIn, char cType ); |
27 | 34 | ||
28 | private: | 35 | private: |
29 | }; | 36 | }; |
30 | }; | 37 | }; |
31 | 38 | ||
32 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ); | 39 | //Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ); |
diff --git a/c++-qt/src/types.h b/c++-qt/src/types.h index bd1c8ae..1efdf26 100644 --- a/c++-qt/src/types.h +++ b/c++-qt/src/types.h | |||
@@ -1,3 +1,10 @@ | |||
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-qt/object.h" | 8 | #include "gats-qt/object.h" |
2 | #include "gats-qt/boolean.h" | 9 | #include "gats-qt/boolean.h" |
3 | #include "gats-qt/dictionary.h" | 10 | #include "gats-qt/dictionary.h" |
diff --git a/c++-qt/tests/echo/main.cpp b/c++-qt/tests/echo/main.cpp index 43ceae4..4925fc6 100644 --- a/c++-qt/tests/echo/main.cpp +++ b/c++-qt/tests/echo/main.cpp | |||
@@ -1,14 +1,21 @@ | |||
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 <QApplication> | 8 | #include <QApplication> |
2 | 9 | ||
3 | #include "mainwnd.h" | 10 | #include "mainwnd.h" |
4 | 11 | ||
5 | int main( int argc, char *argv[] ) | 12 | int main( int argc, char *argv[] ) |
6 | { | 13 | { |
7 | QApplication app( argc, argv ); | 14 | QApplication app( argc, argv ); |
8 | 15 | ||
9 | MainWnd wnd; | 16 | MainWnd wnd; |
10 | wnd.show(); | 17 | wnd.show(); |
11 | 18 | ||
12 | return app.exec(); | 19 | return app.exec(); |
13 | } | 20 | } |
14 | 21 | ||
diff --git a/c++-qt/tests/echo/mainwnd.cpp b/c++-qt/tests/echo/mainwnd.cpp index 13c93a1..3995720 100644 --- a/c++-qt/tests/echo/mainwnd.cpp +++ b/c++-qt/tests/echo/mainwnd.cpp | |||
@@ -1,10 +1,17 @@ | |||
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 | MainWnd::MainWnd() | 10 | MainWnd::MainWnd() |
4 | { | 11 | { |
5 | pSrv = new QTcpServer( this ); | 12 | pSrv = new QTcpServer( this ); |
6 | connect( pSrv, SIGNAL(newConnection()), this, SLOT(newConnection())); | 13 | connect( pSrv, SIGNAL(newConnection()), this, SLOT(newConnection())); |
7 | pSrv->listen( QHostAddress::Any, 7317 ); | 14 | pSrv->listen( QHostAddress::Any, 7317 ); |
8 | } | 15 | } |
9 | 16 | ||
10 | MainWnd::~MainWnd() | 17 | MainWnd::~MainWnd() |
@@ -13,24 +20,24 @@ MainWnd::~MainWnd() | |||
13 | 20 | ||
14 | void MainWnd::newConnection() | 21 | void MainWnd::newConnection() |
15 | { | 22 | { |
16 | while( pSrv->hasPendingConnections() ) | 23 | while( pSrv->hasPendingConnections() ) |
17 | { | 24 | { |
18 | QTcpSocket *pSock = pSrv->nextPendingConnection(); | 25 | QTcpSocket *pSock = pSrv->nextPendingConnection(); |
19 | Gats::GatsStream *pGats = new Gats::GatsStream( *pSock ); | 26 | Gats::GatsStream *pGats = new Gats::GatsStream( *pSock ); |
20 | connect( pSock, SIGNAL(readyRead()), pGats, SLOT(readObject()) ); | 27 | connect( pSock, SIGNAL(readyRead()), pGats, SLOT(readObject()) ); |
21 | connect( pGats, SIGNAL(objectRead( Gats::Object * )), | 28 | connect( pGats, SIGNAL(objectRead( Gats::Object * )), |
22 | this, SLOT(objectRead( Gats::Object * ))); | 29 | this, SLOT(objectRead( Gats::Object * ))); |
23 | } | 30 | } |
24 | } | 31 | } |
25 | 32 | ||
26 | void MainWnd::objectRead( Gats::Object *pObj ) | 33 | void MainWnd::objectRead( Gats::Object *pObj ) |
27 | { | 34 | { |
28 | ((Gats::GatsStream *)sender())->writeObject( pObj ); | 35 | ((Gats::GatsStream *)sender())->writeObject( pObj ); |
29 | 36 | ||
30 | Gats::Object *pCopy = pObj->clone(); | 37 | Gats::Object *pCopy = pObj->clone(); |
31 | delete pObj; | 38 | delete pObj; |
32 | 39 | ||
33 | ((Gats::GatsStream *)sender())->writeObject( pCopy ); | 40 | ((Gats::GatsStream *)sender())->writeObject( pCopy ); |
34 | 41 | ||
35 | delete pCopy; | 42 | delete pCopy; |
36 | } | 43 | } |
diff --git a/c++-qt/tests/echo/mainwnd.h b/c++-qt/tests/echo/mainwnd.h index 0afbd6a..71c5c8e 100644 --- a/c++-qt/tests/echo/mainwnd.h +++ b/c++-qt/tests/echo/mainwnd.h | |||
@@ -1,3 +1,10 @@ | |||
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 | 8 | ||
2 | #include <QTcpServer> | 9 | #include <QTcpServer> |
3 | #include <QTcpSocket> | 10 | #include <QTcpSocket> |
@@ -8,16 +15,16 @@ | |||
8 | 15 | ||
9 | class MainWnd : public QMainWindow | 16 | class MainWnd : public QMainWindow |
10 | { | 17 | { |
11 | Q_OBJECT; | 18 | Q_OBJECT; |
12 | public: | 19 | public: |
13 | QTcpServer *pSrv; | 20 | QTcpServer *pSrv; |
14 | 21 | ||
15 | MainWnd(); | 22 | MainWnd(); |
16 | virtual ~MainWnd(); | 23 | virtual ~MainWnd(); |
17 | 24 | ||
18 | public slots: | 25 | public slots: |
19 | void newConnection(); | 26 | void newConnection(); |
20 | void objectRead( Gats::Object *pObj ); | 27 | void objectRead( Gats::Object *pObj ); |
21 | 28 | ||
22 | signals: | 29 | signals: |
23 | }; | 30 | }; |
diff --git a/java/FileExample.java b/java/FileExample.java index e0db728..1bfa710 100644 --- a/java/FileExample.java +++ b/java/FileExample.java | |||
@@ -1,3 +1,10 @@ | |||
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 | import com.xagasoft.gats.*; | 8 | import com.xagasoft.gats.*; |
2 | 9 | ||
3 | import java.io.FileInputStream; | 10 | import java.io.FileInputStream; |
diff --git a/java/com/xagasoft/gats/GatsBoolean.java b/java/com/xagasoft/gats/GatsBoolean.java index 7e5d217..d54e8de 100644 --- a/java/com/xagasoft/gats/GatsBoolean.java +++ b/java/com/xagasoft/gats/GatsBoolean.java | |||
@@ -1,3 +1,10 @@ | |||
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 | package com.xagasoft.gats; | 8 | package com.xagasoft.gats; |
2 | 9 | ||
3 | import java.io.InputStream; | 10 | import java.io.InputStream; |
diff --git a/java/com/xagasoft/gats/GatsDictionary.java b/java/com/xagasoft/gats/GatsDictionary.java index e359dfa..7909c68 100644 --- a/java/com/xagasoft/gats/GatsDictionary.java +++ b/java/com/xagasoft/gats/GatsDictionary.java | |||
@@ -1,3 +1,10 @@ | |||
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 | package com.xagasoft.gats; | 8 | package com.xagasoft.gats; |
2 | 9 | ||
3 | import java.io.InputStream; | 10 | import java.io.InputStream; |
diff --git a/java/com/xagasoft/gats/GatsFloat.java b/java/com/xagasoft/gats/GatsFloat.java index 3d7583e..4440ea5 100644 --- a/java/com/xagasoft/gats/GatsFloat.java +++ b/java/com/xagasoft/gats/GatsFloat.java | |||
@@ -1,3 +1,10 @@ | |||
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 | package com.xagasoft.gats; | 8 | package com.xagasoft.gats; |
2 | 9 | ||
3 | import java.io.InputStream; | 10 | import java.io.InputStream; |
diff --git a/java/com/xagasoft/gats/GatsInputStream.java b/java/com/xagasoft/gats/GatsInputStream.java index 7d598b4..6502258 100644 --- a/java/com/xagasoft/gats/GatsInputStream.java +++ b/java/com/xagasoft/gats/GatsInputStream.java | |||
@@ -1,3 +1,10 @@ | |||
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 | package com.xagasoft.gats; | 8 | package com.xagasoft.gats; |
2 | 9 | ||
3 | import java.io.InputStream; | 10 | import java.io.InputStream; |
diff --git a/java/com/xagasoft/gats/GatsInteger.java b/java/com/xagasoft/gats/GatsInteger.java index 0ea5122..de8e343 100644 --- a/java/com/xagasoft/gats/GatsInteger.java +++ b/java/com/xagasoft/gats/GatsInteger.java | |||
@@ -1,3 +1,10 @@ | |||
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 | package com.xagasoft.gats; | 8 | package com.xagasoft.gats; |
2 | 9 | ||
3 | import java.io.OutputStream; | 10 | import java.io.OutputStream; |
diff --git a/java/com/xagasoft/gats/GatsList.java b/java/com/xagasoft/gats/GatsList.java index 84a9b31..1c3bba8 100644 --- a/java/com/xagasoft/gats/GatsList.java +++ b/java/com/xagasoft/gats/GatsList.java | |||
@@ -1,3 +1,10 @@ | |||
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 | package com.xagasoft.gats; | 8 | package com.xagasoft.gats; |
2 | 9 | ||
3 | import java.io.InputStream; | 10 | import java.io.InputStream; |
diff --git a/java/com/xagasoft/gats/GatsNull.java b/java/com/xagasoft/gats/GatsNull.java index 7919433..370028e 100644 --- a/java/com/xagasoft/gats/GatsNull.java +++ b/java/com/xagasoft/gats/GatsNull.java | |||
@@ -1,3 +1,10 @@ | |||
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 | package com.xagasoft.gats; | 8 | package com.xagasoft.gats; |
2 | 9 | ||
3 | import java.io.InputStream; | 10 | import java.io.InputStream; |
diff --git a/java/com/xagasoft/gats/GatsObject.java b/java/com/xagasoft/gats/GatsObject.java index e26ab7b..df489aa 100644 --- a/java/com/xagasoft/gats/GatsObject.java +++ b/java/com/xagasoft/gats/GatsObject.java | |||
@@ -1,3 +1,10 @@ | |||
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 | package com.xagasoft.gats; | 8 | package com.xagasoft.gats; |
2 | 9 | ||
3 | import java.io.InputStream; | 10 | import java.io.InputStream; |
diff --git a/java/com/xagasoft/gats/GatsOutputStream.java b/java/com/xagasoft/gats/GatsOutputStream.java index c71491b..2a20d99 100644 --- a/java/com/xagasoft/gats/GatsOutputStream.java +++ b/java/com/xagasoft/gats/GatsOutputStream.java | |||
@@ -1,3 +1,10 @@ | |||
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 | package com.xagasoft.gats; | 8 | package com.xagasoft.gats; |
2 | 9 | ||
3 | import java.io.OutputStream; | 10 | import java.io.OutputStream; |
diff --git a/java/com/xagasoft/gats/GatsString.java b/java/com/xagasoft/gats/GatsString.java index 8e5c5c0..442ef67 100644 --- a/java/com/xagasoft/gats/GatsString.java +++ b/java/com/xagasoft/gats/GatsString.java | |||
@@ -1,3 +1,10 @@ | |||
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 | package com.xagasoft.gats; | 8 | package com.xagasoft.gats; |
2 | 9 | ||
3 | import java.io.InputStream; | 10 | import java.io.InputStream; |
diff --git a/java/com/xagasoft/gats/KeyNotFoundException.java b/java/com/xagasoft/gats/KeyNotFoundException.java index 49d14e1..ddcde18 100644 --- a/java/com/xagasoft/gats/KeyNotFoundException.java +++ b/java/com/xagasoft/gats/KeyNotFoundException.java | |||
@@ -1,3 +1,10 @@ | |||
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 | package com.xagasoft.gats; | 8 | package com.xagasoft.gats; |
2 | 9 | ||
3 | /** | 10 | /** |
diff --git a/java/com/xagasoft/gats/package-info.java b/java/com/xagasoft/gats/package-info.java index 6feb5f1..1792bc5 100644 --- a/java/com/xagasoft/gats/package-info.java +++ b/java/com/xagasoft/gats/package-info.java | |||
@@ -1,3 +1,10 @@ | |||
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 | /** | 8 | /** |
2 | * The Generalized Agile Transport System. | 9 | * The Generalized Agile Transport System. |
3 | * | 10 | * |
diff --git a/php/phpgats.php b/php/phpgats.php index 8a16e09..df9b1ba 100644 --- a/php/phpgats.php +++ b/php/phpgats.php | |||
@@ -1,4 +1,11 @@ | |||
1 | <?php | 1 | <?php |
2 | /* | ||
3 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
4 | * | ||
5 | * This file is part of the libgats library and is released under the | ||
6 | * terms of the license contained in the file LICENSE. | ||
7 | */ | ||
8 | |||
2 | 9 | ||
3 | /** @cond */ | 10 | /** @cond */ |
4 | if( !defined("phpgats_defined") ) | 11 | if( !defined("phpgats_defined") ) |
diff --git a/php/phpgats2.php b/php/phpgats2.php index 1e713fc..11abebe 100644 --- a/php/phpgats2.php +++ b/php/phpgats2.php | |||
@@ -1,4 +1,11 @@ | |||
1 | <?php | 1 | <?php |
2 | /* | ||
3 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
4 | * | ||
5 | * This file is part of the libgats library and is released under the | ||
6 | * terms of the license contained in the file LICENSE. | ||
7 | */ | ||
8 | |||
2 | 9 | ||
3 | /** @cond */ | 10 | /** @cond */ |
4 | if( !defined("_phpgats2_defined") ) | 11 | if( !defined("_phpgats2_defined") ) |
diff --git a/python/client.py b/python/client.py index 53e38fd..6cc757a 100755 --- a/python/client.py +++ b/python/client.py | |||
@@ -1,4 +1,10 @@ | |||
1 | #!/usr/bin/python | 1 | #!/usr/bin/python |
2 | # | ||
3 | # Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
4 | # | ||
5 | # This file is part of the libgats library and is released under the | ||
6 | # terms of the license contained in the file LICENSE. | ||
7 | # | ||
2 | 8 | ||
3 | import gats | 9 | import gats |
4 | import socket | 10 | import socket |
diff --git a/python/gats.py b/python/gats.py index adf5122..d6704db 100644 --- a/python/gats.py +++ b/python/gats.py | |||
@@ -1,3 +1,9 @@ | |||
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 | # | ||
1 | 7 | ||
2 | """Provides pickle-compatible functions for working with Gats packets. | 8 | """Provides pickle-compatible functions for working with Gats packets. |
3 | Converts to and from normal python structures like dictionaries, lists, | 9 | Converts to and from normal python structures like dictionaries, lists, |
diff --git a/python/server.py b/python/server.py index c36f073..3dc60cb 100755 --- a/python/server.py +++ b/python/server.py | |||
@@ -1,4 +1,10 @@ | |||
1 | #!/usr/bin/python | 1 | #!/usr/bin/python |
2 | # | ||
3 | # Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
4 | # | ||
5 | # This file is part of the libgats library and is released under the | ||
6 | # terms of the license contained in the file LICENSE. | ||
7 | # | ||
2 | 8 | ||
3 | import gats | 9 | import gats |
4 | import socket | 10 | import socket |
diff --git a/python/test.py b/python/test.py index 0057fbf..be58519 100755 --- a/python/test.py +++ b/python/test.py | |||
@@ -1,4 +1,10 @@ | |||
1 | #!/usr/bin/python | 1 | #!/usr/bin/python |
2 | # | ||
3 | # Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
4 | # | ||
5 | # This file is part of the libgats library and is released under the | ||
6 | # terms of the license contained in the file LICENSE. | ||
7 | # | ||
2 | 8 | ||
3 | import gats | 9 | import gats |
4 | 10 | ||