xref: /aoo41x/main/autodoc/source/ary/cpp/c_namesp.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <precomp.h>
29 #include <ary/cpp/c_namesp.hxx>
30 
31 
32 // NOT FULLY DECLARED SERVICES
33 #include <algorithm>
34 #include <cosv/tpl/tpltools.hxx>
35 #include <ary/cpp/c_funct.hxx>
36 #include <ary/cpp/c_gate.hxx>
37 #include <ary/getncast.hxx>
38 #include <slots.hxx>
39 #include "c_slots.hxx"
40 
41 
42 namespace ary
43 {
44 namespace cpp
45 {
46 
47 typedef std::multimap<String, Ce_id>::const_iterator      operations_citer;
48 
49 Namespace::Namespace()
50 	:   aEssentials(),
51         aAssignedNode(),
52 		// aLocalNamespaces,
53 		// aLocalClasses,
54 		// aLocalEnums,
55 		// aLocalTypedefs,
56 		// aLocalOperations,
57 		// aLocalVariables,
58 		// aLocalConstants,
59 		pParent(0),
60 		nDepth(0)
61 {
62     aAssignedNode.Assign_Entity(*this);
63 }
64 
65 Namespace::Namespace( const String  &     i_sLocalName,
66 					  Namespace &         i_rParent )
67 	:   aEssentials( i_sLocalName,
68 					 i_rParent.CeId(),
69 					 Lid(0) ),
70         aAssignedNode(),
71 		// aLocalNamespaces,
72 		// aLocalClasses,
73 		// aLocalEnums,
74 		// aLocalTypedefs,
75 		// aLocalOperations,
76 		// aLocalVariables,
77 		// aLocalConstants,
78 		pParent(&i_rParent),
79 		nDepth(i_rParent.Depth()+1)
80 {
81     aAssignedNode.Assign_Entity(*this);
82 }
83 
84 Namespace::~Namespace()
85 {
86 }
87 
88 void
89 Namespace::Add_LocalNamespace( DYN Namespace & io_rLocalNamespace )
90 {
91 	aLocalNamespaces[io_rLocalNamespace.LocalName()] = &io_rLocalNamespace;
92 }
93 
94 void
95 Namespace::Add_LocalClass( const String  &     i_sLocalName,
96 						   Cid                 i_nId )
97 {
98 	aLocalClasses[i_sLocalName] = i_nId;
99 }
100 
101 void
102 Namespace::Add_LocalEnum( const String  &     i_sLocalName,
103 						  Cid                 i_nId )
104 {
105 	aLocalEnums[i_sLocalName] = i_nId;
106 }
107 
108 void
109 Namespace::Add_LocalTypedef( const String  &     i_sLocalName,
110 							 Cid                 i_nId )
111 {
112 	aLocalTypedefs[i_sLocalName] = i_nId;
113 }
114 
115 void
116 Namespace::Add_LocalOperation( const String  &     i_sLocalName,
117 							   Cid                 i_nId )
118 {
119     aLocalOperations.insert( Map_Operations::value_type(i_sLocalName, i_nId) );
120 }
121 
122 
123 void
124 Namespace::Add_LocalVariable( const String  &     i_sLocalName,
125 							  Cid                 i_nId )
126 {
127 	aLocalVariables[i_sLocalName] = i_nId;
128 }
129 
130 void
131 Namespace::Add_LocalConstant( const String  &     i_sLocalName,
132 							  Cid                 i_nId )
133 {
134 	aLocalConstants[i_sLocalName] = i_nId;
135 }
136 
137 uintt
138 Namespace::Depth() const
139 {
140 	return nDepth;
141 }
142 
143 Namespace *
144 Namespace::Parent() const
145 {
146 	return pParent;
147 }
148 
149 Ce_id
150 Namespace::Search_Child(const String & i_key) const
151 {
152     Namespace *
153         ret_nsp = Search_LocalNamespace(i_key);
154     if (ret_nsp != 0)
155         return ret_nsp->CeId();
156 
157     Ce_id
158         ret = Search_LocalClass(i_key);
159     if (ret.IsValid())
160         return ret;
161 
162     ret = csv::value_from_map(aLocalEnums, i_key, Ce_id(0));
163     if (ret.IsValid())
164         return ret;
165     ret = csv::value_from_map(aLocalTypedefs, i_key, Ce_id(0));
166     if (ret.IsValid())
167         return ret;
168     ret = csv::value_from_map(aLocalVariables, i_key, Ce_id(0));
169     if (ret.IsValid())
170         return ret;
171     return csv::value_from_map(aLocalConstants, i_key, Ce_id(0));
172 }
173 
174 Namespace *
175 Namespace::Search_LocalNamespace( const String  & i_sLocalName ) const
176 {
177 	return csv::value_from_map(aLocalNamespaces, i_sLocalName, (Namespace*)(0));
178 }
179 
180 uintt
181 Namespace::Get_SubNamespaces( std::vector< const Namespace* > & o_rResultList ) const
182 {
183 	for ( Map_NamespacePtr::const_iterator it = aLocalNamespaces.begin();
184 		  it != aLocalNamespaces.end();
185 		  ++it )
186 	{
187 		o_rResultList.push_back( (*it).second );
188 	}
189 	return o_rResultList.size();
190 }
191 
192 Ce_id
193 Namespace::Search_LocalClass( const String  & i_sName ) const
194 {
195 	return csv::value_from_map(aLocalClasses, i_sName, Ce_id(0));
196 }
197 
198 void
199 Namespace::Search_LocalOperations( std::vector<Ce_id> & o_result,
200                                    const String &       i_sName ) const
201 {
202     operations_citer
203         itLower = aLocalOperations.lower_bound(i_sName);
204     if (itLower == aLocalOperations.end())
205         return;
206     if ( (*itLower).first != i_sName )
207         return;
208 
209     operations_citer
210         itEnd = aLocalOperations.end();
211     for ( operations_citer it = itLower;
212           it != aLocalOperations.end() ? (*itLower).first == i_sName : false;
213           ++it )
214     {
215         o_result.push_back((*it).second);
216     }
217 }
218 
219 
220 const String  &
221 Namespace::inq_LocalName() const
222 {
223 	return aEssentials.LocalName();
224 }
225 
226 Cid
227 Namespace::inq_Owner() const
228 {
229 	return aEssentials.Owner();
230 }
231 
232 Lid
233 Namespace::inq_Location() const
234 {
235 	return Lid(0);
236 }
237 
238 void
239 Namespace::do_Accept(csv::ProcessorIfc & io_processor) const
240 {
241     csv::CheckedCall(io_processor,*this);
242 }
243 
244 ClassId
245 Namespace::get_AryClass() const
246 {
247 	return class_id;
248 }
249 
250 Gid
251 Namespace::inq_Id_Group() const
252 {
253 	return static_cast<Gid>(Id());
254 }
255 
256 const ary::cpp::CppEntity &
257 Namespace::inq_RE_Group() const
258 {
259 	return *this;
260 }
261 
262 const ary::group::SlotList &
263 Namespace::inq_Slots() const
264 {
265 	static const SlotAccessId aProjectSlotData[]
266 			= { SLOT_SubNamespaces, SLOT_Classes, SLOT_Enums, SLOT_Typedefs, SLOT_Operations,
267 				SLOT_Variables, SLOT_Constants };
268 	static const std::vector< SlotAccessId >
269 			aSlots( &aProjectSlotData[0],
270 					  &aProjectSlotData[0]
271 						+ sizeof aProjectSlotData / sizeof (SlotAccessId) );
272 	return aSlots;
273 }
274 
275 DYN Slot *
276 Namespace::inq_Create_Slot( SlotAccessId i_nSlot ) const
277 {
278 	switch ( i_nSlot )
279 	{
280 		case SLOT_SubNamespaces:    return new Slot_SubNamespaces(aLocalNamespaces);
281 		case SLOT_Classes:          return new Slot_MapLocalCe(aLocalClasses);
282 		case SLOT_Enums:            return new Slot_MapLocalCe(aLocalEnums);
283 		case SLOT_Typedefs:         return new Slot_MapLocalCe(aLocalTypedefs);
284 		case SLOT_Operations:       return new Slot_MapOperations(aLocalOperations);
285 		case SLOT_Variables:        return new Slot_MapLocalCe(aLocalVariables);
286 		case SLOT_Constants:        return new Slot_MapLocalCe(aLocalConstants);
287 		default:
288 									return new Slot_Null;
289 	}   // end switch
290 }
291 
292 
293 }   // namespace cpp
294 }   // namespace ary
295