00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef INC_SOFU_COMPOSITE_H
00018 #define INC_SOFU_COMPOSITE_H
00019
00020 #include "main.h"
00021 #include "object.h"
00022
00023 namespace Sofu
00024 {
00025 class Value;
00026 class List;
00027
00028 class Composite : public Object
00029 {
00030 private:
00031 map<string, Object*> properties;
00032 public:
00033 Composite(void);
00034 Composite(const Composite& cpy);
00035 ~Composite(void);
00036
00037 Object*& operator[](const string& propname);
00038 Object* object(const string& propname);
00039 Value* value(const string& propname);
00040 List* list(const string& propname);
00041 Composite* composite(const string& propname);
00042
00043 void set(const string& propname, Object* ivalue);
00044
00045 class iterator;
00046 iterator begin(void);
00047 iterator end(void);
00048
00049 class iterator
00050 {
00051 private:
00052 friend class Composite;
00053 map<string, Object*>::iterator itor;
00054 iterator(map<string, Object*>::iterator iitor, Composite* icomp);
00055 Composite* comp;
00056 public:
00057 iterator(void);
00058 ~iterator(void);
00059
00060 iterator& operator=(iterator& rhs);
00061
00062 bool operator==(const iterator& rhs) const;
00063 bool operator!=(const iterator& rhs) const;
00064
00065 iterator& operator+=(int steps);
00066 iterator& operator-=(int steps);
00067 iterator& operator++(void);
00068 iterator& operator--(void);
00069
00070 pair<string, Object*> operator*(void);
00071 Object* object(void);
00072 Value* value(void);
00073 List* list(void);
00074 Composite* composite(void);
00075
00076 string name(void);
00077 void set(Object* ivalue);
00078 };
00079 };
00080
00084 struct Exc_WrongPropertyType : public Exc
00085 {
00086 string propertyName;
00087 string assumedType;
00088
00089 Exc_WrongPropertyType(const string& ipropertyName,
00090 const string& iassumedType)
00091 : Exc(string("Tried to treat property ") + ipropertyName
00092 + string(" as a ") + iassumedType + string(", which it is not.")),
00093 propertyName(ipropertyName), assumedType(iassumedType)
00094 { }
00095 };
00096
00097 struct Exc_UnassignedIterator : public Exc
00098 {
00099 Exc_UnassignedIterator(void)
00100 : Exc("Tried to use an iterator which is currently not assigned to"
00101 "point to something")
00102 { }
00103 };
00104 }
00105
00106 #endif // INC_COMPOSITE_H