Bump for 3.6-28
[LibreOffice.git] / autodoc / source / ary / idl / ia_ce.cxx
blob5e66838f1ba56fac158ebf1592bbff374949dd8c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <precomp.h>
30 #include "ia_ce.hxx"
33 // NOT FULLY DEFINED SERVICES
34 #include <algorithm>
35 #include <cosv/tpl/tpltools.hxx>
36 #include <ary/idl/i_attribute.hxx>
37 #include <ary/idl/i_constant.hxx>
38 #include <ary/idl/i_constgroup.hxx>
39 #include <ary/idl/i_enum.hxx>
40 #include <ary/idl/i_enumvalue.hxx>
41 #include <ary/idl/i_exception.hxx>
42 #include <ary/idl/i_function.hxx>
43 #include <ary/idl/i_interface.hxx>
44 #include <ary/idl/i_module.hxx>
45 #include <ary/idl/i_namelookup.hxx>
46 #include <ary/idl/i_property.hxx>
47 #include <ary/idl/i_service.hxx>
48 #include <ary/idl/i_singleton.hxx>
49 #include <ary/idl/i_siservice.hxx>
50 #include <ary/idl/i_sisingleton.hxx>
51 #include <ary/idl/i_struct.hxx>
52 #include <ary/idl/i_structelem.hxx>
53 #include <ary/idl/i_traits.hxx>
54 #include <ary/idl/i_typedef.hxx>
55 #include <idsort.hxx>
56 #include "ia_type.hxx"
57 #include "is_ce.hxx"
58 #include "it_tplparam.hxx"
63 namespace ary
65 namespace idl
68 inline Module &
69 CeAdmin::lhf_Access_Module( Ce_id i_nId )
70 { return ary_cast<Module>(Storage()[i_nId]); }
72 inline void
73 CeAdmin::lhf_Put2Storage_and_AssignId( CodeEntity & pass_io_rCe )
74 { // This also assigns an ID to pass_io_rCe:
75 Storage().Store_Entity(pass_io_rCe);
76 my_NameDictionary().Add_Name( pass_io_rCe.LocalName(),
77 pass_io_rCe.CeId(),
78 pass_io_rCe.AryClass(),
79 pass_io_rCe.Owner() );
82 inline void
83 CeAdmin::lhf_Store_NewEntity( DYN CodeEntity & pass_io_rCe,
84 Module & i_rOwner )
86 lhf_Put2Storage_and_AssignId(pass_io_rCe);
87 i_rOwner.Add_Name(pass_io_rCe.LocalName(), pass_io_rCe.CeId());
90 inline void
91 CeAdmin::lhf_Store_NewEntity( DYN CodeEntity & pass_io_rCe,
92 Ce_id i_nOwnerModule )
94 lhf_Store_NewEntity(pass_io_rCe, lhf_Access_Module(i_nOwnerModule));
99 CeAdmin::CeAdmin( NameLookup & io_rNameDictionary,
100 TypeAdmin & io_rTypePilot )
101 : pStorage(new Ce_Storage),
102 pGlobalNamespace(0),
103 pNameDictionary(&io_rNameDictionary),
104 pTypePilot(&io_rTypePilot)
106 Storage().Set_Reserved(
107 predefined::ce_GlobalNamespace,
108 *new Module );
109 pGlobalNamespace = &lhf_Access_Module(Ce_id(predefined::ce_GlobalNamespace));
112 CeAdmin::~CeAdmin()
118 Module &
119 CeAdmin::CheckIn_Module( Ce_id i_nParentId,
120 const String & i_sName )
122 Module & rOwner = lhf_Access_Module(i_nParentId);
123 Ce_id nId = rOwner.Search_Name(i_sName);
124 if (nId.IsValid())
126 return lhf_Access_Module(nId);
129 Module & ret = *new Module( i_sName,
130 rOwner );
131 lhf_Store_NewEntity(ret, rOwner);
132 return ret;
135 Service &
136 CeAdmin::Store_Service( Ce_id i_nOwner,
137 const String & i_sName )
139 Service & ret = *new Service( i_sName,
140 i_nOwner );
141 lhf_Store_NewEntity(ret, i_nOwner);
142 return ret;
145 SglIfcService &
146 CeAdmin::Store_SglIfcService( Ce_id i_nOwner,
147 const String & i_sName,
148 Type_id i_nBaseInterface )
150 SglIfcService &
151 ret = *new SglIfcService( i_sName,
152 i_nOwner,
153 i_nBaseInterface );
154 lhf_Store_NewEntity(ret, i_nOwner);
155 return ret;
158 Interface &
159 CeAdmin::Store_Interface( Ce_id i_nOwner,
160 const String & i_sName,
161 Type_id i_nBase )
163 Interface & ret = *new Interface( i_sName,
164 i_nOwner );
165 lhf_Store_NewEntity(ret, i_nOwner);
166 if (i_nBase.IsValid())
167 ret.Add_Base(i_nBase, 0);
168 return ret;
171 Struct &
172 CeAdmin::Store_Struct( Ce_id i_nOwner,
173 const String & i_sName,
174 Type_id i_nBase,
175 const String & i_sTemplateParam )
177 if (NOT i_sTemplateParam.empty())
179 return lhf_Store_TplStruct( i_nOwner,
180 i_sName,
181 i_nBase,
182 i_sTemplateParam );
185 Struct & ret = *new Struct( i_sName,
186 i_nOwner,
187 i_nBase,
188 String::Null_(),
189 Type_id::Null_() );
190 lhf_Store_NewEntity(ret, i_nOwner);
192 return ret;
195 Exception &
196 CeAdmin::Store_Exception( Ce_id i_nOwner,
197 const String & i_sName,
198 Type_id i_nBase )
200 Exception & ret = *new Exception( i_sName,
201 i_nOwner,
202 i_nBase );
203 lhf_Store_NewEntity(ret, i_nOwner);
204 return ret;
207 Enum &
208 CeAdmin::Store_Enum( Ce_id i_nOwner,
209 const String & i_sName )
211 Enum & ret = *new Enum( i_sName,
212 i_nOwner );
213 lhf_Store_NewEntity(ret, i_nOwner);
214 return ret;
217 Typedef &
218 CeAdmin::Store_Typedef( Ce_id i_nOwner,
219 const String & i_sName,
220 Type_id i_nDefiningType )
222 Typedef & ret = *new Typedef( i_sName,
223 i_nOwner,
224 i_nDefiningType );
225 lhf_Store_NewEntity(ret, i_nOwner);
226 return ret;
230 ConstantsGroup &
231 CeAdmin::Store_ConstantsGroup( Ce_id i_nOwner,
232 const String & i_sName )
234 ConstantsGroup & ret = *new ConstantsGroup( i_sName,
235 i_nOwner );
236 lhf_Store_NewEntity(ret, i_nOwner);
237 return ret;
240 Singleton &
241 CeAdmin::Store_Singleton( Ce_id i_nOwner,
242 const String & i_sName )
244 Singleton & ret = *new Singleton( i_sName,
245 i_nOwner );
246 lhf_Store_NewEntity(ret, i_nOwner);
247 return ret;
250 SglIfcSingleton &
251 CeAdmin::Store_SglIfcSingleton( Ce_id i_nOwner,
252 const String & i_sName,
253 Type_id i_nBaseInterface )
255 SglIfcSingleton &
256 ret = *new SglIfcSingleton( i_sName,
257 i_nOwner,
258 i_nBaseInterface );
259 lhf_Store_NewEntity(ret, i_nOwner);
260 return ret;
263 Constant &
264 CeAdmin::Store_Constant( Ce_id i_nOwner,
265 const String & i_sName,
266 Type_id i_nType,
267 const String & i_sValue )
269 ConstantsGroup &
270 rOwner = ary_cast<ConstantsGroup>(Storage()[i_nOwner]);
271 Constant & ret = *new Constant( i_sName,
272 i_nOwner,
273 rOwner.NameRoom(),
274 i_nType,
275 i_sValue );
276 lhf_Put2Storage_and_AssignId(ret);
277 rOwner.Add_Constant(ret.CeId());
278 return ret;
281 Property &
282 CeAdmin::Store_Property( Ce_id i_nOwner,
283 const String & i_sName,
284 Type_id i_nType,
285 Property::Stereotypes i_stereotypes )
287 Service &
288 rOwner = ary_cast<Service>(Storage()[i_nOwner]);
289 Property & ret = *new Property( i_sName,
290 i_nOwner,
291 rOwner.NameRoom(),
292 i_nType,
293 i_stereotypes );
294 lhf_Put2Storage_and_AssignId(ret);
295 rOwner.Add_Property(ret.CeId());
296 return ret;
299 Function &
300 CeAdmin::Store_Function( Ce_id i_nOwner,
301 const String & i_sName,
302 Type_id i_nReturnType,
303 bool i_bOneWay )
305 Interface &
306 rOwner = ary_cast<Interface>(Storage()[i_nOwner]);
307 Function & ret = *new Function( i_sName,
308 i_nOwner,
309 rOwner.NameRoom(),
310 i_nReturnType,
311 i_bOneWay);
312 lhf_Put2Storage_and_AssignId(ret);
313 rOwner.Add_Function(ret.CeId());
314 return ret;
317 Function &
318 CeAdmin::Store_ServiceConstructor( Ce_id i_nOwner,
319 const String & i_sName )
321 SglIfcService &
322 rOwner = ary_cast<SglIfcService>(Storage()[i_nOwner]);
323 Function & ret = *new Function( i_sName,
324 i_nOwner,
325 rOwner.NameRoom() );
326 lhf_Put2Storage_and_AssignId(ret);
327 rOwner.Add_Constructor(ret.CeId());
328 return ret;
331 StructElement &
332 CeAdmin::Store_StructMember( Ce_id i_nOwner,
333 const String & i_sName,
334 Type_id i_nType )
336 Struct &
337 rOwner = ary_cast<Struct>(Storage()[i_nOwner]);
338 StructElement & ret = *new StructElement( i_sName,
339 i_nOwner,
340 rOwner.NameRoom(),
341 i_nType );
342 lhf_Put2Storage_and_AssignId(ret);
343 rOwner.Add_Member(ret.CeId());
344 return ret;
347 StructElement &
348 CeAdmin::Store_ExceptionMember( Ce_id i_nOwner,
349 const String & i_sName,
350 Type_id i_nType )
352 Exception &
353 rOwner = ary_cast<Exception>(Storage()[i_nOwner]);
354 StructElement & ret = *new StructElement( i_sName,
355 i_nOwner,
356 rOwner.NameRoom(),
357 i_nType );
358 lhf_Put2Storage_and_AssignId(ret);
359 rOwner.Add_Member(ret.CeId());
360 return ret;
363 EnumValue &
364 CeAdmin::Store_EnumValue( Ce_id i_nOwner,
365 const String & i_sName,
366 const String & i_sValue )
368 Enum &
369 rOwner = ary_cast<Enum>(Storage()[i_nOwner]);
370 EnumValue & ret = *new EnumValue( i_sName,
371 i_nOwner,
372 rOwner.NameRoom(),
373 i_sValue );
374 lhf_Put2Storage_and_AssignId(ret);
375 rOwner.Add_Value(ret.CeId());
376 return ret;
379 Attribute &
380 CeAdmin::Store_Attribute( Ce_id i_nOwner,
381 const String & i_sName,
382 Type_id i_nType,
383 bool i_bReadOnly,
384 bool i_bBound )
386 Interface &
387 rOwner = ary_cast<Interface>(Storage()[i_nOwner]);
389 Attribute & ret = *new Attribute ( i_sName,
390 i_nOwner,
391 rOwner.NameRoom(),
392 i_nType,
393 i_bReadOnly,
394 i_bBound );
395 lhf_Put2Storage_and_AssignId(ret);
396 rOwner.Add_Attribute(ret.CeId());
397 return ret;
400 const Module &
401 CeAdmin::GlobalNamespace() const
403 csv_assert(pGlobalNamespace);
404 return *pGlobalNamespace;
407 const CodeEntity &
408 CeAdmin::Find_Ce( Ce_id i_nId ) const
410 return Storage()[i_nId];
414 const Module &
415 CeAdmin::Find_Module( Ce_id i_nId ) const
417 return ary_cast<Module>(Storage()[i_nId]);
420 const Module *
421 CeAdmin::Search_Module( Ce_id i_nId ) const
423 if (NOT i_nId.IsValid())
424 return 0;
425 return ary_cast<Module>( & Storage()[i_nId] );
428 const Function &
429 CeAdmin::Find_Function( Ce_id i_nId ) const
431 return ary_cast<Function>(Storage()[i_nId]);
434 const Property &
435 CeAdmin::Find_Property( Ce_id i_nId ) const
437 return ary_cast<Property>(Storage()[i_nId]);
440 const EnumValue &
441 CeAdmin::Find_EnumValue( Ce_id i_nId ) const
443 return ary_cast<EnumValue>(Storage()[i_nId]);
446 const Constant &
447 CeAdmin::Find_Constant( Ce_id i_nId ) const
449 return ary_cast<Constant>(Storage()[i_nId]);
452 const StructElement &
453 CeAdmin::Find_StructElement( Ce_id i_nId ) const
455 return ary_cast<StructElement>(Storage()[i_nId]);
458 void
459 CeAdmin::Get_Text( StringVector & o_module,
460 String & o_ce,
461 String & o_member,
462 const CodeEntity & i_ce ) const
464 const CodeEntity * pCe = &i_ce;
465 csv::erase_container(o_module);
466 o_ce.clear();
467 o_member.clear();
469 switch ( pCe->SightLevel() )
471 // Here are intentionally no breaks!
472 case sl_Member:
473 if ( is_type<Function>(*pCe) )
474 o_member = StreamLock(200)()
475 << pCe->LocalName()
476 << "()"
477 << c_str;
478 else
479 o_member = pCe->LocalName();
480 pCe = & Storage()[pCe->Owner()];
481 case sl_File:
482 o_ce = pCe->LocalName();
483 pCe = & Storage()[pCe->NameRoom()];
484 case sl_Module:
485 get_ModuleText(o_module,*pCe);
486 break;
487 default:
488 csv_assert(false);
489 } // end switch
492 const NameLookup &
493 CeAdmin::NameDictionary() const
495 return *pNameDictionary;
499 void
500 CeAdmin::Get_AlphabeticalIndex( std::vector<Ce_id> & o_rResult,
501 alphabetical_index::E_Letter i_cLetter ) const
503 const int C_nLowerUpperDiff = 'a'-'A';
505 // Establishing filter:
506 UINT8 filter[256];
508 UINT8 nLetter = static_cast<UINT8>(i_cLetter);
509 memset(filter, 0, 256);
510 filter[nLetter] = 1;
511 if ( i_cLetter != alphabetical_index::non_alpha )
512 filter[nLetter - C_nLowerUpperDiff] = 1;
514 // Gather entities which start with i_cLetter:
515 o_rResult.reserve(1000);
516 idl::Ce_Storage::c_iter
517 itEnd = Storage().End();
518 for ( idl::Ce_Storage::c_iter it = Storage().BeginUnreserved();
519 it != itEnd;
520 ++it )
522 if ( filter[ static_cast<UINT8>(*(*it).LocalName().c_str()) ] == 1 )
523 o_rResult.push_back( (*it).CeId() );
526 std::sort( o_rResult.begin(),
527 o_rResult.end(),
528 IdSorter<Ce_Compare>() );
532 Module &
533 CeAdmin::GlobalNamespace()
535 csv_assert(pGlobalNamespace);
536 return *pGlobalNamespace;
539 CodeEntity &
540 CeAdmin::Find_Ce( Ce_id i_nId )
542 return Storage()[i_nId];
545 void
546 CeAdmin::get_ModuleText( StringVector & o_module,
547 const CodeEntity & i_ce ) const
549 if (i_ce.NameRoom().IsValid())
551 const CodeEntity &
552 rParent = Storage()[i_ce.NameRoom()];
553 get_ModuleText(o_module, rParent);
554 o_module.push_back(i_ce.LocalName());
558 Struct &
559 CeAdmin::lhf_Store_TplStruct( Ce_id i_nOwner,
560 const String & i_sName,
561 Type_id i_nBase,
562 const String & i_sTemplateParam )
564 csv_assert(NOT i_sTemplateParam.empty());
566 TemplateParamType &
567 rTpt = pTypePilot->Store_TemplateParamType(i_sTemplateParam);
569 Struct & ret = *new Struct( i_sName,
570 i_nOwner,
571 i_nBase,
572 i_sTemplateParam,
573 rTpt.TypeId() );
574 lhf_Store_NewEntity(ret, i_nOwner);
575 rTpt.Set_StructId(ret.CeId());
577 return ret;
581 } // namespace idl
582 } // namespace ary
584 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */