Public Types | List of all members
cgicc::HTMLElement Class Referenceabstract

Class representing an HTML element. More...

#include <cgicc/HTMLElement.h>

Inheritance diagram for cgicc::HTMLElement:
cgicc::MStreamable cgicc::HTMLBooleanElement< nullTag > cgicc::HTMLAtomicElement< Tag > cgicc::HTMLBooleanElement< Tag > cgicc::comment

Public Types

enum  EElementType { eAtomic , eBoolean }
 Possible types of HTMLElements. More...
 

Public Member Functions

Constructors and Destructor
 HTMLElement (const HTMLElement &element)
 Copy constructor.
 
virtual ~HTMLElement ()
 Destructor.
 
Overloaded Operators
bool operator== (const HTMLElement &element) const
 Compare two HTMLElements for equality.
 
bool operator!= (const HTMLElement &element) const
 Compare two HTMLElements for inequality.
 
HTMLElementoperator= (const HTMLElement &element)
 Assignment operator.
 
Accessor Methods

Information on the element

virtual const char * getName () const =0
 Get the name of this element.
 
std::string getData () const
 Get the data contained in this element, if any.
 
EElementType getType () const
 Get the type of this element.
 
Mutator Methods

Set properties of the element

void setData (const std::string &data)
 Set the data contained in this element.
 
virtual HTMLElementclone () const =0
 Clone this HTMLElement.
 
Embedded HTMLElement Management

Manage elements embedded in this one

const HTMLElementListgetEmbedded () const
 Get the HTMLElementList embedded in this element, if any.
 
void setEmbedded (const HTMLElementList &embedded)
 Set the HTMLElementList associated with this element.
 
HTMLElementadd (const HTMLElement &element)
 Add an embedded HTMLElement in this one.
 
HTMLElementadd (HTMLElement *element)
 Add an embedded HTMLElement in this one.
 
HTMLAttribute Management

Manage attributes embedded in this element

const HTMLAttributeListgetAttributes () const
 Get the attributes associated with this element.
 
void setAttributes (const HTMLAttributeList &attributes)
 Set the attributes associated with this element.
 
HTMLElementset (const std::string &name)
 Set an HTMLAttribute on this HTMLElement.
 
HTMLElementset (const std::string &name, const std::string &value)
 Set an HTMLAttribute on this HTMLElement.
 
- Public Member Functions inherited from cgicc::MStreamable
 MStreamable ()
 Empty constructor.
 
virtual ~MStreamable ()
 Empty destructor.
 
virtual void render (std::ostream &out) const =0
 Write this object to a stream.

 

Boolean element methods

Methods specific to boolean elements

virtual void swapState () const
 Swap the state of the boolean element.
 
virtual bool getState () const
 Get the state of this boolean element.
 
virtual void render (std::ostream &out) const
 Render this HTMLElement to an ostream.
 
 HTMLElement (const HTMLAttributeList *attributes, const HTMLElement *embedded, const std::string *data, EElementType type)
 Subclass constructor.
 
bool dataSpecified () const
 For subclasses only.
 

Detailed Description

Class representing an HTML element.

An HTML element is any entity enclosed in angle brackets (< and >) interpreted as HTML, for example a, img, html, and body.

This class is an abstract base class that defines the interface for all HTMLElement subclasses.

Definition at line 60 of file HTMLElement.h.

Member Enumeration Documentation

◆ EElementType

Possible types of HTMLElements.

An HTMLElement is either atomic, meaning it has no corresponding closing tag (elements such as hr and br are atomic) or boolean (elements such as a and ol are boolean)

Enumerator
eAtomic 

Atomic element, such as hr

eBoolean 

Boolean element, such as strong

Definition at line 71 of file HTMLElement.h.

Constructor & Destructor Documentation

◆ HTMLElement() [1/2]

cgicc::HTMLElement::HTMLElement ( const HTMLElement element)

Copy constructor.

Sets the name and internal state of this element to those of element

Parameters
elementThe HTMLElement to copy.

◆ ~HTMLElement()

virtual cgicc::HTMLElement::~HTMLElement ( )
virtual

Destructor.

Delete this HTMLElement object

◆ HTMLElement() [2/2]

cgicc::HTMLElement::HTMLElement ( const HTMLAttributeList attributes,
const HTMLElement embedded,
const std::string *  data,
EElementType  type 
)
protected

Subclass constructor.

This allows the subclasses to fully specify all properties

Parameters
attributesA pointer to an HTMLAttributeList containing the HTMLAttributes for this HTMLElement, if any
embeddedA pointer to the embedded HTMLElement, if any
dataA pointer to the data, if any
typeThe type of element

Member Function Documentation

◆ add() [1/2]

HTMLElement & cgicc::HTMLElement::add ( const HTMLElement element)

Add an embedded HTMLElement in this one.

Parameters
elementA reference to an HTMLElement to embed in this one
Returns
A reference to this

◆ add() [2/2]

HTMLElement & cgicc::HTMLElement::add ( HTMLElement element)

Add an embedded HTMLElement in this one.

This element takes ownership of element, which should not be deleted.

Parameters
elementA pointer to an HTMLElement to embed.
Returns
A reference to this

◆ clone()

virtual HTMLElement * cgicc::HTMLElement::clone ( ) const
pure virtual

Clone this HTMLElement.

This performs a deep copy of the element

