summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-06 21:18:15 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-06 21:18:15 +0000
commit3c846af2fa8e4693c190c5131ec87d967eb58b3e (patch)
tree46ce9a7ae6f83d1dccd79a751a5340cca2eb05bc
parent3144bd7deb950de0cb80e2215c1545bdf8fc81e9 (diff)
downloadlibbu++-3c846af2fa8e4693c190c5131ec87d967eb58b3e.tar.gz
libbu++-3c846af2fa8e4693c190c5131ec87d967eb58b3e.tar.bz2
libbu++-3c846af2fa8e4693c190c5131ec87d967eb58b3e.tar.xz
libbu++-3c846af2fa8e4693c190c5131ec87d967eb58b3e.zip
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...
-rw-r--r--src/entities/bu-class46
-rw-r--r--src/list.h20
-rw-r--r--src/tafdocument.cpp9
-rw-r--r--src/tafdocument.h22
-rw-r--r--src/tafnode.cpp16
-rw-r--r--src/tafnode.h17
-rw-r--r--src/tafreader.cpp47
-rw-r--r--src/tafreader.h12
-rw-r--r--test.taf26
9 files changed, 151 insertions, 64 deletions
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 @@
1<?xml version="1.1" ?>
2<entity desc="Basic cpp class, with optional parent class. (.cpp+.h)">
3 <param name="name" required="yes" desc="Name of the class"/>
4 <param name="parent" required="no" desc="Name of the parent class"/>
5 <file
6 name="header"
7 filename="{=name:%tolower}.h"
8>#ifndef {=name:%uccsplit:%toupper}_H
9#define {=name:%uccsplit:%toupper}_H
10
11#include &lt;stdint.h&gt;
12
13{?parent:"#include \"{=parent:%tolower}.h\"
14
15"}namespace Bu
16{
17 /**
18 *
19 */
20 class {=name}{?parent:" : public {=parent}"}
21 {
22 public:
23 {=name}();
24 virtual ~{=name}();
25
26 private:
27
28 };
29}
30
31#endif
32</file>
33 <file
34 name="source"
35 filename="{=name:%tolower}.cpp"
36>#include "bu/{=name:%tolower}.h"
37
38Bu::{=name}::{=name}()
39{
40}
41
42Bu::{=name}::~{=name}()
43{
44}
45</file>
46</entity>
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
344 { 344 {
345 return nSize; 345 return nSize;
346 } 346 }
347
348 value &first()
349 {
350 return *pFirst->pValue;
351 }
352
353 const value &first() const
354 {
355 return *pFirst->pValue;
356 }
357
358 value &last()
359 {
360 return *pLast->pValue;
361 }
362
363 const value &last() const
364 {
365 return *pLast->pValue;
366 }
347 367
348 private: 368 private:
349 Link *pFirst; 369 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 @@
1#include "tafdocument.h"
2
3Bu::TafDocument::TafDocument()
4{
5}
6
7Bu::TafDocument::~TafDocument()
8{
9}
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 @@
1#ifndef BU_TAF_DOCUMENT_H
2#define BU_TAF_DOCUMENT_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 /**
9 *
10 */
11 class TafDocument
12 {
13 public:
14 TafDocument();
15 virtual ~TafDocument();
16
17 private:
18
19 };
20}
21
22#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()
7Bu::TafNode::~TafNode() 7Bu::TafNode::~TafNode()
8{ 8{
9} 9}
10
11void Bu::TafNode::setProperty( Bu::FString sName, Bu::FString sValue )
12{
13 if( hProp.has( sName ) )
14 {
15 hProp.insert( sName, PropList() );
16 }
17
18 hProp.get( sName ).append( sValue );
19}
20
21const Bu::TafNode::PropList &Bu::TafNode::getProperty( const Bu::FString &sName )
22{
23 return hProp.get( sName );
24}
25
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 @@
2#define BU_TAF_NODE_H 2#define BU_TAF_NODE_H
3 3
4#include <stdint.h> 4#include <stdint.h>
5#include "bu/fstring.h"
6#include "bu/hash.h"
7#include "bu/list.h"
5 8
6namespace Bu 9namespace Bu
7{ 10{
@@ -11,11 +14,23 @@ namespace Bu
11 class TafNode 14 class TafNode
12 { 15 {
13 public: 16 public:
17 typedef Bu::List<Bu::FString> PropList;
18 typedef Bu::Hash<Bu::FString, PropList> PropHash;
19 typedef Bu::List<TafNode *> NodeList;
20 typedef Bu::Hash<Bu::FString, NodeList> NodeHash;
21
22 public:
14 TafNode(); 23 TafNode();
15 virtual ~TafNode(); 24 virtual ~TafNode();
16 25
17 private: 26 void setProperty( Bu::FString sName, Bu::FString sValue );
27 const PropList &getProperty( const Bu::FString &sName );
18 28
29 private:
30 Bu::FString sName;
31 PropHash hProp;
32 NodeHash hChildren;
19 }; 33 };
20} 34}
35
21#endif 36#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 @@
2#include "bu/exceptions.h" 2#include "bu/exceptions.h"
3#include "bu/fstring.h" 3#include "bu/fstring.h"
4 4
5using namespace Bu;
6
5Bu::TafReader::TafReader( Bu::Stream &sIn ) : 7Bu::TafReader::TafReader( Bu::Stream &sIn ) :
6 sIn( sIn ) 8 sIn( sIn )
7{ 9{
@@ -13,22 +15,18 @@ Bu::TafReader::~TafReader()
13{ 15{
14} 16}
15 17
18Bu::TafNode *Bu::TafReader::readNode()
19{
20}
21
16void Bu::TafReader::node() 22void Bu::TafReader::node()
17{ 23{
18 ws(); 24 ws();
19 if( c != '{' ) 25 if( c != '{' )
20 throw Bu::TafException("Expected '{'"); 26 throw TafException("Expected '{'");
21 next(); 27 next();
22 ws(); 28 ws();
23 Bu::FString sName; 29 FString sName = readStr();
24 for(;;)
25 {
26 if( c == ':' )
27 break;
28 else
29 sName += c;
30 next();
31 }
32 next(); 30 next();
33 printf("Node[%s]:\n", sName.getStr() ); 31 printf("Node[%s]:\n", sName.getStr() );
34 32
@@ -56,15 +54,7 @@ void Bu::TafReader::nodeContent()
56 54
57void Bu::TafReader::nodeProperty() 55void Bu::TafReader::nodeProperty()
58{ 56{
59 Bu::FString sName; 57 FString sName = readStr();
60 for(;;)
61 {
62 if( isws() || c == '=' )
63 break;
64 else
65 sName += c;
66 next();
67 }
68 ws(); 58 ws();
69 if( c != '=' ) 59 if( c != '=' )
70 { 60 {
@@ -72,8 +62,14 @@ void Bu::TafReader::nodeProperty()
72 return; 62 return;
73 } 63 }
74 next(); 64 next();
65 FString sValue = readStr();
66 printf(" %s = %s\n", sName.getStr(), sValue.getStr() );
67}
68
69Bu::FString Bu::TafReader::readStr()
70{
75 ws(); 71 ws();
76 Bu::FString sValue; 72 FString s;
77 if( c == '"' ) 73 if( c == '"' )
78 { 74 {
79 next(); 75 next();
@@ -98,7 +94,7 @@ void Bu::TafReader::nodeProperty()
98 } 94 }
99 else if( c == '"' ) 95 else if( c == '"' )
100 break; 96 break;
101 sValue += c; 97 s += c;
102 next(); 98 next();
103 } 99 }
104 next(); 100 next();
@@ -107,17 +103,14 @@ void Bu::TafReader::nodeProperty()
107 { 103 {
108 for(;;) 104 for(;;)
109 { 105 {
110 if( isws() || c == '}' || c == '{' ) 106 if( isws() || c == '}' || c == '{' || c == ':' || c == '=' )
111 break; 107 break;
112 sValue += c; 108 s += c;
113 next(); 109 next();
114 } 110 }
115 } 111 }
116 printf(" %s = %s\n", sName.getStr(), sValue.getStr() );
117}
118 112
119FString Bu::TafReader::readStr() 113 return s;
120{
121} 114}
122 115
123void Bu::TafReader::ws() 116void 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 @@
2#define BU_TAF_READER_H 2#define BU_TAF_READER_H
3 3
4#include <stdint.h> 4#include <stdint.h>
5#include "bu/tafdocument.h" 5#include "bu/tafnode.h"
6#include "bu/stream.h" 6#include "bu/stream.h"
7#include "bu/fstring.h"
7 8
8namespace Bu 9namespace Bu
9{ 10{
10 /** 11 /**
11 * 12 *
12 */ 13 */
13 class TafReader : public Bu::TafDocument 14 class TafReader
14 { 15 {
15 public: 16 public:
16 TafReader( Bu::Stream &sIn ); 17 TafReader( Bu::Stream &sIn );
17 virtual ~TafReader(); 18 virtual ~TafReader();
18 19
20 Bu::TafNode *readNode();
21
19 private: 22 private:
20 void node(); 23 void node();
21 void nodeContent(); 24 void nodeContent();
@@ -23,10 +26,9 @@ namespace Bu
23 void ws(); 26 void ws();
24 bool isws(); 27 bool isws();
25 void next(); 28 void next();
26 FString readStr(); 29 Bu::FString readStr();
27 char c; 30 char c;
28 Stream &sIn; 31 Bu::Stream &sIn;
29
30 }; 32 };
31} 33}
32 34
diff --git a/test.taf b/test.taf
new file mode 100644
index 0000000..045b042
--- /dev/null
+++ b/test.taf
@@ -0,0 +1,26 @@
1{player:
2 password = "aoeuaoeuao"
3 userclass = "implementor"
4 species = "human"
5 sex = "male"
6 active
7 startroom = "Salourn::Xagafinelle's Room"
8 {stats: str=14 dex=12 spd=12 enr=7 rea=12 wil=10 int=13 cha=14}
9 {hp: cur = 100 max = 100}
10 {en: cur = 100 max = 100}
11 attackrate = 30
12 gold = 0
13 {inventory:
14 {: count=1 id="Salourn::Dark Blade"}
15 {: count=1 id="Salourn::Dark Suit"}
16 {: count=3 id="Salourn::Small Fig"}
17 }
18 {aliases:
19 {: key="." value="say"}
20 {: key="," value="yell"}
21 {: key="li" value="lightning"}
22 }
23 description = "They appear to be rather average looking, not particularly
24 tall or short, with facial features that are difficult to remember even
25 seconds after witnessing them."
26}