Google
Web alhem.net

ElementList.cpp

Go to the documentation of this file.
00001 #include "ElementList.h"
00002 #include "RefCount.h"
00003 
00004 
00005 namespace Cgi
00006 {
00007 
00008 
00009 ElementList::ElementList(const std::string& tag) : Element(tag)
00010 , m_ref_count( new RefCount() )
00011 {
00012 }
00013 
00014 
00015 ElementList::ElementList(const ElementList& ref) : Element(ref)
00016 , m_ref_count( ref.m_ref_count )
00017 {
00018         for (element_v::const_iterator it = ref.m_elements.begin(); it != ref.m_elements.end(); it++)
00019         {
00020                 Element *p = *it;
00021                 p -> SetParent( this );
00022                 m_elements.push_back( p );
00023         }
00024         m_ref_count -> Increase();
00025 }
00026 
00027 
00028 ElementList::~ElementList()
00029 {
00030         if (!m_ref_count -> Decrease())
00031         {
00032                 for (element_v::const_iterator it = m_elements.begin(); it != m_elements.end(); it++)
00033                 {
00034                         Element *p = *it;
00035                         delete p;
00036                 }
00037                 delete m_ref_count;
00038         }
00039 }
00040 
00041 
00042 void ElementList::Add(Element& el)
00043 {
00044         el.SetParent( this );
00045         m_elements.push_back( el.Copy() );
00046 }
00047 
00048 
00049 std::string ElementList::GetElements() const
00050 {
00051         std::string str;
00052         for (element_v::const_iterator it = m_elements.begin(); it != m_elements.end(); it++)
00053         {
00054                 Element *p = *it;
00055                 std::string tmp = p -> ToString();
00056                 str += tmp;
00057         }
00058         return str;
00059 }
00060 
00061 
00062 std::string ElementList::ToString() const
00063 {
00064         return GetAttributes( GetElementName() ) + GetElements() + "</" + GetElementName() + ">";
00065 }
00066 
00067 
00068 } // namespace Cgi
00069 
00070 

Generated for cgi++ by doxygen 1.3.7

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