aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2022-04-06 23:45:42 -0700
committerMike Buland <eichlan@xagasoft.com>2022-04-06 23:45:42 -0700
commit3cbd1038e20dcb2b25db4e74666ec21766642729 (patch)
tree1fab95855d344196a44feadda75bfc0a5a63b61f
parentb522669649e81c61c6a5e390991b8fd70bfdeed9 (diff)
downloadlibgats-3cbd1038e20dcb2b25db4e74666ec21766642729.tar.gz
libgats-3cbd1038e20dcb2b25db4e74666ec21766642729.tar.bz2
libgats-3cbd1038e20dcb2b25db4e74666ec21766642729.tar.xz
libgats-3cbd1038e20dcb2b25db4e74666ec21766642729.zip
toString works.
It does indent automatically. I figure, you know, if you're converting to a string then a big part of the reason is so you can read it. In that case, why make it optional?
-rw-r--r--c++-qt/gats-qt/boolean.h2
-rw-r--r--c++-qt/gats-qt/dictionary.h2
-rw-r--r--c++-qt/gats-qt/float.h2
-rw-r--r--c++-qt/gats-qt/integer.h2
-rw-r--r--c++-qt/gats-qt/list.h2
-rw-r--r--c++-qt/gats-qt/null.h2
-rw-r--r--c++-qt/gats-qt/object.h2
-rw-r--r--c++-qt/gats-qt/string.h2
-rw-r--r--c++-qt/src/boolean.cpp8
-rw-r--r--c++-qt/src/dictionary.cpp46
-rw-r--r--c++-qt/src/float.cpp6
-rw-r--r--c++-qt/src/gatsstream.cpp7
-rw-r--r--c++-qt/src/integer.cpp7
-rw-r--r--c++-qt/src/list.cpp28
-rw-r--r--c++-qt/src/null.cpp7
-rw-r--r--c++-qt/src/object.cpp1
-rw-r--r--c++-qt/src/string.cpp26
17 files changed, 144 insertions, 8 deletions
diff --git a/c++-qt/gats-qt/boolean.h b/c++-qt/gats-qt/boolean.h
index e6d10af..07dcbc3 100644
--- a/c++-qt/gats-qt/boolean.h
+++ b/c++-qt/gats-qt/boolean.h
@@ -31,6 +31,8 @@ namespace Gats
31 31
32 virtual void write( QIODevice &rOut ) const; 32 virtual void write( QIODevice &rOut ) const;
33 virtual void read( QIODevice &rIn, char cType ); 33 virtual void read( QIODevice &rIn, char cType );
34
35 virtual QString toString( int iIndent=0 ) const;
34 36
35 private: 37 private:
36 bool bVal; 38 bool bVal;
diff --git a/c++-qt/gats-qt/dictionary.h b/c++-qt/gats-qt/dictionary.h
index b1b6051..6f9e82a 100644
--- a/c++-qt/gats-qt/dictionary.h
+++ b/c++-qt/gats-qt/dictionary.h
@@ -30,6 +30,8 @@ namespace Gats
30 virtual Type getType() const { return typeDictionary; } 30 virtual Type getType() const { return typeDictionary; }
31 virtual void write( QIODevice &rOut ) const; 31 virtual void write( QIODevice &rOut ) const;
32 virtual void read( QIODevice &rIn, char cType ); 32 virtual void read( QIODevice &rIn, char cType );
33
34 virtual QString toString( int iIndent=0 ) const;
33 35
34 void insert( const QByteArray &sKey, const char *s ); 36 void insert( const QByteArray &sKey, const char *s );
35 void insert( const QByteArray &sKey, const QByteArray &s ); 37 void insert( const QByteArray &sKey, const QByteArray &s );
diff --git a/c++-qt/gats-qt/float.h b/c++-qt/gats-qt/float.h
index 5a1ff4b..453d000 100644
--- a/c++-qt/gats-qt/float.h
+++ b/c++-qt/gats-qt/float.h
@@ -28,6 +28,8 @@ namespace Gats
28 28
29 virtual void write( QIODevice &rOut ) const; 29 virtual void write( QIODevice &rOut ) const;
30 virtual void read( QIODevice &rIn, char cType ); 30 virtual void read( QIODevice &rIn, char cType );
31
32 virtual QString toString( int iIndent=0 ) const;
31 33
32 private: 34 private:
33 double fVal; 35 double fVal;
diff --git a/c++-qt/gats-qt/integer.h b/c++-qt/gats-qt/integer.h
index 3427682..2f08d43 100644
--- a/c++-qt/gats-qt/integer.h
+++ b/c++-qt/gats-qt/integer.h
@@ -33,6 +33,8 @@ namespace Gats
33 33
34 virtual void write( QIODevice &rOut ) const; 34 virtual void write( QIODevice &rOut ) const;
35 virtual void read( QIODevice &rIn, char cType ); 35 virtual void read( QIODevice &rIn, char cType );
36
37 virtual QString toString( int iIndent=0 ) const;
36 38
37 template<typename itype> 39 template<typename itype>
38 static void readPackedInt( QIODevice &rStream, itype &rOut ) 40 static void readPackedInt( QIODevice &rStream, itype &rOut )
diff --git a/c++-qt/gats-qt/list.h b/c++-qt/gats-qt/list.h
index 27c17c3..f87ddd7 100644
--- a/c++-qt/gats-qt/list.h
+++ b/c++-qt/gats-qt/list.h
@@ -29,6 +29,8 @@ namespace Gats
29 29
30 virtual void write( QIODevice &rOut ) const; 30 virtual void write( QIODevice &rOut ) const;
31 virtual void read( QIODevice &rIn, char cType ); 31 virtual void read( QIODevice &rIn, char cType );
32
33 virtual QString toString( int iIndent=0 ) const;
32 34
33 void append( const char *s ); 35 void append( const char *s );
34 void append( const QByteArray &s ); 36 void append( const QByteArray &s );
diff --git a/c++-qt/gats-qt/null.h b/c++-qt/gats-qt/null.h
index 974ae09..7bf309a 100644
--- a/c++-qt/gats-qt/null.h
+++ b/c++-qt/gats-qt/null.h
@@ -27,6 +27,8 @@ namespace Gats
27 27
28 virtual void write( QIODevice &rOut ) const; 28 virtual void write( QIODevice &rOut ) const;
29 virtual void read( QIODevice &rIn, char cType ); 29 virtual void read( QIODevice &rIn, char cType );
30
31 virtual QString toString( int iIndent=0 ) const;
30 }; 32 };
31}; 33};
32 34
diff --git a/c++-qt/gats-qt/object.h b/c++-qt/gats-qt/object.h
index 6d602de..8d64c38 100644
--- a/c++-qt/gats-qt/object.h
+++ b/c++-qt/gats-qt/object.h
@@ -42,6 +42,8 @@ namespace Gats
42 42
43 virtual void write( QIODevice &rOut ) const=0; 43 virtual void write( QIODevice &rOut ) const=0;
44 virtual void read( QIODevice &rIn, char cType )=0; 44 virtual void read( QIODevice &rIn, char cType )=0;
45
46 virtual QString toString( int iIndent=0 ) const = 0;
45 47
46 static Object *read( QIODevice &rIn ); 48 static Object *read( QIODevice &rIn );
47// static Object *strToGats( const &sStr ); 49// static Object *strToGats( const &sStr );
diff --git a/c++-qt/gats-qt/string.h b/c++-qt/gats-qt/string.h
index 1e87db5..443c5a8 100644
--- a/c++-qt/gats-qt/string.h
+++ b/c++-qt/gats-qt/string.h
@@ -31,6 +31,8 @@ namespace Gats
31 31
32 virtual void write( QIODevice &rOut ) const; 32 virtual void write( QIODevice &rOut ) const;
33 virtual void read( QIODevice &rIn, char cType ); 33 virtual void read( QIODevice &rIn, char cType );
34
35 virtual QString toString( int iIndent=0 ) const;
34 36
35 private: 37 private:
36 }; 38 };
diff --git a/c++-qt/src/boolean.cpp b/c++-qt/src/boolean.cpp
index bd9bca1..8e7317a 100644
--- a/c++-qt/src/boolean.cpp
+++ b/c++-qt/src/boolean.cpp
@@ -40,7 +40,7 @@ void Gats::Boolean::write( QIODevice &rOut ) const
40 } 40 }
41} 41}
42 42
43void Gats::Boolean::read( QIODevice &rIn, char cType ) 43void Gats::Boolean::read( QIODevice & /*rIn*/, char cType )
44{ 44{
45 if( cType == '1' ) 45 if( cType == '1' )
46 { 46 {
@@ -51,6 +51,12 @@ void Gats::Boolean::read( QIODevice &rIn, char cType )
51 bVal = false; 51 bVal = false;
52 } 52 }
53} 53}
54
55QString Gats::Boolean::toString( int /*iIndent*/ ) const
56{
57 return bVal?"true":"false";
58}
59
54/* 60/*
55Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ) 61Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b )
56{ 62{
diff --git a/c++-qt/src/dictionary.cpp b/c++-qt/src/dictionary.cpp
index 10ec6c5..1d666ac 100644
--- a/c++-qt/src/dictionary.cpp
+++ b/c++-qt/src/dictionary.cpp
@@ -73,6 +73,52 @@ void Gats::Dictionary::read( QIODevice &rIn, char /*cType*/ )
73 } 73 }
74} 74}
75 75
76QString Gats::Dictionary::toString( int iIndent ) const
77{
78 if( count() == 0 )
79 return "{ }";
80 QString sRet("{");
81 iIndent++;
82 for( const_iterator i = begin(); i != end(); i++ )
83 {
84 if( i == begin() )
85 {
86 sRet += "\n";
87 }
88 else
89 {
90 sRet += ",\n";
91 }
92 for( int j = 0; j < iIndent; j++ ) sRet += " ";
93 sRet += '"';
94 for( QByteArray::const_iterator iS = i.key().begin();
95 iS != i.key().end(); iS++ )
96 {
97 switch( *iS )
98 {
99 case '\\':
100 sRet += "\\";
101 break;
102
103 case '\"':
104 sRet += "\\\"";
105 break;
106
107 default:
108 sRet += *iS;
109 break;
110 }
111 }
112 sRet += "\": ";
113 sRet += i.value()->toString( iIndent );
114 }
115 iIndent--;
116 sRet += "\n";
117 for( int j = 0; j < iIndent; j++ ) sRet += " ";
118 sRet += "}";
119 return sRet;
120}
121
76void Gats::Dictionary::insert( const QByteArray &sKey, char i ) 122void Gats::Dictionary::insert( const QByteArray &sKey, char i )
77{ 123{
78 ((QHash<QByteArray, Gats::Object *> *)this)->insert( 124 ((QHash<QByteArray, Gats::Object *> *)this)->insert(
diff --git a/c++-qt/src/float.cpp b/c++-qt/src/float.cpp
index 7f0d1a3..d4ec76e 100644
--- a/c++-qt/src/float.cpp
+++ b/c++-qt/src/float.cpp
@@ -126,6 +126,12 @@ void Gats::Float::read( QIODevice &rIn, char cType )
126 if( bNeg ) fVal = -fVal; 126 if( bNeg ) fVal = -fVal;
127 } 127 }
128} 128}
129
130QString Gats::Float::toString( int /*iIndent*/ ) const
131{
132 return QString("%1").arg( fVal );
133}
134
129/* 135/*
130Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ) 136Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt )
131{ 137{
diff --git a/c++-qt/src/gatsstream.cpp b/c++-qt/src/gatsstream.cpp
index cb6b53c..36b2ba8 100644
--- a/c++-qt/src/gatsstream.cpp
+++ b/c++-qt/src/gatsstream.cpp
@@ -42,8 +42,9 @@ Gats::Object *Gats::GatsStream::readObject()
42 } 42 }
43 } while( !skipReadNulls() ); 43 } while( !skipReadNulls() );
44 44
45 uint8_t uVer; 45 // There's only one version, so...we don't need to do anything with this
46 uVer = qbRead[0]; 46 //uint8_t uVer;
47 //uVer = qbRead[0];
47 48
48 int32_t iSize; 49 int32_t iSize;
49 memcpy( &iSize, qbRead.constData()+1, 4 ); 50 memcpy( &iSize, qbRead.constData()+1, 4 );
@@ -102,7 +103,7 @@ void Gats::GatsStream::writeObject( Gats::Object *pObject )
102 pTmp->write( (const char *)&iSize, 4 ); 103 pTmp->write( (const char *)&iSize, 4 );
103 pObject->write( *pTmp ); 104 pObject->write( *pTmp );
104 iSize = htonl( pTmp->pos() ); 105 iSize = htonl( pTmp->pos() );
105 uint64_t iEndPos = pTmp->pos(); 106 //uint64_t iEndPos = pTmp->pos();
106 pTmp->seek( iSizePos ); 107 pTmp->seek( iSizePos );
107 pTmp->write( (const char *)&iSize, 4 ); 108 pTmp->write( (const char *)&iSize, 4 );
108 109
diff --git a/c++-qt/src/integer.cpp b/c++-qt/src/integer.cpp
index 967eb30..1c665b4 100644
--- a/c++-qt/src/integer.cpp
+++ b/c++-qt/src/integer.cpp
@@ -32,10 +32,15 @@ void Gats::Integer::write( QIODevice &rOut ) const
32 writePackedInt( rOut, iVal ); 32 writePackedInt( rOut, iVal );
33} 33}
34 34
35void Gats::Integer::read( QIODevice &rIn, char cType ) 35void Gats::Integer::read( QIODevice &rIn, char /*cType*/ )
36{ 36{
37 readPackedInt( rIn, iVal ); 37 readPackedInt( rIn, iVal );
38} 38}
39
40QString Gats::Integer::toString( int /*iIndent*/ ) const
41{
42 return QString("%1").arg( iVal );
43}
39/* 44/*
40Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ) 45Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i )
41{ 46{
diff --git a/c++-qt/src/list.cpp b/c++-qt/src/list.cpp
index fae51d1..cca7c46 100644
--- a/c++-qt/src/list.cpp
+++ b/c++-qt/src/list.cpp
@@ -48,7 +48,7 @@ void Gats::List::write( QIODevice &rOut ) const
48 rOut.write("e", 1 ); 48 rOut.write("e", 1 );
49} 49}
50 50
51void Gats::List::read( QIODevice &rIn, char cType ) 51void Gats::List::read( QIODevice &rIn, char /*cType*/ )
52{ 52{
53 for(;;) 53 for(;;)
54 { 54 {
@@ -59,6 +59,32 @@ void Gats::List::read( QIODevice &rIn, char cType )
59 } 59 }
60} 60}
61 61
62QString Gats::List::toString( int iIndent ) const
63{
64 if( count() == 0 )
65 return "[ ]";
66 QString sRet("[");
67 iIndent++;
68 for( const_iterator i = begin(); i != end(); i++ )
69 {
70 if( i != begin() )
71 {
72 sRet += ",\n";
73 }
74 else
75 {
76 sRet += "\n";
77 }
78 for( int j = 0; j < iIndent; j++ ) sRet += " ";
79 sRet += (*i)->toString( iIndent );
80 }
81 sRet += "\n";
82 iIndent--;
83 for( int j = 0; j < iIndent; j++ ) sRet += " ";
84 sRet += ']';
85 return sRet;
86}
87
62void Gats::List::append( const char *s ) 88void Gats::List::append( const char *s )
63{ 89{
64 QList<Gats::Object *>::append( new Gats::String( s ) ); 90 QList<Gats::Object *>::append( new Gats::String( s ) );
diff --git a/c++-qt/src/null.cpp b/c++-qt/src/null.cpp
index 8bc87a6..5e3a19c 100644
--- a/c++-qt/src/null.cpp
+++ b/c++-qt/src/null.cpp
@@ -27,9 +27,14 @@ void Gats::Null::write( QIODevice &rOut ) const
27 rOut.write("n", 1 ); 27 rOut.write("n", 1 );
28} 28}
29 29
30void Gats::Null::read( QIODevice &rIn, char cType ) 30void Gats::Null::read( QIODevice & /*rIn*/, char /*cType*/ )
31{ 31{
32} 32}
33
34QString Gats::Null::toString( int /*iIndent*/ ) const
35{
36 return "null";
37}
33/* 38/*
34Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b ) 39Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Null &b )
35{ 40{
diff --git a/c++-qt/src/object.cpp b/c++-qt/src/object.cpp
index 8af203f..b0f0f12 100644
--- a/c++-qt/src/object.cpp
+++ b/c++-qt/src/object.cpp
@@ -88,6 +88,7 @@ const char *Gats::typeToStr( Gats::Type t )
88 case Gats::typeInteger: return "integer"; 88 case Gats::typeInteger: return "integer";
89 case Gats::typeFloat: return "float"; 89 case Gats::typeFloat: return "float";
90 case Gats::typeBoolean: return "boolean"; 90 case Gats::typeBoolean: return "boolean";
91 case Gats::typeNull: return "null";
91 } 92 }
92 93
93 return "***unknown***"; 94 return "***unknown***";
diff --git a/c++-qt/src/string.cpp b/c++-qt/src/string.cpp
index 1eddcf6..fd6cad1 100644
--- a/c++-qt/src/string.cpp
+++ b/c++-qt/src/string.cpp
@@ -57,13 +57,37 @@ void Gats::String::write( QIODevice &rOut ) const
57 rOut.write( constData(), iSize ); 57 rOut.write( constData(), iSize );
58} 58}
59 59
60void Gats::String::read( QIODevice &rIn, char cType ) 60void Gats::String::read( QIODevice &rIn, char /*cType*/ )
61{ 61{
62 uint32_t iSize; 62 uint32_t iSize;
63 Gats::Integer::readPackedInt( rIn, iSize ); 63 Gats::Integer::readPackedInt( rIn, iSize );
64 fill( '\0', iSize ); 64 fill( '\0', iSize );
65 rIn.read( data(), iSize ); 65 rIn.read( data(), iSize );
66} 66}
67
68QString Gats::String::toString( int /*iIndent*/ ) const
69{
70 QString sRet("\"");
71 for( const_iterator iS = begin(); iS != end(); iS++ )
72 {
73 switch( *iS )
74 {
75 case '\\':
76 sRet += "\\";
77 break;
78
79 case '\"':
80 sRet += "\\\"";
81 break;
82
83 default:
84 sRet += *iS;
85 break;
86 }
87 }
88 sRet += "\"";
89 return sRet;
90}
67/* 91/*
68Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ) 92Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s )
69{ 93{