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

skTreeNode.h

00001 /*
00002   Copyright 1996-2002
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.18 2002/12/16 16:11:46 sdw 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 
00036 class  CLASSEXPORT skTreeNodeListIterator 
00037 {
00038  public:
00042   skTreeNodeListIterator(const skTreeNode&);
00046   ~skTreeNodeListIterator();
00050   skTreeNode * operator ()();
00054   void reset();
00055  private:
00056   const skTreeNode& m_Node;
00057   USize m_Index;
00058 };
00059 
00065 class  CLASSEXPORT skTreeNode 
00066 {
00067  public:
00071   skTreeNode();
00075   virtual ~skTreeNode();
00079   skTreeNode(const skTreeNode& );
00083   skTreeNode(const skString& label); 
00087   skTreeNode(const skString& label,const skString& data);
00091   skTreeNode(const skString& label,bool data);
00095   skTreeNode(const skString& label,int  data);
00099   skTreeNode(const skString& label,float data);
00103   skTreeNode& operator=(const skTreeNode& );
00107   skString label() const;
00111   void  label(const skString& s);
00115   skString data() const;
00119   void  data(const skString& s);
00123   bool  boolData() const;
00127   void  boolData(bool);
00131   int   intData() const;
00135   void  intData(int);
00139   float floatData() const;
00143   void  floatData(float);
00147   void  prependChild(skTreeNode*);
00151   void  addChild(skTreeNode*);
00155   void  setChild(skTreeNode*);  
00159   void  deleteChild(skTreeNode*);
00163   bool  containsChild(skTreeNode*);
00168   skTreeNode* findChild(const skString& label) const;
00173   skTreeNode* findChild(const skString& label,const skString& data) const;
00180   skString findChildData(const skString& label,const skString& defaultVal=skString()) const;
00187   bool  findChildboolData(const skString& label, bool defaultVal=false) const;
00194   int   findChildIntData(const skString& label, int defaultVal=0) const;
00201   float findChildFloatData(const skString& label, float defaultVal=0.0f) const;
00205   skString nthChildData(USize index) const;
00209   int   nthChildIntData(USize index) const;
00210 #ifdef STREAMS_ENABLED
00211 
00214   void  write(ostream& out,USize tabstops) const;
00215 #endif
00216 
00220   bool  write(const skString& file) const;
00227   skTreeNode *  nthChild(USize  i) const;
00231   USize numChildren() const;
00235   void  copyItems(skTreeNode& node);
00239   void  moveItemsFrom(skTreeNode& node);
00243   void  clear();
00250   static skTreeNode * read(const skString& file,skExecutableContext& ctxt);
00251   friend class skTreeNodeList;
00252   friend class skTreeNodeListIterator;
00253 
00254  private:
00258   skString m_Label;
00262   skString m_Data;
00266   skTreeNodeList * m_Items;
00267 };
00271 class  CLASSEXPORT skTreeNodeReader 
00272 {
00273  public:
00274 #ifdef STREAMS_ENABLED
00275 
00278   skTreeNodeReader(istream& in);
00282   skTreeNodeReader(istream& in,skString  fileName);
00283 #else
00284 
00287   skTreeNodeReader(FILE * in);
00291   skTreeNodeReader(FILE * in,skString  fileName);
00292 #endif
00293 
00296   ~skTreeNodeReader();
00303   skTreeNode* read(skExecutableContext& ctxt);
00304  private:
00305   class P_TreeNodeReader* pimp;
00306 };
00307 
00311 class CLASSEXPORT  skTreeNodeReaderException : public skException
00312 {
00313  public:
00317   skTreeNodeReaderException(const skString& fileName,const skString& msg)
00318     : m_FileName(fileName),m_Msg(msg){
00319   }
00323   skString toString() const{
00324             return m_FileName+skSTR(":")+m_Msg;
00325             }
00326  private:
00327   skString m_FileName;
00328   skString m_Msg;
00329 };
00330 
00331 #endif
00332                         
00333 
00334 
00335 
00336 
00337 
00338 
00339 
00340 

Generated on Mon Dec 16 16:30:12 2002 for Simkin by doxygen1.3-rc1