00001 /* -*- mode: c++; c-basic-offset: 4; -*- */ 00002 #ifndef HTML_COMPOUND_HH 00003 #define HTML_COMPOUND_HH 00004 00005 #include "html/Attrib.hh" 00006 #include "html/object.hh" 00007 #include <list> 00008 00009 namespace html { 00010 00020 class compound : public object { 00021 public: 00025 compound(void); 00026 00033 compound(const compound& x); 00034 00038 virtual ~compound(void); 00039 00045 virtual void write(writer& out) const; 00046 00052 virtual compound* clone(void) const; 00053 00058 virtual const char* getTag(void) const; 00059 00067 object& addObject(const object& thing); 00068 00076 object* addObject(object* thing); 00077 00081 object& back(void); 00082 00087 const object& back(void) const; 00088 00092 object& front(void); 00093 00098 const object& front(void) const; 00099 00102 object& lineBreak(void); 00103 00107 void clear(void); 00108 00113 void remObject(const object* thing); 00114 00121 void addAttr(const std::string& name, const attrib& a); 00122 00126 void clearAttr(void); 00127 00134 void repAttr(const std::string& name, const attrib& a); 00135 00140 void remAttr(const std::string& name); 00141 00142 private: 00143 typedef std::list<object*> HtmlList; 00144 typedef HtmlList::iterator html_iter; 00145 typedef HtmlList::const_iterator const_html_iter; 00146 00147 private: 00148 attList mAttr; 00149 HtmlList mList; 00150 }; 00151 00160 class block : public compound { 00161 public: 00166 block(const std::string& tag) : mTag(tag) {} 00167 00171 virtual ~block(void) {} 00172 00178 virtual block* clone(void) const {return new block(*this);} 00179 00184 const char* getTag(void) const {return mTag.c_str();} 00185 00186 private: 00187 std::string mTag; 00188 }; 00189 00190 } 00191 00192 //====================================== Inline methods. 00193 inline void 00194 html::compound::addAttr(const std::string& name, const attrib& a) { 00195 mAttr.addAttr(name, a); 00196 } 00197 00198 inline html::object* 00199 html::compound::addObject(object* obj) { 00200 mList.push_back(obj); 00201 return obj; 00202 } 00203 00204 inline html::object& 00205 html::compound::addObject(const object& obj) { 00206 return *addObject(obj.clone()); 00207 } 00208 00209 inline html::object& 00210 html::compound::back(void) { 00211 return *mList.back(); 00212 } 00213 00214 inline const html::object& 00215 html::compound::back(void) const { 00216 return *mList.back(); 00217 } 00218 00219 inline html::object& 00220 html::compound::front(void) { 00221 return *mList.front(); 00222 } 00223 00224 inline const html::object& 00225 html::compound::front(void) const { 00226 return *mList.front(); 00227 } 00228 00229 inline void 00230 html::compound::repAttr(const std::string& name, const attrib& a) { 00231 mAttr.repAttr(name, a); 00232 } 00233 00234 inline void 00235 html::compound::remAttr(const std::string& name) { 00236 mAttr.remAttr(name); 00237 } 00238 00239 #endif // HTML_COMPOUND_HH
1.5.4