From 3c846af2fa8e4693c190c5131ec87d967eb58b3e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 6 Jun 2007 21:18:15 +0000 Subject: The TafReader is more general and much nicer, and about to actually construct nodes, that part will be exciting. I also fixed some stuff and added some new functions to List, it now has first() and last() which work just like std::list front() and back(), I may add compatibility functions later... --- src/entities/bu-class | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/list.h | 20 ++++++++++++++++++++ src/tafdocument.cpp | 9 --------- src/tafdocument.h | 22 ---------------------- src/tafnode.cpp | 16 ++++++++++++++++ src/tafnode.h | 17 ++++++++++++++++- src/tafreader.cpp | 47 ++++++++++++++++++++--------------------------- src/tafreader.h | 12 +++++++----- 8 files changed, 125 insertions(+), 64 deletions(-) create mode 100644 src/entities/bu-class delete mode 100644 src/tafdocument.cpp delete mode 100644 src/tafdocument.h (limited to 'src') diff --git a/src/entities/bu-class b/src/entities/bu-class new file mode 100644 index 0000000..81e3d25 --- /dev/null +++ b/src/entities/bu-class @@ -0,0 +1,46 @@ + + + + + #ifndef {=name:%uccsplit:%toupper}_H +#define {=name:%uccsplit:%toupper}_H + +#include <stdint.h> + +{?parent:"#include \"{=parent:%tolower}.h\" + +"}namespace Bu +{ + /** + * + */ + class {=name}{?parent:" : public {=parent}"} + { + public: + {=name}(); + virtual ~{=name}(); + + private: + + }; +} + +#endif + + #include "bu/{=name:%tolower}.h" + +Bu::{=name}::{=name}() +{ +} + +Bu::{=name}::~{=name}() +{ +} + + diff --git a/src/list.h b/src/list.h index ea67f45..4131987 100644 --- a/src/list.h +++ b/src/list.h @@ -344,6 +344,26 @@ namespace Bu { return nSize; } + + value &first() + { + return *pFirst->pValue; + } + + const value &first() const + { + return *pFirst->pValue; + } + + value &last() + { + return *pLast->pValue; + } + + const value &last() const + { + return *pLast->pValue; + } private: Link *pFirst; diff --git a/src/tafdocument.cpp b/src/tafdocument.cpp deleted file mode 100644 index bd44dd5..0000000 --- a/src/tafdocument.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "tafdocument.h" - -Bu::TafDocument::TafDocument() -{ -} - -Bu::TafDocument::~TafDocument() -{ -} diff --git a/src/tafdocument.h b/src/tafdocument.h deleted file mode 100644 index 171f829..0000000 --- a/src/tafdocument.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef BU_TAF_DOCUMENT_H -#define BU_TAF_DOCUMENT_H - -#include - -namespace Bu -{ - /** - * - */ - class TafDocument - { - public: - TafDocument(); - virtual ~TafDocument(); - - private: - - }; -} - -#endif diff --git a/src/tafnode.cpp b/src/tafnode.cpp index c9756ec..01880d9 100644 --- a/src/tafnode.cpp +++ b/src/tafnode.cpp @@ -7,3 +7,19 @@ Bu::TafNode::TafNode() Bu::TafNode::~TafNode() { } + +void Bu::TafNode::setProperty( Bu::FString sName, Bu::FString sValue ) +{ + if( hProp.has( sName ) ) + { + hProp.insert( sName, PropList() ); + } + + hProp.get( sName ).append( sValue ); +} + +const Bu::TafNode::PropList &Bu::TafNode::getProperty( const Bu::FString &sName ) +{ + return hProp.get( sName ); +} + diff --git a/src/tafnode.h b/src/tafnode.h index 34f5289..e962e88 100644 --- a/src/tafnode.h +++ b/src/tafnode.h @@ -2,6 +2,9 @@ #define BU_TAF_NODE_H #include +#include "bu/fstring.h" +#include "bu/hash.h" +#include "bu/list.h" namespace Bu { @@ -10,12 +13,24 @@ namespace Bu */ class TafNode { + public: + typedef Bu::List PropList; + typedef Bu::Hash PropHash; + typedef Bu::List NodeList; + typedef Bu::Hash NodeHash; + public: TafNode(); virtual ~TafNode(); - private: + void setProperty( Bu::FString sName, Bu::FString sValue ); + const PropList &getProperty( const Bu::FString &sName ); + private: + Bu::FString sName; + PropHash hProp; + NodeHash hChildren; }; } + #endif diff --git a/src/tafreader.cpp b/src/tafreader.cpp index 91aa9f2..3bca3d1 100644 --- a/src/tafreader.cpp +++ b/src/tafreader.cpp @@ -2,6 +2,8 @@ #include "bu/exceptions.h" #include "bu/fstring.h" +using namespace Bu; + Bu::TafReader::TafReader( Bu::Stream &sIn ) : sIn( sIn ) { @@ -13,22 +15,18 @@ Bu::TafReader::~TafReader() { } +Bu::TafNode *Bu::TafReader::readNode() +{ +} + void Bu::TafReader::node() { ws(); if( c != '{' ) - throw Bu::TafException("Expected '{'"); + throw TafException("Expected '{'"); next(); ws(); - Bu::FString sName; - for(;;) - { - if( c == ':' ) - break; - else - sName += c; - next(); - } + FString sName = readStr(); next(); printf("Node[%s]:\n", sName.getStr() ); @@ -56,15 +54,7 @@ void Bu::TafReader::nodeContent() void Bu::TafReader::nodeProperty() { - Bu::FString sName; - for(;;) - { - if( isws() || c == '=' ) - break; - else - sName += c; - next(); - } + FString sName = readStr(); ws(); if( c != '=' ) { @@ -72,8 +62,14 @@ void Bu::TafReader::nodeProperty() return; } next(); + FString sValue = readStr(); + printf(" %s = %s\n", sName.getStr(), sValue.getStr() ); +} + +Bu::FString Bu::TafReader::readStr() +{ ws(); - Bu::FString sValue; + FString s; if( c == '"' ) { next(); @@ -98,7 +94,7 @@ void Bu::TafReader::nodeProperty() } else if( c == '"' ) break; - sValue += c; + s += c; next(); } next(); @@ -107,17 +103,14 @@ void Bu::TafReader::nodeProperty() { for(;;) { - if( isws() || c == '}' || c == '{' ) + if( isws() || c == '}' || c == '{' || c == ':' || c == '=' ) break; - sValue += c; + s += c; next(); } } - printf(" %s = %s\n", sName.getStr(), sValue.getStr() ); -} -FString Bu::TafReader::readStr() -{ + return s; } void Bu::TafReader::ws() diff --git a/src/tafreader.h b/src/tafreader.h index 127b571..4da800c 100644 --- a/src/tafreader.h +++ b/src/tafreader.h @@ -2,20 +2,23 @@ #define BU_TAF_READER_H #include -#include "bu/tafdocument.h" +#include "bu/tafnode.h" #include "bu/stream.h" +#include "bu/fstring.h" namespace Bu { /** * */ - class TafReader : public Bu::TafDocument + class TafReader { public: TafReader( Bu::Stream &sIn ); virtual ~TafReader(); + Bu::TafNode *readNode(); + private: void node(); void nodeContent(); @@ -23,10 +26,9 @@ namespace Bu void ws(); bool isws(); void next(); - FString readStr(); + Bu::FString readStr(); char c; - Stream &sIn; - + Bu::Stream &sIn; }; } -- cgit v1.2.3