diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 16:25:22 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 16:25:22 +0000 |
commit | 74dd68ad611d15abf16a65c36a7cfd3f4492930a (patch) | |
tree | 843fed9ba6bb03253a01314afc3b1dfbb2dfd26c /c++-libbu++/src/gatscon/treetogats.cpp | |
parent | d9b407475ae3ebe434b29d9eabdd7d4416e17881 (diff) | |
download | libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.gz libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.bz2 libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.xz libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.zip |
Made the repo less libbu++-centric.
Diffstat (limited to 'c++-libbu++/src/gatscon/treetogats.cpp')
-rw-r--r-- | c++-libbu++/src/gatscon/treetogats.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/c++-libbu++/src/gatscon/treetogats.cpp b/c++-libbu++/src/gatscon/treetogats.cpp new file mode 100644 index 0000000..a1571d1 --- /dev/null +++ b/c++-libbu++/src/gatscon/treetogats.cpp | |||
@@ -0,0 +1,52 @@ | |||
1 | #include "treetogats.h" | ||
2 | |||
3 | #include <QTreeWidgetItem> | ||
4 | |||
5 | #include <gats/types.h> | ||
6 | |||
7 | Gats::Object *treeToGats( QTreeWidgetItem *pRoot ) | ||
8 | { | ||
9 | QString sType = pRoot->text( 1 ); | ||
10 | QByteArray baDat = pRoot->text( 2 ).toAscii(); | ||
11 | if( sType == "int" ) | ||
12 | { | ||
13 | return new Gats::Integer( strtoll( baDat.constData(), NULL, 10 ) ); | ||
14 | } | ||
15 | else if( sType == "str" ) | ||
16 | { | ||
17 | return new Gats::String( baDat.constData(), baDat.size() ); | ||
18 | } | ||
19 | else if( sType == "float" ) | ||
20 | { | ||
21 | return new Gats::Float( strtod( baDat.constData(), NULL ) ); | ||
22 | } | ||
23 | else if( sType == "bool" ) | ||
24 | { | ||
25 | return new Gats::Boolean( baDat == "true" ); | ||
26 | } | ||
27 | else if( sType == "list" ) | ||
28 | { | ||
29 | Gats::List *pRet = new Gats::List(); | ||
30 | for( int j = 0; j < pRoot->childCount(); j++ ) | ||
31 | { | ||
32 | pRet->append( treeToGats( pRoot->child( j ) ) ); | ||
33 | } | ||
34 | return pRet; | ||
35 | } | ||
36 | else if( sType == "dict" ) | ||
37 | { | ||
38 | Gats::Dictionary *pRet = new Gats::Dictionary(); | ||
39 | for( int j = 0; j < pRoot->childCount(); j++ ) | ||
40 | { | ||
41 | QTreeWidgetItem *pChild = pRoot->child( j ); | ||
42 | pRet->insert( | ||
43 | pChild->text( 0 ).toAscii().constData(), | ||
44 | treeToGats( pChild ) | ||
45 | ); | ||
46 | } | ||
47 | return pRet; | ||
48 | } | ||
49 | |||
50 | throw Bu::ExceptionBase("Unhandled type found."); | ||
51 | } | ||
52 | |||