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 /c++-libbu++/src/gatscon/treetogats.cpp | |
| 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.
Diffstat (limited to '')
| -rw-r--r-- | c++-libbu++/src/gatscon/treetogats.cpp | 89 |
1 files changed, 48 insertions, 41 deletions
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 | ||
