OSDN Git Service

mock的なシンプルGCの実装を開始。かなり構造が変わっていっているので、自分で意識しておくこと。
[simplecms/utakata.git] / data_structure.h
1 #ifndef _DATA_STRUCTURE_H_
2 #define _DATA_STRUCTURE_H_
3
4 #include "smart_ptr.h"
5
6 namespace utakata {
7
8     namespace type {
9         class TypeDescripter;
10     };
11
12     namespace data {
13
14         class DataSpace
15         {
16             // データ領域を表すだけのクラス。
17             // データ領域の入替などを、このクラス自体への代入で済ますために、
18             // オペレータオーバロードが実装されている。
19         public:
20             DataSpace(const smart_ptr<type::TypeDescripter>& data);
21             DataSpace(const DataSpace& space);
22             virtual ~DataSpace() {}
23
24             DataSpace& operator=(const DataSpace& space);
25             bool operator==(const DataSpace& space);
26             bool operator!=(const DataSpace& space);
27
28             type::TypeDescripter& getTypeDescripter();
29
30         private:
31
32             // データ領域を交換する。
33             void swap(const DataSpace& space);
34
35             // データの実体を保持するTypeDescripterのsmart_ptr
36             smart_ptr<type::TypeDescripter> space_;
37
38         };
39
40         template<typename T>
41         class DataCastor
42         {
43             // 各データ実体へのキャストを行うためのインターフェース。
44             // この関数オブジェクトを利用している限り、DataEntityのインターフェースがどうなっているか
45             // を気にする必要は無い。
46         public:
47             DataCastor() {}
48             virtual ~DataCastor() {}
49
50             const T* operator()(const interpreter::Object& p) {
51                 return static_cast<const T*>(
52                     p.getSpace()->getEntity()->getAddress());
53             }
54         };
55     };
56
57 };
58
59 #endif /* _DATA_STRUCTURE_H_ */