1*d291ea28SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*d291ea28SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*d291ea28SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*d291ea28SAndrew Rist * distributed with this work for additional information
6*d291ea28SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*d291ea28SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*d291ea28SAndrew Rist * "License"); you may not use this file except in compliance
9*d291ea28SAndrew Rist * with the License. You may obtain a copy of the License at
10*d291ea28SAndrew Rist *
11*d291ea28SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*d291ea28SAndrew Rist *
13*d291ea28SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*d291ea28SAndrew Rist * software distributed under the License is distributed on an
15*d291ea28SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d291ea28SAndrew Rist * KIND, either express or implied. See the License for the
17*d291ea28SAndrew Rist * specific language governing permissions and limitations
18*d291ea28SAndrew Rist * under the License.
19*d291ea28SAndrew Rist *
20*d291ea28SAndrew Rist *************************************************************/
21cdf0e10cSrcweir
22cdf0e10cSrcweir #include <precomp.h>
23cdf0e10cSrcweir #include <ary/cpp/c_namesp.hxx>
24cdf0e10cSrcweir
25cdf0e10cSrcweir
26cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES
27cdf0e10cSrcweir #include <algorithm>
28cdf0e10cSrcweir #include <cosv/tpl/tpltools.hxx>
29cdf0e10cSrcweir #include <ary/cpp/c_funct.hxx>
30cdf0e10cSrcweir #include <ary/cpp/c_gate.hxx>
31cdf0e10cSrcweir #include <ary/getncast.hxx>
32cdf0e10cSrcweir #include <slots.hxx>
33cdf0e10cSrcweir #include "c_slots.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir
36cdf0e10cSrcweir namespace ary
37cdf0e10cSrcweir {
38cdf0e10cSrcweir namespace cpp
39cdf0e10cSrcweir {
40cdf0e10cSrcweir
41cdf0e10cSrcweir typedef std::multimap<String, Ce_id>::const_iterator operations_citer;
42cdf0e10cSrcweir
Namespace()43cdf0e10cSrcweir Namespace::Namespace()
44cdf0e10cSrcweir : aEssentials(),
45cdf0e10cSrcweir aAssignedNode(),
46cdf0e10cSrcweir // aLocalNamespaces,
47cdf0e10cSrcweir // aLocalClasses,
48cdf0e10cSrcweir // aLocalEnums,
49cdf0e10cSrcweir // aLocalTypedefs,
50cdf0e10cSrcweir // aLocalOperations,
51cdf0e10cSrcweir // aLocalVariables,
52cdf0e10cSrcweir // aLocalConstants,
53cdf0e10cSrcweir pParent(0),
54cdf0e10cSrcweir nDepth(0)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir aAssignedNode.Assign_Entity(*this);
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
Namespace(const String & i_sLocalName,Namespace & i_rParent)59cdf0e10cSrcweir Namespace::Namespace( const String & i_sLocalName,
60cdf0e10cSrcweir Namespace & i_rParent )
61cdf0e10cSrcweir : aEssentials( i_sLocalName,
62cdf0e10cSrcweir i_rParent.CeId(),
63cdf0e10cSrcweir Lid(0) ),
64cdf0e10cSrcweir aAssignedNode(),
65cdf0e10cSrcweir // aLocalNamespaces,
66cdf0e10cSrcweir // aLocalClasses,
67cdf0e10cSrcweir // aLocalEnums,
68cdf0e10cSrcweir // aLocalTypedefs,
69cdf0e10cSrcweir // aLocalOperations,
70cdf0e10cSrcweir // aLocalVariables,
71cdf0e10cSrcweir // aLocalConstants,
72cdf0e10cSrcweir pParent(&i_rParent),
73cdf0e10cSrcweir nDepth(i_rParent.Depth()+1)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir aAssignedNode.Assign_Entity(*this);
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
~Namespace()78cdf0e10cSrcweir Namespace::~Namespace()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir void
Add_LocalNamespace(DYN Namespace & io_rLocalNamespace)83cdf0e10cSrcweir Namespace::Add_LocalNamespace( DYN Namespace & io_rLocalNamespace )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir aLocalNamespaces[io_rLocalNamespace.LocalName()] = &io_rLocalNamespace;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir void
Add_LocalClass(const String & i_sLocalName,Cid i_nId)89cdf0e10cSrcweir Namespace::Add_LocalClass( const String & i_sLocalName,
90cdf0e10cSrcweir Cid i_nId )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir aLocalClasses[i_sLocalName] = i_nId;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir void
Add_LocalEnum(const String & i_sLocalName,Cid i_nId)96cdf0e10cSrcweir Namespace::Add_LocalEnum( const String & i_sLocalName,
97cdf0e10cSrcweir Cid i_nId )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir aLocalEnums[i_sLocalName] = i_nId;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir void
Add_LocalTypedef(const String & i_sLocalName,Cid i_nId)103cdf0e10cSrcweir Namespace::Add_LocalTypedef( const String & i_sLocalName,
104cdf0e10cSrcweir Cid i_nId )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir aLocalTypedefs[i_sLocalName] = i_nId;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir void
Add_LocalOperation(const String & i_sLocalName,Cid i_nId)110cdf0e10cSrcweir Namespace::Add_LocalOperation( const String & i_sLocalName,
111cdf0e10cSrcweir Cid i_nId )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir aLocalOperations.insert( Map_Operations::value_type(i_sLocalName, i_nId) );
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
116cdf0e10cSrcweir
117cdf0e10cSrcweir void
Add_LocalVariable(const String & i_sLocalName,Cid i_nId)118cdf0e10cSrcweir Namespace::Add_LocalVariable( const String & i_sLocalName,
119cdf0e10cSrcweir Cid i_nId )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir aLocalVariables[i_sLocalName] = i_nId;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir void
Add_LocalConstant(const String & i_sLocalName,Cid i_nId)125cdf0e10cSrcweir Namespace::Add_LocalConstant( const String & i_sLocalName,
126cdf0e10cSrcweir Cid i_nId )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir aLocalConstants[i_sLocalName] = i_nId;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir uintt
Depth() const132cdf0e10cSrcweir Namespace::Depth() const
133cdf0e10cSrcweir {
134cdf0e10cSrcweir return nDepth;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir Namespace *
Parent() const138cdf0e10cSrcweir Namespace::Parent() const
139cdf0e10cSrcweir {
140cdf0e10cSrcweir return pParent;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
143cdf0e10cSrcweir Ce_id
Search_Child(const String & i_key) const144cdf0e10cSrcweir Namespace::Search_Child(const String & i_key) const
145cdf0e10cSrcweir {
146cdf0e10cSrcweir Namespace *
147cdf0e10cSrcweir ret_nsp = Search_LocalNamespace(i_key);
148cdf0e10cSrcweir if (ret_nsp != 0)
149cdf0e10cSrcweir return ret_nsp->CeId();
150cdf0e10cSrcweir
151cdf0e10cSrcweir Ce_id
152cdf0e10cSrcweir ret = Search_LocalClass(i_key);
153cdf0e10cSrcweir if (ret.IsValid())
154cdf0e10cSrcweir return ret;
155cdf0e10cSrcweir
156cdf0e10cSrcweir ret = csv::value_from_map(aLocalEnums, i_key, Ce_id(0));
157cdf0e10cSrcweir if (ret.IsValid())
158cdf0e10cSrcweir return ret;
159cdf0e10cSrcweir ret = csv::value_from_map(aLocalTypedefs, i_key, Ce_id(0));
160cdf0e10cSrcweir if (ret.IsValid())
161cdf0e10cSrcweir return ret;
162cdf0e10cSrcweir ret = csv::value_from_map(aLocalVariables, i_key, Ce_id(0));
163cdf0e10cSrcweir if (ret.IsValid())
164cdf0e10cSrcweir return ret;
165cdf0e10cSrcweir return csv::value_from_map(aLocalConstants, i_key, Ce_id(0));
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
168cdf0e10cSrcweir Namespace *
Search_LocalNamespace(const String & i_sLocalName) const169cdf0e10cSrcweir Namespace::Search_LocalNamespace( const String & i_sLocalName ) const
170cdf0e10cSrcweir {
171cdf0e10cSrcweir return csv::value_from_map(aLocalNamespaces, i_sLocalName, (Namespace*)(0));
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
174cdf0e10cSrcweir uintt
Get_SubNamespaces(std::vector<const Namespace * > & o_rResultList) const175cdf0e10cSrcweir Namespace::Get_SubNamespaces( std::vector< const Namespace* > & o_rResultList ) const
176cdf0e10cSrcweir {
177cdf0e10cSrcweir for ( Map_NamespacePtr::const_iterator it = aLocalNamespaces.begin();
178cdf0e10cSrcweir it != aLocalNamespaces.end();
179cdf0e10cSrcweir ++it )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir o_rResultList.push_back( (*it).second );
182cdf0e10cSrcweir }
183cdf0e10cSrcweir return o_rResultList.size();
184cdf0e10cSrcweir }
185cdf0e10cSrcweir
186cdf0e10cSrcweir Ce_id
Search_LocalClass(const String & i_sName) const187cdf0e10cSrcweir Namespace::Search_LocalClass( const String & i_sName ) const
188cdf0e10cSrcweir {
189cdf0e10cSrcweir return csv::value_from_map(aLocalClasses, i_sName, Ce_id(0));
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir void
Search_LocalOperations(std::vector<Ce_id> & o_result,const String & i_sName) const193cdf0e10cSrcweir Namespace::Search_LocalOperations( std::vector<Ce_id> & o_result,
194cdf0e10cSrcweir const String & i_sName ) const
195cdf0e10cSrcweir {
196cdf0e10cSrcweir operations_citer
197cdf0e10cSrcweir itLower = aLocalOperations.lower_bound(i_sName);
198cdf0e10cSrcweir if (itLower == aLocalOperations.end())
199cdf0e10cSrcweir return;
200cdf0e10cSrcweir if ( (*itLower).first != i_sName )
201cdf0e10cSrcweir return;
202cdf0e10cSrcweir
203cdf0e10cSrcweir operations_citer
204cdf0e10cSrcweir itEnd = aLocalOperations.end();
205cdf0e10cSrcweir for ( operations_citer it = itLower;
206cdf0e10cSrcweir it != aLocalOperations.end() ? (*itLower).first == i_sName : false;
207cdf0e10cSrcweir ++it )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir o_result.push_back((*it).second);
210cdf0e10cSrcweir }
211cdf0e10cSrcweir }
212cdf0e10cSrcweir
213cdf0e10cSrcweir
214cdf0e10cSrcweir const String &
inq_LocalName() const215cdf0e10cSrcweir Namespace::inq_LocalName() const
216cdf0e10cSrcweir {
217cdf0e10cSrcweir return aEssentials.LocalName();
218cdf0e10cSrcweir }
219cdf0e10cSrcweir
220cdf0e10cSrcweir Cid
inq_Owner() const221cdf0e10cSrcweir Namespace::inq_Owner() const
222cdf0e10cSrcweir {
223cdf0e10cSrcweir return aEssentials.Owner();
224cdf0e10cSrcweir }
225cdf0e10cSrcweir
226cdf0e10cSrcweir Lid
inq_Location() const227cdf0e10cSrcweir Namespace::inq_Location() const
228cdf0e10cSrcweir {
229cdf0e10cSrcweir return Lid(0);
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
232cdf0e10cSrcweir void
do_Accept(csv::ProcessorIfc & io_processor) const233cdf0e10cSrcweir Namespace::do_Accept(csv::ProcessorIfc & io_processor) const
234cdf0e10cSrcweir {
235cdf0e10cSrcweir csv::CheckedCall(io_processor,*this);
236cdf0e10cSrcweir }
237cdf0e10cSrcweir
238cdf0e10cSrcweir ClassId
get_AryClass() const239cdf0e10cSrcweir Namespace::get_AryClass() const
240cdf0e10cSrcweir {
241cdf0e10cSrcweir return class_id;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir Gid
inq_Id_Group() const245cdf0e10cSrcweir Namespace::inq_Id_Group() const
246cdf0e10cSrcweir {
247cdf0e10cSrcweir return static_cast<Gid>(Id());
248cdf0e10cSrcweir }
249cdf0e10cSrcweir
250cdf0e10cSrcweir const ary::cpp::CppEntity &
inq_RE_Group() const251cdf0e10cSrcweir Namespace::inq_RE_Group() const
252cdf0e10cSrcweir {
253cdf0e10cSrcweir return *this;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir
256cdf0e10cSrcweir const ary::group::SlotList &
inq_Slots() const257cdf0e10cSrcweir Namespace::inq_Slots() const
258cdf0e10cSrcweir {
259cdf0e10cSrcweir static const SlotAccessId aProjectSlotData[]
260cdf0e10cSrcweir = { SLOT_SubNamespaces, SLOT_Classes, SLOT_Enums, SLOT_Typedefs, SLOT_Operations,
261cdf0e10cSrcweir SLOT_Variables, SLOT_Constants };
262cdf0e10cSrcweir static const std::vector< SlotAccessId >
263cdf0e10cSrcweir aSlots( &aProjectSlotData[0],
264cdf0e10cSrcweir &aProjectSlotData[0]
265cdf0e10cSrcweir + sizeof aProjectSlotData / sizeof (SlotAccessId) );
266cdf0e10cSrcweir return aSlots;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir
269cdf0e10cSrcweir DYN Slot *
inq_Create_Slot(SlotAccessId i_nSlot) const270cdf0e10cSrcweir Namespace::inq_Create_Slot( SlotAccessId i_nSlot ) const
271cdf0e10cSrcweir {
272cdf0e10cSrcweir switch ( i_nSlot )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir case SLOT_SubNamespaces: return new Slot_SubNamespaces(aLocalNamespaces);
275cdf0e10cSrcweir case SLOT_Classes: return new Slot_MapLocalCe(aLocalClasses);
276cdf0e10cSrcweir case SLOT_Enums: return new Slot_MapLocalCe(aLocalEnums);
277cdf0e10cSrcweir case SLOT_Typedefs: return new Slot_MapLocalCe(aLocalTypedefs);
278cdf0e10cSrcweir case SLOT_Operations: return new Slot_MapOperations(aLocalOperations);
279cdf0e10cSrcweir case SLOT_Variables: return new Slot_MapLocalCe(aLocalVariables);
280cdf0e10cSrcweir case SLOT_Constants: return new Slot_MapLocalCe(aLocalConstants);
281cdf0e10cSrcweir default:
282cdf0e10cSrcweir return new Slot_Null;
283cdf0e10cSrcweir } // end switch
284cdf0e10cSrcweir }
285cdf0e10cSrcweir
286cdf0e10cSrcweir
287cdf0e10cSrcweir } // namespace cpp
288cdf0e10cSrcweir } // namespace ary
289