HTMLElement.h
Go to the documentation of this file.
1/* -*-mode:c++; c-file-style: "gnu";-*- */
2/*
3 * $Id: HTMLElement.h,v 1.9 2014/04/23 20:55:06 sebdiaz Exp $
4 *
5 * Copyright (C) 1996 - 2004 Stephen F. Booth <sbooth@gnu.org>
6 * 2007 Sebastien DIAZ <sebastien.diaz@gmail.com>
7 * Part of the GNU cgicc library, http://www.gnu.org/software/cgicc
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 3 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
22 */
23
24#ifndef _HTMLELEMENT_H_
25#define _HTMLELEMENT_H_ 1
26
27#ifdef __GNUG__
28# pragma interface
29#endif
30
37#include <string>
38
39#include "CgiDefs.h"
40#include "MStreamable.h"
41#include "HTMLAttributeList.h"
42
43 namespace cgicc {
44
45 class HTMLElementList;
46
47 // ============================================================
48 // Class HTMLElement
49 // ============================================================
50
60 class CGICC_API HTMLElement : public MStreamable
61 {
62 public:
63
71 enum EElementType {
73 eAtomic,
75 eBoolean
76 };
77
78 // ============================================================
79
82
89 HTMLElement(const HTMLElement& element);
90
96 virtual ~HTMLElement();
98
99 // ============================================================
100
103
111 bool
112 operator== (const HTMLElement& element) const;
113
121 inline bool
122 operator!= (const HTMLElement& element) const
123 { return ! operator==(element); }
124
125#ifdef WIN32
126 /* Dummy operator for MSVC++ */
127 inline bool
128 operator< (const HTMLElement& element) const
129 { return false; }
130#endif
131
139 HTMLElement&
140 operator= (const HTMLElement& element);
142
143 // ============================================================
144
149
156 virtual const char*
157 getName() const = 0;
158
165 inline std::string
166 getData() const
167 { return fData; }
168
175 inline EElementType
176 getType() const
177 { return fType; }
179
180 // ============================================================
181
186
193 inline void
194 setData(const std::string& data)
195 { fData = data; }
197
198 // ============================================================
199
206 virtual HTMLElement*
207 clone() const = 0;
208
209 // ============================================================
210
215
222 inline const HTMLElementList*
223 getEmbedded() const
224 { return fEmbedded; }
225
233 void
234 setEmbedded(const HTMLElementList& embedded);
235
243 HTMLElement&
244 add(const HTMLElement& element);
245
253 HTMLElement&
254 add(HTMLElement *element);
256
257 // ============================================================
258
263
270 inline const HTMLAttributeList*
271 getAttributes() const
272 { return fAttributes; }
273
281 void
282 setAttributes(const HTMLAttributeList& attributes);
283
291 HTMLElement&
292 set(const std::string& name);
293
302 HTMLElement&
303 set(const std::string& name,
304 const std::string& value);
306
307 // ============================================================
308
313
319 virtual void
320 swapState() const
321 {}
322
329 virtual bool
330 getState() const
331 { return false; }
333
340 virtual void
341 render(std::ostream& out) const;
342
343 protected:
344
355 HTMLElement(const HTMLAttributeList *attributes,
356 const HTMLElement *embedded,
357 const std::string *data,
358 EElementType type);
359
366 inline bool
367 dataSpecified() const
368 { return fDataSpecified; }
369
370 private:
371 HTMLElement() {}
372
373 HTMLAttributeList *fAttributes;
374 HTMLElementList *fEmbedded;
375 std::string fData;
376 EElementType fType;
377 bool fDataSpecified;
378 };
379
380} // namespace cgicc
381
382#endif /* ! _HTMLELEMENT_H_ */
CgiDefs.h
Platform and operating system specific macro definitions.
HTMLAttributeList.h
Class containing a list of HTMLAttribute objects.
MStreamable.h
Abstract base class for all streamable objects.
cgicc::HTMLAttributeList
An expandable list of HTMLAttribute objects.
Definition: HTMLAttributeList.h:70
cgicc::HTMLElementList
An expandable list of HTMLElement objects.
Definition: HTMLElementList.h:68
cgicc::HTMLElement
Class representing an HTML element.
Definition: HTMLElement.h:61
cgicc::HTMLElement::set
HTMLElement & set(const std::string &name)
Set an HTMLAttribute on this HTMLElement.
cgicc::HTMLElement::swapState
virtual void swapState() const
Swap the state of the boolean element.
Definition: HTMLElement.h:320
cgicc::HTMLElement::add
HTMLElement & add(const HTMLElement &element)
Add an embedded HTMLElement in this one.
cgicc::HTMLElement::EElementType
EElementType
Possible types of HTMLElements.
Definition: HTMLElement.h:71
cgicc::HTMLElement::eAtomic
@ eAtomic
Definition: HTMLElement.h:73
cgicc::HTMLElement::HTMLElement
HTMLElement(const HTMLElement &element)
Copy constructor.
cgicc::HTMLElement::getType
EElementType getType() const
Get the type of this element.
Definition: HTMLElement.h:176
cgicc::HTMLElement::setData
void setData(const std::string &data)
Set the data contained in this element.
Definition: HTMLElement.h:194
cgicc::HTMLElement::getData
std::string getData() const
Get the data contained in this element, if any.
Definition: HTMLElement.h:166
cgicc::HTMLElement::~HTMLElement
virtual ~HTMLElement()
Destructor.
cgicc::HTMLElement::getName
virtual const char * getName() const =0
Get the name of this element.
cgicc::HTMLElement::set
HTMLElement & set(const std::string &name, const std::string &value)
Set an HTMLAttribute on this HTMLElement.
cgicc::HTMLElement::setAttributes
void setAttributes(const HTMLAttributeList &attributes)
Set the attributes associated with this element.
cgicc::HTMLElement::clone
virtual HTMLElement * clone() const =0
Clone this HTMLElement.
cgicc::HTMLElement::getState
virtual bool getState() const
Get the state of this boolean element.
Definition: HTMLElement.h:330
cgicc::HTMLElement::getAttributes
const HTMLAttributeList * getAttributes() const
Get the attributes associated with this element.
Definition: HTMLElement.h:271
cgicc::HTMLElement::add
HTMLElement & add(HTMLElement *element)
Add an embedded HTMLElement in this one.
cgicc::HTMLElement::getEmbedded
const HTMLElementList * getEmbedded() const
Get the HTMLElementList embedded in this element, if any.
Definition: HTMLElement.h:223
cgicc::HTMLElement::dataSpecified
bool dataSpecified() const
For subclasses only.
Definition: HTMLElement.h:367
cgicc::HTMLElement::HTMLElement
HTMLElement(const HTMLAttributeList *attributes, const HTMLElement *embedded, const std::string *data, EElementType type)
Subclass constructor.
cgicc::HTMLElement::render
virtual void render(std::ostream &out) const
Render this HTMLElement to an ostream.
cgicc::HTMLElement::setEmbedded
void setEmbedded(const HTMLElementList &embedded)
Set the HTMLElementList associated with this element.
cgicc::MStreamable
Mix-in streamable interface.
Definition: MStreamable.h:67
cgicc
The namespace containing the cgicc library.
Definition: Cgicc.h:52