xref: /AOO41X/main/autodoc/source/ary/cpp/c_namesp.cxx (revision d291ea287686f95dc2fff9ad28612d818a1c6b1e)
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 #include <precomp.h>
23 #include <ary/cpp/c_namesp.hxx>
24 
25 
26 // NOT FULLY DECLARED SERVICES
27 #include <algorithm>
28 #include <cosv/tpl/tpltools.hxx>
29 #include <ary/cpp/c_funct.hxx>
30 #include <ary/cpp/c_gate.hxx>
31 #include <ary/getncast.hxx>
32 #include <slots.hxx>
33 #include "c_slots.hxx"
34 
35 
36 namespace ary
37 {
38 namespace cpp
39 {
40 
41 typedef std::multimap<String, Ce_id>::const_iterator      operations_citer;
42 
Namespace()43 Namespace::Namespace()
44     :   aEssentials(),
45         aAssignedNode(),
46         // aLocalNamespaces,
47         // aLocalClasses,
48         // aLocalEnums,
49         // aLocalTypedefs,
50         // aLocalOperations,
51         // aLocalVariables,
52         // aLocalConstants,
53         pParent(0),
54         nDepth(0)
55 {
56     aAssignedNode.Assign_Entity(*this);
57 }
58 
Namespace(const String & i_sLocalName,Namespace & i_rParent)59 Namespace::Namespace( const String  &     i_sLocalName,
60                       Namespace &         i_rParent )
61     :   aEssentials( i_sLocalName,
62                      i_rParent.CeId(),
63                      Lid(0) ),
64         aAssignedNode(),
65         // aLocalNamespaces,
66         // aLocalClasses,
67         // aLocalEnums,
68         // aLocalTypedefs,
69         // aLocalOperations,
70         // aLocalVariables,
71         // aLocalConstants,
72         pParent(&i_rParent),
73         nDepth(i_rParent.Depth()+1)
74 {
75     aAssignedNode.Assign_Entity(*this);
76 }
77 
~Namespace()78 Namespace::~Namespace()
79 {
80 }
81 
82 void
Add_LocalNamespace(DYN Namespace & io_rLocalNamespace)83 Namespace::Add_LocalNamespace( DYN Namespace & io_rLocalNamespace )
84 {
85     aLocalNamespaces[io_rLocalNamespace.LocalName()] = &io_rLocalNamespace;
86 }
87 
88 void
Add_LocalClass(const String & i_sLocalName,Cid i_nId)89 Namespace::Add_LocalClass( const String  &     i_sLocalName,
90                            Cid                 i_nId )
91 {
92     aLocalClasses[i_sLocalName] = i_nId;
93 }
94 
95 void
Add_LocalEnum(const String & i_sLocalName,Cid i_nId)96 Namespace::Add_LocalEnum( const String  &     i_sLocalName,
97                           Cid                 i_nId )
98 {
99     aLocalEnums[i_sLocalName] = i_nId;
100 }
101 
102 void
Add_LocalTypedef(const String & i_sLocalName,Cid i_nId)103 Namespace::Add_LocalTypedef( const String  &     i_sLocalName,
104                              Cid                 i_nId )
105 {
106     aLocalTypedefs[i_sLocalName] = i_nId;
107 }
108 
109 void
Add_LocalOperation(const String & i_sLocalName,Cid i_nId)110 Namespace::Add_LocalOperation( const String  &     i_sLocalName,
111                                Cid                 i_nId )
112 {
113     aLocalOperations.insert( Map_Operations::value_type(i_sLocalName, i_nId) );
114 }
115 
116 
117 void
Add_LocalVariable(const String & i_sLocalName,Cid i_nId)118 Namespace::Add_LocalVariable( const String  &     i_sLocalName,
119                               Cid                 i_nId )
120 {
121     aLocalVariables[i_sLocalName] = i_nId;
122 }
123 
124 void
Add_LocalConstant(const String & i_sLocalName,Cid i_nId)125 Namespace::Add_LocalConstant( const String  &     i_sLocalName,
126                               Cid                 i_nId )
127 {
128     aLocalConstants[i_sLocalName] = i_nId;
129 }
130 
131 uintt
Depth() const132 Namespace::Depth() const
133 {
134     return nDepth;
135 }
136 
137 Namespace *
Parent() const138 Namespace::Parent() const
139 {
140     return pParent;
141 }
142 
143 Ce_id
Search_Child(const String & i_key) const144 Namespace::Search_Child(const String & i_key) const
145 {
146     Namespace *
147         ret_nsp = Search_LocalNamespace(i_key);
148     if (ret_nsp != 0)
149         return ret_nsp->CeId();
150 
151     Ce_id
152         ret = Search_LocalClass(i_key);
153     if (ret.IsValid())
154         return ret;
155 
156     ret = csv::value_from_map(aLocalEnums, i_key, Ce_id(0));
157     if (ret.IsValid())
158         return ret;
159     ret = csv::value_from_map(aLocalTypedefs, i_key, Ce_id(0));
160     if (ret.IsValid())
161         return ret;
162     ret = csv::value_from_map(aLocalVariables, i_key, Ce_id(0));
163     if (ret.IsValid())
164         return ret;
165     return csv::value_from_map(aLocalConstants, i_key, Ce_id(0));
166 }
167 
168 Namespace *
Search_LocalNamespace(const String & i_sLocalName) const169 Namespace::Search_LocalNamespace( const String  & i_sLocalName ) const
170 {
171     return csv::value_from_map(aLocalNamespaces, i_sLocalName, (Namespace*)(0));
172 }
173 
174 uintt
Get_SubNamespaces(std::vector<const Namespace * > & o_rResultList) const175 Namespace::Get_SubNamespaces( std::vector< const Namespace* > & o_rResultList ) const
176 {
177     for ( Map_NamespacePtr::const_iterator it = aLocalNamespaces.begin();
178           it != aLocalNamespaces.end();
179           ++it )
180     {
181         o_rResultList.push_back( (*it).second );
182     }
183     return o_rResultList.size();
184 }
185 
186 Ce_id
Search_LocalClass(const String & i_sName) const187 Namespace::Search_LocalClass( const String  & i_sName ) const
188 {
189     return csv::value_from_map(aLocalClasses, i_sName, Ce_id(0));
190 }
191 
192 void
Search_LocalOperations(std::vector<Ce_id> & o_result,const String & i_sName) const193 Namespace::Search_LocalOperations( std::vector<Ce_id> & o_result,
194                                    const String &       i_sName ) const
195 {
196     operations_citer
197         itLower = aLocalOperations.lower_bound(i_sName);
198     if (itLower == aLocalOperations.end())
199         return;
200     if ( (*itLower).first != i_sName )
201         return;
202 
203     operations_citer
204         itEnd = aLocalOperations.end();
205     for ( operations_citer it = itLower;
206           it != aLocalOperations.end() ? (*itLower).first == i_sName : false;
207           ++it )
208     {
209         o_result.push_back((*it).second);
210     }
211 }
212 
213 
214 const String  &
inq_LocalName() const215 Namespace::inq_LocalName() const
216 {
217     return aEssentials.LocalName();
218 }
219 
220 Cid
inq_Owner() const221 Namespace::inq_Owner() const
222 {
223     return aEssentials.Owner();
224 }
225 
226 Lid
inq_Location() const227 Namespace::inq_Location() const
228 {
229     return Lid(0);
230 }
231 
232 void
do_Accept(csv::ProcessorIfc & io_processor) const233 Namespace::do_Accept(csv::ProcessorIfc & io_processor) const
234 {
235     csv::CheckedCall(io_processor,*this);
236 }
237 
238 ClassId
get_AryClass() const239 Namespace::get_AryClass() const
240 {
241     return class_id;
242 }
243 
244 Gid
inq_Id_Group() const245 Namespace::inq_Id_Group() const
246 {
247     return static_cast<Gid>(Id());
248 }
249 
250 const ary::cpp::CppEntity &
inq_RE_Group() const251 Namespace::inq_RE_Group() const
252 {
253     return *this;
254 }
255 
256 const ary::group::SlotList &
inq_Slots() const257 Namespace::inq_Slots() const
258 {
259     static const SlotAccessId aProjectSlotData[]
260             = { SLOT_SubNamespaces, SLOT_Classes, SLOT_Enums, SLOT_Typedefs, SLOT_Operations,
261                 SLOT_Variables, SLOT_Constants };
262     static const std::vector< SlotAccessId >
263             aSlots( &aProjectSlotData[0],
264                       &aProjectSlotData[0]
265                         + sizeof aProjectSlotData / sizeof (SlotAccessId) );
266     return aSlots;
267 }
268 
269 DYN Slot *
inq_Create_Slot(SlotAccessId i_nSlot) const270 Namespace::inq_Create_Slot( SlotAccessId i_nSlot ) const
271 {
272     switch ( i_nSlot )
273     {
274         case SLOT_SubNamespaces:    return new Slot_SubNamespaces(aLocalNamespaces);
275         case SLOT_Classes:          return new Slot_MapLocalCe(aLocalClasses);
276         case SLOT_Enums:            return new Slot_MapLocalCe(aLocalEnums);
277         case SLOT_Typedefs:         return new Slot_MapLocalCe(aLocalTypedefs);
278         case SLOT_Operations:       return new Slot_MapOperations(aLocalOperations);
279         case SLOT_Variables:        return new Slot_MapLocalCe(aLocalVariables);
280         case SLOT_Constants:        return new Slot_MapLocalCe(aLocalConstants);
281         default:
282                                     return new Slot_Null;
283     }   // end switch
284 }
285 
286 
287 }   // namespace cpp
288 }   // namespace ary
289