00001 /*************************************************************************** 00002 * Copyright (C) 2004 by Rick L. Vinyard, Jr. * 00003 * rvinyard@cs.nmsu.edu * 00004 * * 00005 * This file is part of the papyrus library. * 00006 * * 00007 * papyrus is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU Lesser General Public License * 00009 * version 3.0 as published by the Free Software Foundation. * 00010 * * 00011 * papyrus is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU Lesser General Public License version 3.0 for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with the papyrus library. If not, see * 00018 * <http://www.gnu.org/licenses/>. * 00019 ***************************************************************************/ 00020 #ifndef PAPYRUSOBJECT_H 00021 #define PAPYRUSOBJECT_H 00022 00023 #include <map> 00024 #include <stdint.h> 00025 #include <glibmm/ustring.h> 00026 #include <sigc++/sigc++.h> 00027 00028 #include <papyrus/pointer.h> 00029 #include <papyrus/utility.h> 00030 00031 namespace Papyrus 00032 { 00033 00034 typedef std::map<Glib::ustring,Glib::ustring> AttributeValueMap; 00035 00044 // TODO find out why this freezes on destruction when it inherits from sigc::trackable 00045 class Object/*: public sigc::trackable*/ 00046 { 00047 protected: 00048 Object ( const Glib::ustring& id=Glib::ustring() ) :m_id ( id ) { } 00049 00050 Object ( const AttributeValueMap& avmap ) { this->set( avmap ); } 00051 00052 public: 00053 virtual ~Object() { } 00054 00055 const Glib::ustring& id() const 00056 { 00057 return m_id; 00058 } 00059 00060 void set_id ( const Glib::ustring& i ) 00061 { 00062 m_id = i; 00063 m_signal_id_changed.emit(); 00064 } 00065 00066 virtual void set( const AttributeValueMap& avmap ) 00067 { 00068 AttributeValueMap::const_iterator i; 00069 00070 i = this->find_attribute( avmap, "id" ); 00071 00072 if ( i != avmap.end() ) this->set_id( i->second ); 00073 } 00074 00075 sigc::signal<void>& signal_changed() 00076 { 00077 return m_signal_changed; 00078 } 00079 00080 sigc::signal<void>& signal_id_changed() 00081 { 00082 return m_signal_id_changed; 00083 } 00084 00085 protected: 00086 Glib::ustring m_id; 00087 00094 AttributeValueMap::const_iterator find_attribute( const AttributeValueMap& avmap, const Glib::ustring& attribute ) 00095 { 00096 AttributeValueMap::const_iterator i; 00097 for ( i = avmap.begin(); i != avmap.end(); i++ ) 00098 if ( strcaseeq( i->first, attribute ) ) return i; 00099 return avmap.end(); 00100 } 00101 00102 sigc::signal<void> m_signal_changed; 00103 sigc::signal<void> m_signal_id_changed; 00104 }; 00105 00106 } 00107 00108 #endif