00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef IDIOSKOPOSOBJECT_H
00021 #define IDIOSKOPOSOBJECT_H
00022
00023 #include <string>
00024 #include <set>
00025 #include <iostream>
00026 #include <sstream>
00027 #include <iterator>
00028 #include <sigc++/sigc++.h>
00029 #include <libxml++/libxml++.h>
00030 #include <typeinfo>
00031
00032 #include <idioskopos/pointer.h>
00033 #include <idioskopos/error.h>
00034
00035 #define IDIOSKOPOS_OBJECT(idioskopos_name) \
00036 virtual const Glib::ustring& class_name() const { \
00037 static Glib::ustring s = (#idioskopos_name); \
00038 return (s); \
00039 }
00040
00065 namespace Idioskopos
00066 {
00067
00068 class Introspectable;
00069
00082 class Object: public virtual sigc::trackable
00083 {
00084 public:
00085 typedef IdioskoposPointer<Object> pointer;
00086 typedef std::set<Object*> Objects;
00087
00089 class iterator {
00090 public:
00091 iterator();
00092 iterator( Object* container, std::set<Object*>::iterator iter );
00093 iterator( Object* container, Object::pointer containee, size_t index );
00094
00095 iterator& operator++();
00096 iterator& operator--();
00097 iterator operator++(int);
00098 iterator operator--(int);
00099 Object* operator->();
00100 Object& operator*();
00101 bool operator==(const iterator& other) const;
00102 bool operator!=(const iterator& other) const;
00103
00104 protected:
00105
00106 typedef enum TYPE {
00107 NONE,
00108 SET_ITERATOR,
00109 INDEX,
00110 } TYPE;
00111
00112 TYPE m_type;
00113 Object* m_container;
00114 std::set<Object*>::iterator m_set_iterator;
00115 Object::pointer m_containee;
00116 size_t m_index;
00117 };
00118
00119 IDIOSKOPOS_OBJECT(Object);
00120
00121 Object(const Glib::ustring& name,
00122 sigc::slot<void> slot=sigc::slot<void>() );
00123
00128 Object(const Glib::ustring& name,
00129 Introspectable& container,
00130 sigc::slot<void> slot=sigc::slot<void>());
00131
00132 virtual ~Object();
00133
00134 const Glib::ustring& name();
00135
00136 void set_name(const Glib::ustring& n);
00137
00142 virtual sigc::signal<void, Object*> signal_property_added();
00143
00148 virtual sigc::signal<void, Object*> signal_property_removed();
00149
00150 sigc::signal<void,const Glib::ustring&> signal_name_changed();
00151
00155 sigc::signal<void>& signal_value_changed();
00156
00160 virtual const std::type_info& type() const = 0;
00161
00166 virtual Glib::ustring xml(int indent=-1) = 0;
00167
00168 virtual void set_xml(const Glib::ustring& s, bool change_names=false, bool create_missing=true);
00169
00170 virtual void set_xml(const xmlpp::Node* n, bool change_names=false, bool create_missing=true);
00171
00176 virtual Glib::ustring value();
00177
00178 virtual void set_value( const Glib::ustring& v );
00179
00180 template <typename T>
00181 void set_value( const T& t )
00182 {
00183 std::ostringstream sout;
00184 Glib::ustring s;
00185 sout << t;
00186 s = sout.str();
00187 this->set_value(s);
00188 }
00189
00195 virtual size_t num_properties() const;
00196
00197 virtual iterator properties_begin();
00198
00199 virtual iterator properties_end();
00200
00208 virtual Object& operator[](const Glib::ustring& name) throw(error::bad_property_name);
00209
00210 protected:
00211 Glib::ustring m_name;
00212
00213 sigc::signal<void, const Glib::ustring&> m_signal_name_changed;
00214
00218 sigc::signal<void> m_signal_value_changed;
00219
00220 virtual iterator next_property(std::set<Object*>::iterator i);
00221
00222 virtual iterator previous_property(std::set<Object*>::iterator i);
00223
00224 virtual iterator next_property(size_t i);
00225
00226 virtual iterator previous_property(size_t i);
00227
00228 };
00229
00230 }
00231
00232 #include <idioskopos/factory.h>
00233
00234 #endif