aboutsummaryrefslogtreecommitdiff
path: root/src/gatscon/treetogats.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/gatscon/treetogats.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/gatscon/treetogats.cpp b/src/gatscon/treetogats.cpp
new file mode 100644
index 0000000..a1571d1
--- /dev/null
+++ b/src/gatscon/treetogats.cpp
@@ -0,0 +1,52 @@
1#include "treetogats.h"
2
3#include <QTreeWidgetItem>
4
5#include <gats/types.h>
6
7Gats::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