Google
Web alhem.net

Cgi::Element Class Reference

#include <Element.h>

Inheritance diagram for Cgi::Element:

Inheritance graph
Collaboration diagram for Cgi::Element:

Collaboration graph
List of all members.

Public Member Functions

 Element (const std::string &tag)
virtual ~Element ()
virtual std::string ToString () const
 Generate full tag including content and closing tag.
virtual void SetClass (Class *cl)
ClassGetClass () const
virtual void SetId (const std::string &id)
const std::string & GetId () const
virtual void SetStyle (const std::string &style)
const std::string & GetStyle () const
virtual void SetParent (Element *parent)
ElementGetParent () const
virtual ElementCopy ()=0
std::string GetAttributes (const std::string &tag="") const
 Get class, id, style, and other attributes.
const std::string & GetElementName () const
void SetAttribute (const std::string &key, const std::string &value)
const std::string & GetAttribute (const std::string &key)
void SetContent (const std::string &content)
const std::string & GetContent () const
virtual doctype_t GetDoctype ()
 Get Document type from HtmlDocument.

Private Attributes

std::string m_tag
 element name
Elementm_parent
Classm_class
std::string m_id
std::string m_style
attrmap_t m_attrs
std::string m_content
std::string m_temporary

Detailed Description

Definition at line 25 of file Element.h.


Constructor & Destructor Documentation

Cgi::Element::Element ( const std::string &  tag  ) 

Definition at line 9 of file Element.cpp.

00010 : m_tag(tag)
00011 , m_parent(NULL)
00012 , m_class(NULL)
00013 {
00014 }

Cgi::Element::~Element (  )  [virtual]

Definition at line 17 of file Element.cpp.

00018 {
00019 }


Member Function Documentation

std::string Cgi::Element::ToString (  )  const [virtual]

Generate full tag including content and closing tag.

Reimplemented in Cgi::ElementList, and Cgi::HtmlDocument.

Definition at line 133 of file Element.cpp.

References GetAttributes(), GetContent(), and GetElementName().

00134 {
00135         return GetAttributes( GetElementName() ) + GetContent() + "</" + GetElementName() + ">";
00136 }

void Cgi::Element::SetClass ( Class cl  )  [virtual]

Definition at line 22 of file Element.cpp.

References m_class.

00023 {
00024         m_class = cl;
00025 }

Class * Cgi::Element::GetClass (  )  const

Definition at line 28 of file Element.cpp.

References m_class.

00029 {
00030         return m_class;
00031 }

void Cgi::Element::SetId ( const std::string &  id  )  [virtual]

Definition at line 34 of file Element.cpp.

References m_id.

00035 {
00036         m_id = id;
00037 }

const std::string & Cgi::Element::GetId (  )  const

Definition at line 40 of file Element.cpp.

References m_id.

00041 {
00042         return m_id;
00043 }

void Cgi::Element::SetStyle ( const std::string &  style  )  [virtual]

Definition at line 46 of file Element.cpp.

References m_style.

00047 {
00048         m_style = style;
00049 }

const std::string & Cgi::Element::GetStyle (  )  const

Definition at line 52 of file Element.cpp.

References m_style.

00053 {
00054         return m_style;
00055 }

void Cgi::Element::SetParent ( Element parent  )  [virtual]

Definition at line 58 of file Element.cpp.

References m_parent.

Referenced by Cgi::ElementList::Add(), and Cgi::ElementList::ElementList().

00059 {
00060         m_parent = parent;
00061 }

Element * Cgi::Element::GetParent (  )  const

Definition at line 64 of file Element.cpp.

References m_parent.

00065 {
00066         return m_parent;
00067 }

virtual Element* Cgi::Element::Copy (  )  [pure virtual]

Implemented in Cgi::Body, Cgi::Head, Cgi::HtmlDocument, Cgi::Style, and Cgi::Title.

Referenced by Cgi::ElementList::Add().

std::string Cgi::Element::GetAttributes ( const std::string &  tag = ""  )  const

Get class, id, style, and other attributes.

Parameters:
tag Element name

Definition at line 70 of file Element.cpp.

References m_attrs, m_class, m_id, and m_style.

