OSDN Git Service

全体の環境を表すenvironmentの追加。
[simplecms/utakata.git] / datum_id.h
1 #ifndef _DATUM_ID_H_
2 #define _DATUM_ID_H_
3
4 // datumで示される構文データの各ID
5
6 namespace utakata {
7
8     namespace syntax {
9
10         class DatumID
11         {
12         public:
13             enum private_DATUMID_ {
14                 STRING,               // <string>
15                 ABBREVIATIONS,        // 各abbrev prefix
16                 SYMBOL,               // <symbol>
17                 NUMBER,               // <number>
18                 CHARACTOR,            // <charactor>
19                 BOOLEAN,              // <boolean>
20                 BYTEVECTOR,           // <bytevector>
21                 VECTOR,               // <vector>
22                 LIST,                 // <list>
23                 LITERAL,              // <lexeme datum>
24                 NIL,
25             };
26
27         private:
28
29             typedef private_DATUMID_ DATUMID_;
30             DATUMID_ S_;
31
32             template<DATUMID_> class Literal;
33
34         public:
35
36             template<DATUMID_ S>
37             DatumID(const Literal<S>&) : S_(S) {}
38
39             DATUMID_ toEnum() const {return S_;}
40
41             friend bool operator==(DatumID s, DatumID t) {return s.S_ == t.S_;}
42             friend bool operator!=(DatumID s, DatumID t) {return !(s == t);}
43
44             static const Literal<STRING>           string;
45             static const Literal<ABBREVIATIONS>    abbreviations;
46             static const Literal<SYMBOL>           symbol;
47             static const Literal<NUMBER>           number;
48             static const Literal<CHARACTOR>        charactor;
49             static const Literal<BOOLEAN>          boolean;
50             static const Literal<BYTEVECTOR>       byteVector;
51             static const Literal<VECTOR>           vector;
52             static const Literal<LIST>             list;
53             static const Literal<LITERAL>       literal;
54             static const Literal<NIL>              nil;
55         };
56
57         // 内部クラスかつ、単に該当するEnumを返すだけのクラステンプレート
58         template<DatumID::private_DATUMID_ S>
59         class DatumID::Literal : private DatumID
60         {
61         public:
62
63             DatumID::private_DATUMID_ toEnum() const {return S;}
64
65         private:
66
67             friend class DatumID;
68             // 暗黙的なコピーコンストラクタを利用する。
69             Literal() : DatumID(*this) {}
70             ~Literal() {}
71
72             void* operator new(size_t);
73             void operator delete(void*);
74             void operator=(const Literal&);
75             void* operator&() const;
76         };
77
78     };
79
80 };
81
82 #endif /* _DATUM_ID_H_ */