Returns
A pointer to a newly-allocated copy of this.

Implemented in cgicc::HTMLAtomicElement< Tag >, cgicc::HTMLBooleanElement< Tag >, and cgicc::HTMLBooleanElement< nullTag >.

◆ dataSpecified()

bool cgicc::HTMLElement::dataSpecified ( ) const
inlineprotected

For subclasses only.

Returns true if data was specified in the constructor.

Returns
true if data was specified in the constructor, false otherwise

Definition at line 367 of file HTMLElement.h.

◆ getAttributes()

const HTMLAttributeList * cgicc::HTMLElement::getAttributes ( ) const
inline

Get the attributes associated with this element.

If this method returns 0, no attributes are embedded

Returns
The attribute list.

Definition at line 271 of file HTMLElement.h.

◆ getData()

std::string cgicc::HTMLElement::getData ( ) const
inline

Get the data contained in this element, if any.

This is only applicable for boolean elements

Returns
The data contained in this element.

Definition at line 166 of file HTMLElement.h.

◆ getEmbedded()

const HTMLElementList * cgicc::HTMLElement::getEmbedded ( ) const
inline

Get the HTMLElementList embedded in this element, if any.

If this method returns 0, no elements are embedded

Returns
The embedded element list.

Definition at line 223 of file HTMLElement.h.

◆ getName()

virtual const char * cgicc::HTMLElement::getName ( ) const
pure virtual

Get the name of this element.

For example, html or body.

Returns
The name of this element.

Implemented in cgicc::HTMLAtomicElement< Tag >, cgicc::HTMLBooleanElement< Tag >, and cgicc::HTMLBooleanElement< nullTag >.

◆ getState()

virtual bool cgicc::HTMLElement::getState ( ) const
inlinevirtual

Get the state of this boolean element.

Returns
true if the element is active, false otherwise

Reimplemented in cgicc::HTMLBooleanElement< Tag >, and cgicc::HTMLBooleanElement< nullTag >.

Definition at line 330 of file HTMLElement.h.

◆ getType()

EElementType cgicc::HTMLElement::getType ( ) const
inline

Get the type of this element.

Most HTMLElements are boolean

Returns
The type of this element

Definition at line 176 of file HTMLElement.h.

◆ operator!=()

bool cgicc::HTMLElement::operator!= ( const HTMLElement element) const
inline

Compare two HTMLElements for inequality.

HTMLElements are equal if they have the same name

Parameters
elementThe HTMLElement to compare to this one.
Returns
false if the two HTMLElements are equal, true otherwise.

Definition at line 122 of file HTMLElement.h.

◆ operator=()

HTMLElement & cgicc::HTMLElement::operator= ( const HTMLElement element)

Assignment operator.

Sets the name and internal state of this element to those of element

Parameters
elementThe HTMLElement to copy
Returns
A reference to this

◆ operator==()

bool cgicc::HTMLElement::operator== ( const HTMLElement element) const

Compare two HTMLElements for equality.

HTMLElements are equal if they have the same name

Parameters
elementThe HTMLElement to compare to this one.
Returns
true if the two HTMLElements are equal, false otherwise.

◆ render()

virtual void cgicc::HTMLElement::render ( std::ostream &  out) const
virtual

Render this HTMLElement to an ostream.

This is used for output

Parameters
outThe ostream to which to write

Implements cgicc::MStreamable.

◆ set() [1/2]

HTMLElement & cgicc::HTMLElement::set ( const std::string &  name)

Set an HTMLAttribute on this HTMLElement.

Parameters
nameThe name of the HTMLAttribute to set
Returns
A reference to this

◆ set() [2/2]

HTMLElement & cgicc::HTMLElement::set ( const std::string &  name,
const std::string &  value 
)

Set an HTMLAttribute on this HTMLElement.

Parameters
nameThe name of the HTMLAttribute
valueThe value of the HTMLAttribute
Returns
A reference to this

◆ setAttributes()

void cgicc::HTMLElement::setAttributes ( const HTMLAttributeList attributes)

Set the attributes associated with this element.

This is usually called by subclass constructors

Parameters
attributesThe HTMLAttributeList containing the HTMLAttributes belonging to this element.

◆ setData()

void cgicc::HTMLElement::setData ( const std::string &  data)
inline

Set the data contained in this element.

The data is the text contained between the opening and closing tags

Parameters
dataThe data to store in this element.

Definition at line 194 of file HTMLElement.h.

◆ setEmbedded()

void cgicc::HTMLElement::setEmbedded ( const HTMLElementList embedded)

Set the HTMLElementList associated with this element.

This is usually called by subclass constructors

Parameters
embeddedThe HTMLElementList containing the HTMLElements embedded in this element.

◆ swapState()

virtual void cgicc::HTMLElement::swapState ( ) const
inlinevirtual

Swap the state of the boolean element.

A state of true means the element is active

Reimplemented in cgicc::HTMLBooleanElement< Tag >, and cgicc::HTMLBooleanElement< nullTag >.

Definition at line 320 of file HTMLElement.h.


The documentation for this class was generated from the following file:

GNU cgicc - A C++ class library for writing CGI applications
Copyright © 1996 - 2004 Stephen F. Booth
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front Cover Texts, and with no Back-Cover Texts.
Documentation generated Fri Mar 1 2024 08:39:42 for cgicc by doxygen 1.9.6