Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

skTreeNode.h

00001 /*
00002   Copyright 1996-2003
00003   Simon Whiteside
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019  * $Id: skTreeNode.h,v 1.28 2003/03/18 19:36:13 simkin_cvs Exp $
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 // switches on the optimization where a shared class buffer is used
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 

Generated on Tue Mar 18 19:46:18 2003 for Simkin by doxygen1.3-rc1