Google
Web alhem.net

Element.cpp

Go to the documentation of this file.
00001 #include "Element.h"
00002 #include "Class.h"
00003 
00004 
00005 namespace Cgi
00006 {
00007 
00008 
00009 Element::Element(const std::string& tag)
00010 : m_tag(tag)
00011 , m_parent(NULL)
00012 , m_class(NULL)
00013 {
00014 }
00015 
00016 
00017 Element::~Element()
00018 {
00019 }
00020 
00021 
00022 void Element::SetClass(Class *cl)
00023 {
00024         m_class = cl;
00025 }
00026 
00027 
00028 Class *Element::GetClass() const
00029 {
00030         return m_class;
00031 }
00032 
00033 
00034 void Element::SetId(const std::string& id)
00035 {
00036         m_id = id;
00037 }
00038 
00039 
00040 const std::string& Element::GetId() const
00041 {
00042         return m_id;
00043 }
00044 
00045 
00046 void Element::SetStyle(const std::string& style)
00047 {
00048         m_style = style;
00049 }
00050 
00051 
00052 const std::string& Element::GetStyle() const
00053 {
00054         return m_style;
00055 }
00056 
00057 
00058 void Element::SetParent(Element *parent)
00059 {
00060         m_parent = parent;
00061 }
00062 
00063 
00064 Element *Element::GetParent() const
00065 {
00066         return m_parent;
00067 }
00068 
00069 
00070 std::string Element::GetAttributes(const std::string& tag) const
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 }
00103 
00104 
00105 void Element::SetAttribute(const std::string& key, const std::string& value)
00106 {
00107         m_attrs[key] = value;
00108 }
00109 
00110 
00111 const std::string& Element::GetAttribute(const std::string& key)
00112 {
00113         if (m_attrs.find(key) != m_attrs.end())
00114         {
00115                 return m_attrs[key];
00116         }
00117         return m_temporary;
00118 }
00119 
00120 
00121 void Element::SetContent(const std::string& content)
00122 {
00123         m_content = content;
00124 }
00125 
00126 
00127 const std::string& Element::GetContent() const
00128 {
00129         return m_content;
00130 }
00131 
00132 
00133 std::string Element::ToString() const
00134 {
00135         return GetAttributes( GetElementName() ) + GetContent() + "</" + GetElementName() + ">";
00136 }
00137 
00138 
00139 doctype_t Element::GetDoctype()
00140 {
00141         return m_parent -> GetDoctype();
00142 }
00143 
00144 
00145 const std::string& Element::GetElementName() const
00146 {
00147         return m_tag;
00148 }
00149 
00150 
00151 } // namespace Cgi

Generated for cgi++ by doxygen 1.3.7

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