1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef ARY_CPP_C_TRAITS_HXX
25 #define ARY_CPP_C_TRAITS_HXX
26
27
28
29 // USED SERVICES
30 // BASE CLASSES
31 // OTHER
32 #include <ary/cpp/c_types4cpp.hxx>
33
34
35
36 namespace ary
37 {
38 namespace symtree
39 {
40 template <class X> class Node;
41 }
42 }
43
44
45
46
47 namespace ary
48 {
49 namespace cpp
50 {
51
52
53 /** Basic traits for derived ones of ->CodeEntity.
54 */
55 struct Ce_Traits
56 {
57 typedef CodeEntity entity_base_type;
58 typedef Ce_id id_type;
59
60 static entity_base_type &
61 EntityOf_(
62 id_type i_id );
63 };
64
65
66 /** An instance of SYMBOL_TRAITS for ->::ary::SortedIds<>.
67
68 @see ::ary::SortedIds<>
69 */
70 struct CeNode_Traits : public Ce_Traits
71 {
72 static const symtree::Node<CeNode_Traits> *
73 NodeOf_(
74 const entity_base_type &
75 i_entity );
76 static symtree::Node<CeNode_Traits> *
77 NodeOf_(
78 entity_base_type & i_entity );
79 static entity_base_type *
80 ParentOf_(
81 const entity_base_type &
82 i_entity );
83 template <class KEY>
84 static id_type Search_(
85 const entity_base_type &
86 i_entity,
87 const KEY & i_localKey );
88 };
89
90
91 /** An instance of COMPARE for ->::ary::SortedIds<>.
92
93 @see ::ary::SortedIds<>
94 */
95 struct Ce_Compare : public Ce_Traits
96 {
97 typedef String key_type;
98
99 static const key_type &
100 KeyOf_(
101 const entity_base_type &
102 i_entity );
103 static bool Lesser_(
104 const key_type & i_1,
105 const key_type & i_2 );
106 };
107
108 /** An instance of COMPARE for ->::ary::SortedIds<>.
109
110 @see ::ary::SortedIds<>
111 */
112 struct Ce_GlobalCompare : public Ce_Traits
113 {
114 typedef entity_base_type key_type;
115
116 static const key_type &
KeyOf_ary::cpp::Ce_GlobalCompare117 KeyOf_(
118 const entity_base_type &
119 i_entity )
120 { return i_entity; }
121 static bool Lesser_(
122 const key_type & i_1,
123 const key_type & i_2 );
124 };
125
126
127 /** Basic traits for derivd ones of ->DefineEntity.
128 */
129 struct Def_Traits
130 {
131 typedef DefineEntity entity_base_type;
132 typedef De_id id_type;
133
134 static entity_base_type &
135 EntityOf_(
136 id_type i_id );
137 };
138
139
140 /** An instance of COMPARE for ->::ary::SortedIds<>.
141
142 @see ::ary::SortedIds<>
143 */
144 struct Def_Compare : public Def_Traits
145 {
146 typedef String key_type;
147
148 static const key_type &
149 KeyOf_(
150 const entity_base_type &
151 i_entity );
152 static bool Lesser_(
153 const key_type & i_1,
154 const key_type & i_2 );
155 };
156
157 /** Basic traits for derivd ones of ->Type.
158 */
159 struct Type_Traits
160 {
161 typedef Type entity_base_type;
162 typedef Type_id id_type;
163
164 static entity_base_type &
165 EntityOf_(
166 id_type i_id );
167 };
168
169 /** An instance of COMPARE for ->::ary::SortedIds<>.
170
171 @see ::ary::SortedIds<>
172 */
173 struct UsedType_Compare : public Type_Traits
174 {
175 typedef UsedType key_type;
176
177 static const key_type &
178 KeyOf_(
179 const entity_base_type &
180 i_entity );
181 static bool Lesser_(
182 const key_type & i_1,
183 const key_type & i_2 );
184 };
185
186
187
188
189
190
191 // IMPLEMENTATION
192
193 /// Implementation helper for ->CeNode_Traits::Search_ .
194 Ce_id CeNode_Search(
195 const CodeEntity & i_entity,
196 const String & i_localKey );
197
198
199 template <class KEY>
200 Ce_Traits::id_type
Search_(const entity_base_type & i_entity,const KEY & i_localKey)201 CeNode_Traits::Search_( const entity_base_type & i_entity,
202 const KEY & i_localKey )
203 {
204 return CeNode_Search(i_entity, i_localKey);
205 }
206
207
208
209
210 } // namespace cpp
211 } // namespace ary
212 #endif
213