00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef TREENODE_H
00024 #define TREENODE_H
00025
00026 #include "skString.h"
00027 #include "skException.h"
00028
00029 class CLASSEXPORT skTreeNode;
00030 class CLASSEXPORT skTreeNodeList;
00031 class CLASSEXPORT skExecutableContext;
00032 class CLASSEXPORT skInputSource;
00033 class CLASSEXPORT skOutputDestination;
00034
00038 class CLASSEXPORT skTreeNodeListIterator
00039 {
00040 public:
00044 skTreeNodeListIterator(const skTreeNode&);
00048 ~skTreeNodeListIterator();
00052 skTreeNode * operator ()();
00056 void reset();
00057 private:
00058 const skTreeNode& m_Node;
00059 USize m_Index;
00060 };
00061
00067 class CLASSEXPORT skTreeNode
00068 {
00069 public:
00073 skTreeNode();
00077 virtual ~skTreeNode();
00081 skTreeNode(const skTreeNode& );
00085 skTreeNode(const skString& label);
00089 skTreeNode(const skString& label,const skString& data);
00093 skTreeNode(const skString& label,bool data);
00097 skTreeNode(const skString& label,int data);
00101 skTreeNode(const skString& label,float data);
00105 skTreeNode& operator=(const skTreeNode& );
00109 skString label() const;
00113 void label(const skString& s);
00117 skString data() const;
00121 void data(const skString& s);
00125 bool boolData() const;
00129 void boolData(bool);
00133 int intData() const;
00137 void intData(int);
00141 float floatData() const;
00145 void floatData(float);
00149 void prependChild(skTreeNode*);
00153 void addChild(skTreeNode*);
00157 void setChild(skTreeNode*);
00161 void removeChild(skTreeNode*);
00165 void deleteChild(skTreeNode*);
00169 bool containsChild(skTreeNode*);
00174 skTreeNode* findChild(const skString& label) const;
00179 skTreeNode* findChild(const skString& label,const skString& data) const;
00186 skString findChildData(const skString& label,const skString& defaultVal=skString()) const;
00193 bool findChildboolData(const skString& label, bool defaultVal=false) const;
00200 int findChildIntData(const skString& label, int defaultVal=0) const;
00207 float findChildFloatData(const skString& label, float defaultVal=0.0f) const;
00211 skString nthChildData(USize index) const;
00215 int nthChildIntData(USize index) const;
00222 void write(skOutputDestination& out,USize tabstops,bool include_tabs=true) const;
00227 bool write(const skString& file) const;
00234 skTreeNode * nthChild(USize i) const;
00238 USize numChildren() const;
00242 void copyItems(skTreeNode& node);
00246 void moveItemsFrom(skTreeNode& node);
00250 void clear();
00257 static skTreeNode * read(const skString& file,skExecutableContext& ctxt);
00258 friend class skTreeNodeList;
00259 friend class skTreeNodeListIterator;
00260
00261 private:
00265 skString m_Label;
00269 skString m_Data;
00273 skTreeNodeList * m_Items;
00274 };
00278
00279 #define USECLASSBUFFER
00280 const int MAXBUFFER=20000;
00281 class CLASSEXPORT skTreeNodeReader
00282 {
00283 public:
00284 skTreeNodeReader(skInputSource& in, const skString& source_name);
00288 ~skTreeNodeReader();
00295 skTreeNode* read(skExecutableContext& ctxt);
00296 private:
00297 enum Lexeme { L_IDENT, L_TEXT, L_LBRACE, L_RBRACE, L_EOF, L_ERROR };
00299 void grabBuffer();
00301 void error(const skString& msg);
00304 Lexeme lex();
00306 void unLex();
00311 skTreeNode * parseTreeNode(skTreeNode * pparent);
00315 void parseTreeNodeList(skTreeNode * list);
00317 void addToLexText(Char c);
00319 skString m_FileName;
00321 bool m_UnLex;
00323 Lexeme m_LastLexeme;
00325 Char * m_LexText;
00327 unsigned short m_LineNum;
00329 unsigned short m_Pos;
00331 skInputSource& m_In;
00333 bool m_Error;
00334 #ifdef USECLASSBUFFER
00335
00336 bool m_UsingClassLexText;
00338 static Char g_ClassLexText[MAXBUFFER];
00340 static bool g_LexTextUsed;
00341 #endif
00342 };
00343
00347 class CLASSEXPORT skTreeNodeReaderException : public skException
00348 {
00349 public:
00353 skTreeNodeReaderException(const skString& fileName,const skString& msg)
00354 : m_FileName(fileName),m_Msg(msg){
00355 }
00359 skString getMessage() const{
00360 return toString();
00361 }
00365 skString toString() const{
00366 return m_FileName+skSTR(":")+m_Msg;
00367 }
00368 private:
00369 skString m_FileName;
00370 skString m_Msg;
00371 };
00372 #include "skAlist.h"
00373 EXTERN_TEMPLATE template class CLASSEXPORT skTAList<skTreeNode>;
00374
00378 class CLASSEXPORT skTreeNodeList : public skTAList<skTreeNode>
00379 {
00380 public:
00382 skTreeNodeList();
00386 skTreeNodeList(const skTreeNodeList& list);
00388 virtual ~skTreeNodeList();
00393 skTreeNode * findItem(const skString& label) const;
00399 skTreeNode * findItem(const skString& label,const skString& data) const;
00404 skTreeNode * nthElt(USize i) const;
00408 skTreeNodeList& operator=(const skTreeNodeList& list);
00409 };
00410
00411 #endif
00412
00413
00414
00415
00416
00417
00418
00419
00420