From: stephan b. <sg...@us...> - 2004-12-28 04:14:47
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14606/src/s11n Added Files: S11nNode.cpp S11nNode.h Log Message: egg. A proof-of-concept data node type which subclasses SimplePropertyStore. Acts as SIO's concrete data node impl. --- NEW FILE: S11nNode.h --- #ifndef s11n_S11NNODE_HPP_INCLUDED #define s11n_S11NNODE_HPP_INCLUDED 1 #include <list> #include <string> #include <pclasses/Util/SimplePropertyStore.h> #include <pclasses/s11n/traits.h> namespace P { namespace SIO { class S11nNode : public ::P::Util::SimplePropertyStore { public: typedef ::P::Util::SimplePropertyStore ParentType; typedef ParentType::map_type map_type; typedef map_type::key_type key; typedef map_type::value_type value; typedef map_type::mapped_type mapped; typedef map_type::iterator iterator; typedef map_type::const_iterator const_iterator; typedef std::list<S11nNode *> child_list_type; S11nNode(); explicit S11nNode( const std::string & name ); virtual ~S11nNode(); S11nNode( const S11nNode & ); S11nNode & operator=( const S11nNode & ); child_list_type & children(); const child_list_type & children() const; std::string name() const; void name( const std::string & n ); void class_name( const std::string & n ); std::string class_name() const; void clear(); // WTF doesn't gcc see the inherited clear() without this??? iterator S11nNode::begin(); const_iterator S11nNode::begin() const; iterator S11nNode::end(); const_iterator S11nNode::end() const; protected: void copy( const S11nNode & rhs ); void clear_properties(); void clear_children(); std::string m_name; // name of this node std::string m_iname; // class_name name of this node child_list_type m_children; // holds child pointers }; } } // namespace P::SIO #endif // s11n_S11NNODE_HPP_INCLUDED --- NEW FILE: S11nNode.cpp --- #include "S11nNode.h" #include "functor.h" // object_deleter, child_pointer_deep_copier namespace P { namespace SIO { #define NODE_CLASS_NAME "S11nNode" #define NODE_DEFAULT_NAME "S11nNode" S11nNode::S11nNode() : ::P::Util::SimplePropertyStore(), m_name(NODE_DEFAULT_NAME), m_iname(NODE_CLASS_NAME) { } S11nNode::S11nNode( const std::string & name ) : ::P::Util::SimplePropertyStore(), m_name(NODE_DEFAULT_NAME), m_iname(NODE_CLASS_NAME) { } S11nNode::S11nNode( const S11nNode &rhs ) { if( &rhs == this ) return; this->copy( rhs ); } S11nNode::~S11nNode() { this->clear(); } S11nNode & S11nNode::operator=( const S11nNode & rhs ) { if( &rhs == this ) return *this; this->copy( rhs ); return *this; } S11nNode::child_list_type & S11nNode::children() { return this->m_children; } const S11nNode::child_list_type & S11nNode::children() const { return this->m_children; } void S11nNode::copy( const S11nNode & rhs ) { if ( &rhs == this ) return; this->clear(); this->name( rhs.name() ); this->class_name( rhs.class_name() ); std::copy( rhs.begin(), rhs.end(), std::insert_iterator<map_type>( this->getMap(), this->getMap().begin() ) ); std::for_each( rhs.children().begin(), rhs.children().end(), ::P::s11n::child_pointer_deep_copier<child_list_type>( this->children() ) ); } void S11nNode::clear() { this->clear_children(); this->clear_properties(); } void S11nNode::class_name( const std::string & n ) { this->m_iname = n; } std::string S11nNode::class_name()const { return this->m_iname; } void S11nNode::name( const std::string & n ) { this->m_name = n; } std::string S11nNode::name() const { return this->m_name; } void S11nNode::clear_properties() { if ( getMap().empty() ) return; getMap().erase( getMap().begin(), getMap().end() ); } void S11nNode::clear_children() { std::for_each( this->children().begin(), this->children().end(), ::P::s11n::object_deleter() ); this->children().clear(); } S11nNode::iterator S11nNode::begin() { return this->getMap().begin(); } S11nNode::const_iterator S11nNode::begin() const { return this->getMap().begin(); } S11nNode::iterator S11nNode::end() { return this->getMap().end(); } S11nNode::const_iterator S11nNode::end() const { return this->getMap().end(); } }} // P::SIO |