diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-08-27 21:53:54 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-08-27 21:53:54 +0000 |
commit | c10c9ef627c7e79fde6170fe334238bbcb5d66e5 (patch) | |
tree | 4a0971d81e666e91866ddeaf9b58b952ce2fdd0a | |
parent | 2a72923397d866f33221b9d32a3f9653d1a960e7 (diff) | |
download | libgats-c10c9ef627c7e79fde6170fe334238bbcb5d66e5.tar.gz libgats-c10c9ef627c7e79fde6170fe334238bbcb5d66e5.tar.bz2 libgats-c10c9ef627c7e79fde6170fe334238bbcb5d66e5.tar.xz libgats-c10c9ef627c7e79fde6170fe334238bbcb5d66e5.zip |
Added formatter handlers for debugging, works really well. Also added a bunch
more helpers to make it as easy to use as possible.
-rw-r--r-- | src/boolean.cpp | 6 | ||||
-rw-r--r-- | src/boolean.h | 2 | ||||
-rw-r--r-- | src/dictionary.cpp | 23 | ||||
-rw-r--r-- | src/dictionary.h | 2 | ||||
-rw-r--r-- | src/float.cpp | 7 | ||||
-rw-r--r-- | src/float.h | 2 | ||||
-rw-r--r-- | src/integer.cpp | 7 | ||||
-rw-r--r-- | src/integer.h | 2 | ||||
-rw-r--r-- | src/list.cpp | 81 | ||||
-rw-r--r-- | src/list.h | 19 | ||||
-rw-r--r-- | src/object.cpp | 28 | ||||
-rw-r--r-- | src/object.h | 3 | ||||
-rw-r--r-- | src/string.cpp | 22 | ||||
-rw-r--r-- | src/string.h | 5 |
14 files changed, 209 insertions, 0 deletions
diff --git a/src/boolean.cpp b/src/boolean.cpp index 087845a..e0600f2 100644 --- a/src/boolean.cpp +++ b/src/boolean.cpp | |||
@@ -1,5 +1,6 @@ | |||
1 | #include "gats/boolean.h" | 1 | #include "gats/boolean.h" |
2 | 2 | ||
3 | #include <bu/formatter.h> | ||
3 | #include <bu/stream.h> | 4 | #include <bu/stream.h> |
4 | 5 | ||
5 | Gats::Boolean::Boolean() : | 6 | Gats::Boolean::Boolean() : |
@@ -40,3 +41,8 @@ void Gats::Boolean::read( Bu::Stream &rIn, char cType ) | |||
40 | } | 41 | } |
41 | } | 42 | } |
42 | 43 | ||
44 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ) | ||
45 | { | ||
46 | return f << "(bool) " << b.getValue(); | ||
47 | } | ||
48 | |||
diff --git a/src/boolean.h b/src/boolean.h index 3035b32..270e578 100644 --- a/src/boolean.h +++ b/src/boolean.h | |||
@@ -24,4 +24,6 @@ namespace Gats | |||
24 | }; | 24 | }; |
25 | }; | 25 | }; |
26 | 26 | ||
27 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ); | ||
28 | |||
27 | #endif | 29 | #endif |
diff --git a/src/dictionary.cpp b/src/dictionary.cpp index 1a9549f..b789bbf 100644 --- a/src/dictionary.cpp +++ b/src/dictionary.cpp | |||
@@ -6,6 +6,8 @@ | |||
6 | #include "gats/string.h" | 6 | #include "gats/string.h" |
7 | #include "gats/list.h" | 7 | #include "gats/list.h" |
8 | 8 | ||
9 | #include <bu/formatter.h> | ||
10 | |||
9 | template<> | 11 | template<> |
10 | uint32_t Bu::__calcHashCode<Gats::String>( const Gats::String &s ) | 12 | uint32_t Bu::__calcHashCode<Gats::String>( const Gats::String &s ) |
11 | { | 13 | { |
@@ -156,3 +158,24 @@ Gats::Dictionary *Gats::Dictionary::getDict( const Bu::FString &sKey ) | |||
156 | return pOb; | 158 | return pOb; |
157 | } | 159 | } |
158 | 160 | ||
161 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ) | ||
162 | { | ||
163 | f << "(dict) {"; | ||
164 | f.incIndent(); | ||
165 | int iMax = 0; | ||
166 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) | ||
167 | { | ||
168 | if( i.getKey().getSize() > iMax ) | ||
169 | iMax = i.getKey().getSize(); | ||
170 | } | ||
171 | iMax += 2; | ||
172 | for( Gats::Dictionary::const_iterator i = d.begin(); i; i++ ) | ||
173 | { | ||
174 | f << f.nl << Bu::Fmt( iMax ) << i.getKey() + ": " << *i.getValue(); | ||
175 | } | ||
176 | f.decIndent(); | ||
177 | f << f.nl << "}"; | ||
178 | |||
179 | return f; | ||
180 | } | ||
181 | |||
diff --git a/src/dictionary.h b/src/dictionary.h index 8f4b949..39248d2 100644 --- a/src/dictionary.h +++ b/src/dictionary.h | |||
@@ -43,4 +43,6 @@ template<> | |||
43 | uint32_t __calcHashCode<Gats::String>( const Gats::String &s ); | 43 | uint32_t __calcHashCode<Gats::String>( const Gats::String &s ); |
44 | }; | 44 | }; |
45 | 45 | ||
46 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ); | ||
47 | |||
46 | #endif | 48 | #endif |
diff --git a/src/float.cpp b/src/float.cpp index e257b37..139df3e 100644 --- a/src/float.cpp +++ b/src/float.cpp | |||
@@ -1,6 +1,8 @@ | |||
1 | #include "gats/float.h" | 1 | #include "gats/float.h" |
2 | #include "gats/integer.h" | 2 | #include "gats/integer.h" |
3 | 3 | ||
4 | #include <bu/formatter.h> | ||
5 | |||
4 | Gats::Float::Float() : | 6 | Gats::Float::Float() : |
5 | fVal( 0.0 ) | 7 | fVal( 0.0 ) |
6 | { | 8 | { |
@@ -35,3 +37,8 @@ void Gats::Float::read( Bu::Stream &rIn, char cType ) | |||
35 | sscanf( buf, "%la", &fVal ); | 37 | sscanf( buf, "%la", &fVal ); |
36 | } | 38 | } |
37 | 39 | ||
40 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ) | ||
41 | { | ||
42 | return f << "(float) " << flt.getValue(); | ||
43 | } | ||
44 | |||
diff --git a/src/float.h b/src/float.h index 1b3a06a..27233ae 100644 --- a/src/float.h +++ b/src/float.h | |||
@@ -23,4 +23,6 @@ namespace Gats | |||
23 | }; | 23 | }; |
24 | } | 24 | } |
25 | 25 | ||
26 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ); | ||
27 | |||
26 | #endif | 28 | #endif |
diff --git a/src/integer.cpp b/src/integer.cpp index ad48eaf..2a713e3 100644 --- a/src/integer.cpp +++ b/src/integer.cpp | |||
@@ -1,5 +1,7 @@ | |||
1 | #include "gats/integer.h" | 1 | #include "gats/integer.h" |
2 | 2 | ||
3 | #include <bu/formatter.h> | ||
4 | |||
3 | Gats::Integer::Integer() : | 5 | Gats::Integer::Integer() : |
4 | iVal( 0 ) | 6 | iVal( 0 ) |
5 | { | 7 | { |
@@ -25,3 +27,8 @@ void Gats::Integer::read( Bu::Stream &rIn, char cType ) | |||
25 | readPackedInt( rIn, iVal ); | 27 | readPackedInt( rIn, iVal ); |
26 | } | 28 | } |
27 | 29 | ||
30 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ) | ||
31 | { | ||
32 | return f << "(int) " << i.getValue(); | ||
33 | } | ||
34 | |||
diff --git a/src/integer.h b/src/integer.h index 6ed7c49..be7c808 100644 --- a/src/integer.h +++ b/src/integer.h | |||
@@ -75,4 +75,6 @@ namespace Gats | |||
75 | }; | 75 | }; |
76 | }; | 76 | }; |
77 | 77 | ||
78 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ); | ||
79 | |||
78 | #endif | 80 | #endif |
diff --git a/src/list.cpp b/src/list.cpp index 995a764..0e5f56f 100644 --- a/src/list.cpp +++ b/src/list.cpp | |||
@@ -1,5 +1,11 @@ | |||
1 | #include "gats/list.h" | 1 | #include "gats/list.h" |
2 | 2 | ||
3 | #include "gats/string.h" | ||
4 | #include "gats/integer.h" | ||
5 | #include "gats/float.h" | ||
6 | #include "gats/boolean.h" | ||
7 | |||
8 | #include <bu/formatter.h> | ||
3 | #include <bu/stream.h> | 9 | #include <bu/stream.h> |
4 | 10 | ||
5 | Gats::List::List() | 11 | Gats::List::List() |
@@ -31,3 +37,78 @@ void Gats::List::read( Bu::Stream &rIn, char cType ) | |||
31 | } | 37 | } |
32 | } | 38 | } |
33 | 39 | ||
40 | void Gats::List::append( const char *s ) | ||
41 | { | ||
42 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); | ||
43 | } | ||
44 | |||
45 | void Gats::List::append( const Bu::FString &s ) | ||
46 | { | ||
47 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); | ||
48 | } | ||
49 | |||
50 | void Gats::List::append( int32_t i ) | ||
51 | { | ||
52 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); | ||
53 | } | ||
54 | |||
55 | void Gats::List::append( int64_t i ) | ||
56 | { | ||
57 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); | ||
58 | } | ||
59 | |||
60 | void Gats::List::append( bool b ) | ||
61 | { | ||
62 | Bu::List<Gats::Object *>::append( new Gats::Boolean( b ) ); | ||
63 | } | ||
64 | |||
65 | void Gats::List::append( double d ) | ||
66 | { | ||
67 | Bu::List<Gats::Object *>::append( new Gats::Float( d ) ); | ||
68 | } | ||
69 | |||
70 | |||
71 | void Gats::List::prepend( const char *s ) | ||
72 | { | ||
73 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); | ||
74 | } | ||
75 | |||
76 | void Gats::List::prepend( const Bu::FString &s ) | ||
77 | { | ||
78 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); | ||
79 | } | ||
80 | |||
81 | void Gats::List::prepend( int32_t i ) | ||
82 | { | ||
83 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); | ||
84 | } | ||
85 | |||
86 | void Gats::List::prepend( int64_t i ) | ||
87 | { | ||
88 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); | ||
89 | } | ||
90 | |||
91 | void Gats::List::prepend( bool b ) | ||
92 | { | ||
93 | Bu::List<Gats::Object *>::prepend( new Gats::Boolean( b ) ); | ||
94 | } | ||
95 | |||
96 | void Gats::List::prepend( double d ) | ||
97 | { | ||
98 | Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) ); | ||
99 | } | ||
100 | |||
101 | |||
102 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ) | ||
103 | { | ||
104 | f << "(list) ["; | ||
105 | f.incIndent(); | ||
106 | for( Gats::List::const_iterator i = l.begin(); i; i++ ) | ||
107 | { | ||
108 | f << f.nl << **i; | ||
109 | } | ||
110 | f.decIndent(); | ||
111 | f << f.nl << "]"; | ||
112 | return f; | ||
113 | } | ||
114 | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | #include "gats/object.h" | 4 | #include "gats/object.h" |
5 | #include <bu/list.h> | 5 | #include <bu/list.h> |
6 | #include <bu/fstring.h> | ||
6 | 7 | ||
7 | namespace Gats | 8 | namespace Gats |
8 | { | 9 | { |
@@ -16,7 +17,25 @@ namespace Gats | |||
16 | 17 | ||
17 | virtual void write( Bu::Stream &rOut ) const; | 18 | virtual void write( Bu::Stream &rOut ) const; |
18 | virtual void read( Bu::Stream &rIn, char cType ); | 19 | virtual void read( Bu::Stream &rIn, char cType ); |
20 | |||
21 | void append( const char *s ); | ||
22 | void append( const Bu::FString &s ); | ||
23 | void append( int32_t i ); | ||
24 | void append( int64_t i ); | ||
25 | void append( bool b ); | ||
26 | void append( double d ); | ||
27 | using Bu::List<Gats::Object *>::append; | ||
28 | |||
29 | void prepend( const char *s ); | ||
30 | void prepend( const Bu::FString &s ); | ||
31 | void prepend( int32_t i ); | ||
32 | void prepend( int64_t i ); | ||
33 | void prepend( bool b ); | ||
34 | void prepend( double d ); | ||
35 | using Bu::List<Gats::Object *>::prepend; | ||
19 | }; | 36 | }; |
20 | }; | 37 | }; |
21 | 38 | ||
39 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ); | ||
40 | |||
22 | #endif | 41 | #endif |
diff --git a/src/object.cpp b/src/object.cpp index 9176b49..f5148ad 100644 --- a/src/object.cpp +++ b/src/object.cpp | |||
@@ -7,6 +7,7 @@ | |||
7 | #include "gats/list.h" | 7 | #include "gats/list.h" |
8 | #include "gats/dictionary.h" | 8 | #include "gats/dictionary.h" |
9 | 9 | ||
10 | #include <bu/formatter.h> | ||
10 | #include <bu/stream.h> | 11 | #include <bu/stream.h> |
11 | 12 | ||
12 | Gats::Object::Object() | 13 | Gats::Object::Object() |
@@ -61,3 +62,30 @@ Gats::Object *Gats::Object::read( Bu::Stream &rIn ) | |||
61 | return pObj; | 62 | return pObj; |
62 | } | 63 | } |
63 | 64 | ||
65 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ) | ||
66 | { | ||
67 | switch( obj.getType() ) | ||
68 | { | ||
69 | case Gats::typeDictionary: | ||
70 | return f << dynamic_cast<const Gats::Dictionary &>(obj); | ||
71 | |||
72 | case Gats::typeList: | ||
73 | return f << dynamic_cast<const Gats::List &>(obj); | ||
74 | |||
75 | case Gats::typeString: | ||
76 | return f << dynamic_cast<const Gats::String &>(obj); | ||
77 | |||
78 | case Gats::typeInteger: | ||
79 | return f << dynamic_cast<const Gats::Integer &>(obj); | ||
80 | |||
81 | case Gats::typeFloat: | ||
82 | return f << dynamic_cast<const Gats::Float &>(obj); | ||
83 | |||
84 | case Gats::typeBoolean: | ||
85 | return f << dynamic_cast<const Gats::Boolean &>(obj); | ||
86 | |||
87 | default: | ||
88 | return f << "***ERROR: Bad Gats type***"; | ||
89 | } | ||
90 | } | ||
91 | |||
diff --git a/src/object.h b/src/object.h index 10bdc47..44f9da7 100644 --- a/src/object.h +++ b/src/object.h | |||
@@ -4,6 +4,7 @@ | |||
4 | namespace Bu | 4 | namespace Bu |
5 | { | 5 | { |
6 | class Stream; | 6 | class Stream; |
7 | class Formatter; | ||
7 | }; | 8 | }; |
8 | 9 | ||
9 | namespace Gats | 10 | namespace Gats |
@@ -36,4 +37,6 @@ namespace Gats | |||
36 | }; | 37 | }; |
37 | }; | 38 | }; |
38 | 39 | ||
40 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Object &obj ); | ||
41 | |||
39 | #endif | 42 | #endif |
diff --git a/src/string.cpp b/src/string.cpp index 416375d..2134a01 100644 --- a/src/string.cpp +++ b/src/string.cpp | |||
@@ -2,10 +2,27 @@ | |||
2 | 2 | ||
3 | #include "gats/integer.h" | 3 | #include "gats/integer.h" |
4 | 4 | ||
5 | #include <bu/formatter.h> | ||
6 | |||
5 | Gats::String::String() | 7 | Gats::String::String() |
6 | { | 8 | { |
7 | } | 9 | } |
8 | 10 | ||
11 | Gats::String::String( const char *s ) : | ||
12 | Bu::FString( s ) | ||
13 | { | ||
14 | } | ||
15 | |||
16 | Gats::String::String( const char *s, long iLength ) : | ||
17 | Bu::FString( s, iLength ) | ||
18 | { | ||
19 | } | ||
20 | |||
21 | Gats::String::String( long iLength ) : | ||
22 | Bu::FString( iLength ) | ||
23 | { | ||
24 | } | ||
25 | |||
9 | Gats::String::String( const String &s ) : | 26 | Gats::String::String( const String &s ) : |
10 | Bu::FString( s ) | 27 | Bu::FString( s ) |
11 | { | 28 | { |
@@ -36,3 +53,8 @@ void Gats::String::read( Bu::Stream &rIn, char cType ) | |||
36 | rIn.read( getStr(), iSize ); | 53 | rIn.read( getStr(), iSize ); |
37 | } | 54 | } |
38 | 55 | ||
56 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ) | ||
57 | { | ||
58 | return f << "(str) \"" << dynamic_cast<const Bu::FString &>(s) << "\""; | ||
59 | } | ||
60 | |||
diff --git a/src/string.h b/src/string.h index 5343ba8..ea13517 100644 --- a/src/string.h +++ b/src/string.h | |||
@@ -10,6 +10,9 @@ namespace Gats | |||
10 | { | 10 | { |
11 | public: | 11 | public: |
12 | String(); | 12 | String(); |
13 | String( const char *s ); | ||
14 | String( const char *s, long iLength ); | ||
15 | String( long iLength ); | ||
13 | String( const String &s ); | 16 | String( const String &s ); |
14 | String( const Bu::FString &s ); | 17 | String( const Bu::FString &s ); |
15 | virtual ~String(); | 18 | virtual ~String(); |
@@ -23,4 +26,6 @@ namespace Gats | |||
23 | }; | 26 | }; |
24 | }; | 27 | }; |
25 | 28 | ||
29 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ); | ||
30 | |||
26 | #endif | 31 | #endif |