Referenced by Cgi::ElementList::ToString(), and ToString().

00071 {
00072         std::string r;
00073         if (tag.size())
00074         {
00075                 r += "<" + tag;
00076         }
00077         if (m_class)
00078         {
00079                 // %! htmlsafestr ( m_class -> GetName() )
00080                 r += " class='" + m_class -> GetName() + "'";
00081         }
00082         if (m_id.size())
00083         {
00084                 // %! htmlsafestr ( m_id )
00085                 r += " id='" + m_id + "'";
00086         }
00087         if (m_style.size())
00088         {
00089                 // %! htmlsafestr ( m_style )
00090                 r += " style='" + m_style + "'";
00091         }
00092         for (attrmap_t::const_iterator it = m_attrs.begin(); it != m_attrs.end(); it++)
00093         {
00094                 // %! htmlsafestr ( it -> second )
00095                 r += " " + it -> first + "='" + it -> second + "'";
00096         }
00097         if (tag.size())
00098         {
00099                 r += ">";
00100         }
00101         return r;
00102 }

const std::string & Cgi::Element::GetElementName (  )  const

Definition at line 145 of file Element.cpp.

References m_tag.

Referenced by Cgi::ElementList::ToString(), and ToString().

00146 {
00147         return m_tag;
00148 }

void Cgi::Element::SetAttribute ( const std::string &  key,
const std::string &  value 
)

Definition at line 105 of file Element.cpp.

References m_attrs.

Referenced by Cgi::Style::SetType().

00106 {
00107         m_attrs[key] = value;
00108 }

const std::string & Cgi::Element::GetAttribute ( const std::string &  key  ) 

Definition at line 111 of file Element.cpp.

References m_attrs, and m_temporary.

Referenced by Cgi::Style::GetType().

00112 {
00113         if (m_attrs.find(key) != m_attrs.end())
00114         {
00115                 return m_attrs[key];
00116         }
00117         return m_temporary;
00118 }

void Cgi::Element::SetContent ( const std::string &  content  ) 

Definition at line 121 of file Element.cpp.

References m_content.

Referenced by Cgi::Title::SetTitle(), Cgi::Style::Style(), and Cgi::Title::Title().

00122 {
00123         m_content = content;
00124 }

const std::string & Cgi::Element::GetContent (  )  const

Definition at line 127 of file Element.cpp.

References m_content.

Referenced by Cgi::Title::GetTitle(), and ToString().

00128 {
00129         return m_content;
00130 }

doctype_t Cgi::Element::GetDoctype (  )  [virtual]

Get Document type from HtmlDocument.

Reimplemented in Cgi::HtmlDocument.

Definition at line 139 of file Element.cpp.

References m_parent.

00140 {
00141         return m_parent -> GetDoctype();
00142 }


Member Data Documentation

std::string Cgi::Element::m_tag [private]

element name

Definition at line 64 of file Element.h.

Referenced by GetElementName().

Element* Cgi::Element::m_parent [private]

Definition at line 65 of file Element.h.

Referenced by GetDoctype(), GetParent(), and SetParent().

Class* Cgi::Element::m_class [private]

Definition at line 66 of file Element.h.

Referenced by GetAttributes(), GetClass(), and SetClass().

std::string Cgi::Element::m_id [private]

Definition at line 67 of file Element.h.

Referenced by GetAttributes(), GetId(), and SetId().

std::string Cgi::Element::m_style [private]

Definition at line 68 of file Element.h.

Referenced by GetAttributes(), GetStyle(), and SetStyle().

attrmap_t Cgi::Element::m_attrs [private]

Definition at line 69 of file Element.h.

Referenced by GetAttribute(), GetAttributes(), and SetAttribute().

std::string Cgi::Element::m_content [private]

Definition at line 70 of file Element.h.

Referenced by GetContent(), and SetContent().

std::string Cgi::Element::m_temporary [private]

Definition at line 71 of file Element.h.

Referenced by GetAttribute().


The documentation for this class was generated from the following files:
Generated for cgi++ by doxygen 1.3.7

Page, code, and content Copyright (C) 2004 by Anders Hedström