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_8h-source.html,v 1.7 2004/12/17 21:31:15 sdw Exp $
00020 */
00021 
00022 
00023 #ifndef TREENODE_H
00024 #define TREENODE_H
00025 
00026 #include "skString.h"
00027 #include "skException.h"
00028 #include "skConstants.h"
00029 
00030 class  CLASSEXPORT skTreeNode;
00031 class  CLASSEXPORT skTreeNodeList;
00032 class  CLASSEXPORT skExecutableContext;
00033 class  CLASSEXPORT skInputSource;
00034 class  CLASSEXPORT skOutputDestination;
00035 
00036 
00042 class  CLASSEXPORT skTreeNode 
00043 #ifdef __SYMBIAN32__
00044 : public CBase
00045 #endif
00046 {
00047  public:
00051   inline skTreeNode();
00052 #ifndef __SYMBIAN32__
00053 
00057   skTreeNode(const skTreeNode& );
00058 #endif
00059 
00062   inline skTreeNode(const skString& label); 
00066   inline skTreeNode(const skString& label,const skString& data);
00070   IMPORT_C skTreeNode(const skString& label,bool data);
00074   IMPORT_C skTreeNode(const skString& label,int  data);
00075 #ifdef USE_FLOATING_POINT
00076 
00079   IMPORT_C skTreeNode(const skString& label,float data);
00080 #endif
00081 
00084   virtual ~skTreeNode();
00089   IMPORT_C skTreeNode& operator=(const skTreeNode& );
00093   IMPORT_C bool operator==(const skTreeNode& other) const;
00097   IMPORT_C bool deepCompare(const skTreeNode& other,bool check_tagname) const;
00101   inline skString label() const;
00105   inline void  label(const skString& s);
00109   inline void  label(const Char * s);
00113   inline skString data() const;
00117   inline void  data(const skString& s);
00121   inline void  data(const Char * s);
00125   IMPORT_C bool boolData() const;
00130   IMPORT_C void boolData(bool);
00134   IMPORT_C int  intData() const;
00139   IMPORT_C void intData(int);
00140 #ifdef USE_FLOATING_POINT
00141 
00144   IMPORT_C float floatData() const;
00149   IMPORT_C void floatData(float);
00150 #endif
00151 
00155   IMPORT_C void  prependChild(skTreeNode*);
00160   IMPORT_C void  addChild(skTreeNode*);
00165   IMPORT_C void  setChild(skTreeNode*); 
00169   IMPORT_C void  removeChild(skTreeNode*);
00173   IMPORT_C void  deleteChild(skTreeNode*);
00177   IMPORT_C bool containsChild(skTreeNode*);
00182   IMPORT_C skTreeNode* findChild(const skString& label) const;
00183 #ifdef __SYMBIAN32__
00184 
00189   IMPORT_C skTreeNode* findChild(const TDesC& label) const;
00190 #endif
00191 
00195   IMPORT_C skTreeNode* findChild(const skString& label,const skString& data) const;
00201   IMPORT_C skString findChildData(const skString& label) const;
00208   IMPORT_C skString findChildData(const skString& label,const skString& defaultVal) const;
00209 #ifdef __SYMBIAN32__
00210 
00216   IMPORT_C skString findChildData(const TDesC& label) const;
00217 #endif
00218 
00224   IMPORT_C bool findChildboolData(const skString& label, bool defaultVal=false) const;
00231   IMPORT_C int  findChildIntData(const skString& label, int defaultVal=0) const;
00232 #ifdef __SYMBIAN32__
00233 
00240   IMPORT_C int  findChildIntData(const TDesC& label, int defaultVal=0) const;
00241 #endif
00242 #ifdef USE_FLOATING_POINT
00243 
00249   IMPORT_C float findChildFloatData(const skString& label, float defaultVal=0.0f) const;
00250 #endif
00251 
00254   IMPORT_C skString nthChildData(USize index) const;
00258   IMPORT_C int  nthChildIntData(USize index) const;
00266   IMPORT_C void  write(skOutputDestination& out,USize tabstops,bool include_tabs=true) const;
00271   IMPORT_C bool write(const skString& file) const;
00278   IMPORT_C skTreeNode *  nthChild(USize  i) const;
00282   IMPORT_C USize numChildren() const;
00286   IMPORT_C void copyItems(skTreeNode& node);
00290   IMPORT_C void moveItemsFrom(skTreeNode& node);
00294   IMPORT_C void clear();
00302   static IMPORT_C skTreeNode * read(const skString& file,skExecutableContext& ctxt);
00303   
00304  private:
00308   static void writeTabs(skOutputDestination& out,int tabstops);
00309 #ifdef __SYMBIAN32__
00310 
00314   skTreeNode(const skTreeNode& );
00315 #endif
00316 
00319   skString m_Label;
00323   skString m_Data;
00327   skTreeNodeList * m_Items;
00328 };
00332 class  CLASSEXPORT skTreeNodeListIterator 
00333 #ifdef __SYMBIAN32__
00334 : public CBase
00335 #endif
00336 {
00337  public:
00341   IMPORT_C skTreeNodeListIterator(const skTreeNode&);
00345   IMPORT_C virtual ~skTreeNodeListIterator();
00349   IMPORT_C skTreeNode * operator ()();
00353   IMPORT_C void reset();
00354  private:
00355   const skTreeNode& m_Node;
00356   USize m_Index;
00357 };
00361 // switches on the optimization where a shared class buffer is used
00362 #ifndef __SYMBIAN32__
00363 #define USECLASSBUFFER
00364 #endif
00365 const int MAXBUFFER=20000;
00366 class  CLASSEXPORT skTreeNodeReader 
00367 #ifdef __SYMBIAN32__
00368 : public CBase
00369 #endif
00370 {
00371  public:
00372    IMPORT_C skTreeNodeReader();
00376    IMPORT_C skTreeNodeReader(skInputSource& in, const skString& source_name);
00380   IMPORT_C virtual ~skTreeNodeReader();
00388   IMPORT_C skTreeNode* read(skExecutableContext& ctxt);
00389 #ifdef __SYMBIAN32__
00390 
00398   IMPORT_C skTreeNode* read(skInputSource * in, const TDesC& source_name,skExecutableContext& ctxt);
00399 #endif
00400 #ifdef __SYMBIAN32__
00401 
00406   inline operator TCleanupItem();
00411   inline static void Cleanup(TAny * s);
00412 #endif
00413 
00416   IMPORT_C void clear();
00417  private:
00418   enum Lexeme           { L_IDENT, L_TEXT, L_LBRACE, L_RBRACE, L_EOF, L_ERROR };
00422   void grabBuffer();
00424   void error(const skString& msg);
00426   void error(const Char * msg);
00429   Lexeme lex();
00431   void  unLex();
00437   skTreeNode *  parseTreeNode(skTreeNode * pparent);
00442   void parseTreeNodeList(skTreeNode * list);
00444   void addToLexText(Char c);
00446   skString m_FileName;
00448   bool m_UnLex;
00450   Lexeme m_LastLexeme;
00452   Char  * m_LexText;
00454   unsigned short m_LineNum;
00456   unsigned short m_Pos;
00458   skInputSource * m_In;
00460   bool  m_Error;
00461 #ifdef USECLASSBUFFER
00462 
00463   bool  m_UsingClassLexText;
00465   static Char g_ClassLexText[MAXBUFFER];
00467   static bool g_LexTextUsed;
00468 #endif
00469 };
00470 
00474 class CLASSEXPORT  skTreeNodeReaderException : public skException
00475 {
00476  public:
00480   skTreeNodeReaderException(const skString& fileName,const skString& msg)
00481     : m_FileName(fileName),m_Msg(msg){
00482   }
00486   skString getMessage() const{
00487     return toString();
00488   }
00492   skString toString() const{
00493     return skString::addStrings(m_FileName.ptr(),s_colon,m_Msg.ptr());
00494   }
00495  private:
00496   skString m_FileName;
00497   skString m_Msg;
00498 };
00499 #include "skAlist.h"
00500 #ifdef INSTANTIATE_TEMPLATES
00501 EXTERN_TEMPLATE template class CLASSEXPORT skTAList<skTreeNode>;
00502 #endif
00503 
00507 class  CLASSEXPORT skTreeNodeList :  public skTAList<skTreeNode>
00508 {           
00509  public:
00511   IMPORT_C skTreeNodeList();
00512 #ifndef __SYMBIAN32__
00513 
00516   skTreeNodeList(const skTreeNodeList& list);
00517 #endif
00518 
00519   IMPORT_C virtual ~skTreeNodeList();
00524   IMPORT_C skTreeNode * findItem(const skString& label) const;
00530   IMPORT_C skTreeNode * findItem(const skString& label,const skString& data) const;
00535   IMPORT_C skTreeNode * nthElt(USize  i) const;
00540   IMPORT_C skTreeNodeList&   operator=(const skTreeNodeList& list);
00541 };
00542 
00543 //-----------------------------------------------------------------
00544 inline skTreeNode::skTreeNode()
00545 //-----------------------------------------------------------------
00546   : m_Items(0)
00547 {
00548 }
00549 //-----------------------------------------------------------------
00550 inline skTreeNode::skTreeNode(const skString& label)
00551   //-----------------------------------------------------------------
00552   : m_Label(label),m_Items(0)
00553 {
00554 }
00555 //-----------------------------------------------------------------
00556 inline skTreeNode::skTreeNode(const skString& label,const skString&  data)
00557   //-----------------------------------------------------------------
00558   : m_Label(label),m_Data(data),m_Items(0)
00559 {
00560 }
00561 //-----------------------------------------------------------------
00562 inline skString skTreeNode::label() const
00563   //-----------------------------------------------------------------
00564 {
00565   return m_Label;
00566 }
00567 //-----------------------------------------------------------------
00568 inline void skTreeNode::label(const skString& s) 
00569   //-----------------------------------------------------------------
00570 {
00571   m_Label=s;
00572 }
00573 //-----------------------------------------------------------------
00574 inline void skTreeNode::label(const Char * s) 
00575   //-----------------------------------------------------------------
00576 {
00577   m_Label=s;
00578 }
00579 //-----------------------------------------------------------------
00580 inline skString skTreeNode::data() const
00581 //-----------------------------------------------------------------
00582 {
00583   return m_Data;
00584 }
00585 //-----------------------------------------------------------------
00586 inline void skTreeNode::data(const skString& t) 
00587 //-----------------------------------------------------------------
00588 {
00589   m_Data=t;
00590 }
00591 //-----------------------------------------------------------------
00592 inline void skTreeNode::data(const Char * t) 
00593 //-----------------------------------------------------------------
00594 {
00595   m_Data=t;
00596 }
00597 #ifdef __SYMBIAN32__
00598 //-------------------------------------------------------------------------
00599 inline skTreeNodeReader::operator TCleanupItem()
00600   //-------------------------------------------------------------------------
00601   // used for leave support of local variable lists
00602 {
00603   return TCleanupItem(Cleanup,this);
00604 }
00605 //-------------------------------------------------------------------------
00606 inline void skTreeNodeReader::Cleanup(TAny * s)
00607   //-------------------------------------------------------------------------
00608   // called in case there is a leave
00609 {
00610   ((skTreeNodeReader *)s)->clear();
00611 }
00612 #endif
00613 //-----------------------------------------------------------------
00614 inline skTreeNodeList::skTreeNodeList()
00615 //-----------------------------------------------------------------
00616 {
00617 }
00618 
00619 #endif
00620                         
00621 
00622 
00623 
00624 
00625 
00626 
00627 
00628 

Generated on Fri Dec 17 20:28:26 2004 for Simkin C++ for Symbian by doxygen1.3