papyrus logo

object.h

Go to the documentation of this file.
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   class Object: public sigc::trackable
00045   {
00046     protected:
00047       Object ( const Glib::ustring& id=Glib::ustring() ) :m_id ( id ) { }
00048 
00049       Object ( const AttributeValueMap& avmap ) { this->set( avmap ); }
00050 
00051     public:
00052       virtual ~Object() { }
00053 
00054       const Glib::ustring& id() const
00055       {
00056         return m_id;
00057       }
00058 
00059       void set_id ( const Glib::ustring& i )
00060       {
00061         m_id = i;
00062         m_signal_id_changed.emit();
00063       }
00064 
00065       virtual void set( const AttributeValueMap& avmap )
00066       {
00067         AttributeValueMap::const_iterator i;
00068 
00069         i = this->find_attribute( avmap, "id" );
00070 
00071         if ( i != avmap.end() ) this->set_id( i->second );
00072       }
00073 
00074       sigc::signal<void>& signal_changed()
00075       {
00076         return m_signal_changed;
00077       }
00078 
00079       sigc::signal<void>& signal_id_changed()
00080       {
00081         return m_signal_id_changed;
00082       }
00083 
00084     protected:
00085       Glib::ustring m_id;
00086 
00093       AttributeValueMap::const_iterator find_attribute( const AttributeValueMap& avmap, const Glib::ustring& attribute )
00094       {
00095         AttributeValueMap::const_iterator i;
00096         for ( i = avmap.begin(); i != avmap.end(); i++ )
00097           if ( strcaseeq( i->first, attribute ) ) return i;
00098         return avmap.end();
00099       }
00100 
00101       sigc::signal<void> m_signal_changed;
00102       sigc::signal<void> m_signal_id_changed;
00103   };
00104 
00105 }
00106 
00107 #endif

Generated on Fri Apr 16 12:40:10 2010 for papyrus by doxygen 1.6.1