source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/include/Enum.h@ 828

Last change on this file since 828 was 828, checked in by イグトランス (egtra), 12 years ago

egtraブランチの内容をマージ。

File size: 2.5 KB
Line 
1#pragma once
2
3class EnumMember
4{
5 std::string name;
6 std::string value;
7 int sourceIndex;
8
9public:
10 EnumMember( const std::string &name, const std::string &value, int sourceIndex )
11 : name( name )
12 , value( value )
13 , sourceIndex( sourceIndex )
14 {
15 }
16
17 EnumMember(EnumMember&& y)
18 : name(std::move(y.name))
19 , value(std::move(y.value))
20 , sourceIndex(std::move(y.sourceIndex))
21 {
22 }
23
24 EnumMember(EnumMember const& y)
25 : name(y.name)
26 , value(y.value)
27 , sourceIndex(y.sourceIndex)
28 {
29 }
30
31 EnumMember& operator =(EnumMember&& y)
32 {
33 name = std::move(y.name);
34 value = std::move(y.value);
35 sourceIndex = std::move(y.sourceIndex);
36 return *this;
37 }
38
39 EnumMember& operator =(EnumMember const& y)
40 {
41 return *this = std::move(EnumMember(y));
42 }
43
44 const std::string &GetName() const
45 {
46 return name;
47 }
48 const std::string &GetValueStr() const
49 {
50 return value;
51 }
52 int GetSourceIndex() const
53 {
54 return sourceIndex;
55 }
56};
57
58class EnumInfo
59 : public Symbol
60{
61
62 BOOL bConst;
63
64 std::vector<EnumMember> members;
65public:
66
67 EnumInfo( const NamespaceScopes &namespaceScopes, const std::string &name )
68 : Symbol( namespaceScopes, name )
69 {
70 }
71
72 EnumInfo(EnumInfo&& y)
73 : Symbol(std::move(y))
74 , bConst(std::move(y.bConst))
75 , members(std::move(y.members))
76 {
77 }
78
79 EnumInfo(EnumInfo const& y)
80 : Symbol(y)
81 , bConst(y.bConst)
82 , members(y.members)
83 {
84 }
85
86 EnumInfo& operator =(EnumInfo&& y)
87 {
88 Symbol::operator =(std::move(y));
89 bConst = std::move(y.bConst);
90 members = std::move(y.members);
91 return *this;
92 }
93
94 EnumInfo& operator =(EnumInfo const& y)
95 {
96 return *this = std::move(EnumInfo(y));
97 }
98
99 const std::vector<EnumMember> &GetMembers() const
100 {
101 return members;
102 }
103
104 const EnumMember &GetEnumMember( const std::string &memberName ) const
105 {
106 foreach( const EnumMember &member, members )
107 {
108 if( member.GetName() == memberName )
109 {
110 return member;
111 }
112 }
113 throw;
114 }
115
116 std::vector<EnumMember> &GetEnumMembers()
117 {
118 return members;
119 }
120};
121
122class EnumInfoCollection
123 : public std::vector<EnumInfo>
124{
125public:
126 const EnumInfo *Find( const Symbol &symbol ) const
127 {
128 const EnumInfoCollection &thisEnumInfoCollection = *this;
129 foreach( const EnumInfo &enumInfo, thisEnumInfoCollection )
130 {
131 if( enumInfo.IsEqualSymbol( symbol ) )
132 {
133 return &enumInfo;
134 }
135 }
136 return NULL;
137 };
138
139 EnumInfoCollection() {}
140
141private:
142 EnumInfoCollection(EnumInfoCollection const&);
143 EnumInfoCollection& operator =(EnumInfoCollection const&);
144};
Note: See TracBrowser for help on using the repository browser.