00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef INC_SOFU_LIST_H
00018 #define INC_SOFU_LIST_H
00019
00020 #include "main.h"
00021 #include "object.h"
00022
00023 namespace Sofu
00024 {
00025 class Value;
00026 class Composite;
00027
00028 class List : public Object
00029 {
00030 private:
00031 vector<Object*> elems;
00032 public:
00033 List(void);
00034 List(const List& cpy);
00035 ~List(void);
00036
00037 class iterator;
00038
00039 iterator begin(void);
00040 iterator end(void);
00041
00042 unsigned int size(void);
00043 Object*& at(int pos);
00044 Value* value(int pos);
00045 List* list(int pos);
00046 Composite* composite(int pos);
00047
00048 void push_back(Object* obj);
00049
00050 class iterator
00051 {
00052 private:
00053 friend class List;
00054 vector<Object*>::iterator itor;
00055 iterator(vector<Object*>::iterator iitor);
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) const;
00066 iterator operator-(int steps) const;
00067 iterator& operator+=(int steps);
00068 iterator& operator-=(int steps);
00069 iterator& operator++(void);
00070 iterator& operator--(void);
00071
00072 Object* operator*(void);
00073 Value* value(void);
00074 List* list(void);
00075 Composite* composite(void);
00076 };
00077 };
00078
00079 struct Exc_WrongListElemType : public Exc
00080 {
00081 int elemNum;
00082 string assumedType;
00083
00084 Exc_WrongListElemType(const string& iassumedType)
00085 : elemNum(-1), assumedType(iassumedType)
00086 {
00087 ostringstream oss;
00088 oss << "Tried to treat a list element as a "
00089 << assumedType << ", which it is not.";
00090 message = oss.str();
00091 }
00092
00093 Exc_WrongListElemType(int ielemNum, const string& iassumedType)
00094 : elemNum(ielemNum), assumedType(iassumedType)
00095 {
00096 ostringstream oss;
00097 oss << "Tried to treat list element number " << elemNum << " as a "
00098 << assumedType << ", which it is not.";
00099 message = oss.str();
00100 }
00101
00102 };
00103 }
00104
00105 #endif // INC_LIST_H