00001 /******************************************************************************* 00002 * Copyright (c) 2006 International Business Machines Corporation 00003 * All rights reserved. This program and the accompanying materials 00004 * are made available under the terms of the Common Public License v1.0 00005 * which accompanies this distribution, and is available at 00006 * http://www.opensource.org/licenses/cpl1.0.php 00007 * 00008 * Contributors: 00009 * Douglas Sprague, Joel Wheeler - initial API and implementation 00010 * 00011 *****************************************************************************/ 00012 00013 00014 #ifndef STILBlock_H 00015 #define STILBlock_H 00016 00017 #include "stilcomstr.h" 00018 #include <list> // ANSI C++ STL list class 00019 00020 #include "stilcom.h" // Common include 00021 #include "stilentity.h" // Common STIL base class for most STIL classes 00022 00023 // At one point, the iterator & const iterator classes were contained in this 00024 // .h file. I've broken them out now, but instead of adding 00025 // "#include stilblockiterator.h" everywhere, for now I'll just put these includes 00026 // here. At some point, remove them and update the rest of the code that uses 00027 // iterators... 00028 #include "stilblockiterator.h" 00029 #include "stilblockconstiterator.h" 00030 00031 // Following inline function will prevent errors when compiling the 00032 // template code for the STL lists of the pointers to STILEntities 00033 // This is needed because the compiler does not know how to ignore 00034 // delete when called on pointers with one level of indirection too much 00035 //inline void destroy(STILEntity**) { } 00036 00037 00038 // Integer value to place in the linenumber field 00039 // of a STILEntity object when it's derived class 00040 // contents are not copied correctly. 00041 //const LONG STILBLOCK_BAD_COPY (-99); 00042 // SWIG doesnt seem to like 'const'- change to #define: 00043 #define STILBLOCK_BAD_COPY -99 00044 00045 class STILBlockIterator; // Prototype of iterator class 00046 class STILBlockConstIterator; // Prototype of iterator class 00047 00048 //--------------------------------------------------------------------------- 00062 //--------------------------------------------------------------------------- 00063 class STILBlock : public STILEntity { 00064 00065 00066 // - Make iterator class a friend for access to 00067 friend class STILBlockIterator; 00068 friend class STILBlockConstIterator; 00069 00070 // - Public members 00071 public: 00072 00073 typedef STILBlockIterator Iterator; 00074 typedef STILBlockConstIterator ConstIterator; 00075 00076 // - Default Constructor 00077 STILBlock(); 00078 00079 // - Construct given a Type 00080 STILBlock(Type); 00081 00082 // - Copy Constructor 00083 STILBlock(const STILBlock &); 00084 00085 // - Destructor 00086 virtual ~STILBlock(); 00087 00088 // - Assignment Operator 00089 STILBlock & operator=(const STILBlock &); 00090 00091 // - Equality Operator 00092 bool operator==(const STILBlock &) const; 00093 00094 // - Less Than Operator 00095 bool operator<(const STILBlock &) const; 00096 00097 // - Initialize this STILBlock object specifying the type. 00098 void init(Type t); 00099 00100 // - Clear out this block of any stored up entities. 00101 void clear(); 00102 00103 // - Write out Header to a given FILE 00104 virtual void write(FILE * pOutFile, LONG indentation=0) const; 00105 00106 // - Get an iterator to iterate over all entities in this block 00107 Iterator iterator(); 00108 00109 // - Get a const iterator to iterate over all entities in this block 00110 ConstIterator constIterator() const; 00111 00112 // - Add a UserKeywords entry 00113 void addUserKeywords(const sstring & keyword, 00114 const sstring & label = "", 00115 LONG linenumber = 0, 00116 const sstring & filename = "" ); 00117 00118 // - Add an Annotation 00119 void addAnn(const sstring & ann, 00120 LONG linenumber = 0, 00121 const sstring & filename = "" ); 00122 00123 // - Add a STILEntity to the entity order list 00124 void addEntity(STILEntity &); 00125 void addEntity(Type t, 00126 const sstring & name, 00127 const sstring & value, 00128 const sstring & label="", 00129 LONG linenumber = 0, 00130 const sstring & filename = "" ); 00131 00132 // - Add/Get a UserStatement entry 00133 //const sstring & getUserStatement(const sstring & keyword) const; 00134 void addUserStatement(const sstring & keyword, 00135 const sstring & value, 00136 const sstring & label = "", 00137 LONG linenumber = 0, 00138 const sstring & filename = "" ); 00139 00140 // - Add/Get a UserBlock 00141 //const sstring & getUserBlock(const sstring & keyword) const; 00142 void addUserBlock(const sstring & keyword, 00143 const sstring & value, 00144 const sstring & label = "", 00145 LONG linenumber = 0, 00146 const sstring & filename = "" ); 00147 00148 // Protected members (accessable to derived classes) 00149 protected: 00150 00151 //----------------------- protected members ------------------------------ 00152 // Ordered list of entities in this block. This list is just a list of 00153 // pointers to the ordered set of entities. The simple entities are 00154 // actually stored in the next list declared in this class 00155 // "simple_entity_list". The complex entities are stored in the 00156 // derived class which contains them. 00157 std::list<STILEntity *> m_entityList; 00158 00159 // List of simple entities which are allocated by calls to the 00160 // addEntity member functions which has the simple entity data elements. 00161 // NOTE: Complex entities are actually stored in the derived class 00162 // which contains them 00163 std::list<STILEntity> m_simpleEntityList; 00164 00165 // List of entity objects for which a copy at the base class level 00166 // has occured so entries were put into this list (and pointed to by 00167 // the regular list of entity pointers) which have the linenumber field 00168 // marked to indicate as objects which currently have a bad copy 00169 std::list<STILEntity> m_badCopyEntityList; 00170 00171 00172 }; // end STILBlock class 00173 00174 //----------------------------- inline functions ----------------------------- 00175 //-------------------------------------------------------------------------- 00187 //-------------------------------------------------------------------------- 00188 inline void STILBlock::addUserStatement(const sstring & k, 00189 const sstring & v, 00190 const sstring & l, 00191 LONG ln, 00192 const sstring & fn) { 00193 addEntity(UserStatement,k,v,l,ln,fn); 00194 } 00195 00196 //-------------------------------------------------------------------------- 00208 //-------------------------------------------------------------------------- 00209 inline void STILBlock::addUserKeywords(const sstring & k, 00210 const sstring & l, 00211 LONG ln, 00212 const sstring & fn) { 00213 addEntity(UserKeywords,"UserKeywords",k,l,ln,fn); 00214 } 00215 00216 //-------------------------------------------------------------------------- 00228 //-------------------------------------------------------------------------- 00229 inline void STILBlock::addUserBlock(const sstring & k, 00230 const sstring & v, 00231 const sstring & l, 00232 LONG ln, 00233 const sstring & fn) { 00234 addEntity(UserBlock,k,v,l,ln,fn); 00235 } 00236 00237 //-------------------------------------------------------------------------- 00247 //-------------------------------------------------------------------------- 00248 inline void STILBlock::addAnn(const sstring & ann, 00249 LONG ln, 00250 const sstring & fn) { 00251 addEntity(Ann,"Ann",ann,"",ln,fn); 00252 } 00253 00254 00255 00256 00257 00258 #endif