update credits
[LibreOffice.git] / autodoc / source / ary / idl / ia_ce.cxx
blob248b01bbb987d2e4e7c45dc7455f2b0404d74960
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <precomp.h>
21 #include "ia_ce.hxx"
24 // NOT FULLY DEFINED SERVICES
25 #include <algorithm>
26 #include <cosv/tpl/tpltools.hxx>
27 #include <ary/idl/i_attribute.hxx>
28 #include <ary/idl/i_constant.hxx>
29 #include <ary/idl/i_constgroup.hxx>
30 #include <ary/idl/i_enum.hxx>
31 #include <ary/idl/i_enumvalue.hxx>
32 #include <ary/idl/i_exception.hxx>
33 #include <ary/idl/i_function.hxx>
34 #include <ary/idl/i_interface.hxx>
35 #include <ary/idl/i_module.hxx>
36 #include <ary/idl/i_namelookup.hxx>
37 #include <ary/idl/i_property.hxx>
38 #include <ary/idl/i_service.hxx>
39 #include <ary/idl/i_singleton.hxx>
40 #include <ary/idl/i_siservice.hxx>
41 #include <ary/idl/i_sisingleton.hxx>
42 #include <ary/idl/i_struct.hxx>
43 #include <ary/idl/i_structelem.hxx>
44 #include <ary/idl/i_traits.hxx>
45 #include <ary/idl/i_typedef.hxx>
46 #include <idsort.hxx>
47 #include "ia_type.hxx"
48 #include "is_ce.hxx"
49 #include "it_tplparam.hxx"
54 namespace ary
56 namespace idl
59 inline Module &
60 CeAdmin::lhf_Access_Module( Ce_id i_nId )
61 { return ary_cast<Module>(Storage()[i_nId]); }
63 inline void
64 CeAdmin::lhf_Put2Storage_and_AssignId( CodeEntity & pass_io_rCe )
65 { // This also assigns an ID to pass_io_rCe:
66 Storage().Store_Entity(pass_io_rCe);
67 my_NameDictionary().Add_Name( pass_io_rCe.LocalName(),
68 pass_io_rCe.CeId(),
69 pass_io_rCe.AryClass(),
70 pass_io_rCe.Owner() );
73 inline void
74 CeAdmin::lhf_Store_NewEntity( DYN CodeEntity & pass_io_rCe,
75 Module & i_rOwner )
77 lhf_Put2Storage_and_AssignId(pass_io_rCe);
78 i_rOwner.Add_Name(pass_io_rCe.LocalName(), pass_io_rCe.CeId());
81 inline void
82 CeAdmin::lhf_Store_NewEntity( DYN CodeEntity & pass_io_rCe,
83 Ce_id i_nOwnerModule )
85 lhf_Store_NewEntity(pass_io_rCe, lhf_Access_Module(i_nOwnerModule));
90 CeAdmin::CeAdmin( NameLookup & io_rNameDictionary,
91 TypeAdmin & io_rTypePilot )
92 : pStorage(new Ce_Storage),
93 pGlobalNamespace(0),
94 pNameDictionary(&io_rNameDictionary),
95 pTypePilot(&io_rTypePilot)
97 Storage().Set_Reserved(
98 predefined::ce_GlobalNamespace,
99 *new Module );
100 pGlobalNamespace = &lhf_Access_Module(Ce_id(predefined::ce_GlobalNamespace));
103 CeAdmin::~CeAdmin()
109 Module &
110 CeAdmin::CheckIn_Module( Ce_id i_nParentId,
111 const String & i_sName )
113 Module & rOwner = lhf_Access_Module(i_nParentId);
114 Ce_id nId = rOwner.Search_Name(i_sName);
115 if (nId.IsValid())
117 return lhf_Access_Module(nId);
120 Module & ret = *new Module( i_sName,
121 rOwner );
122 lhf_Store_NewEntity(ret, rOwner);
123 return ret;
126 Service &
127 CeAdmin::Store_Service( Ce_id i_nOwner,
128 const String & i_sName )
130 Service & ret = *new Service( i_sName,
131 i_nOwner );
132 lhf_Store_NewEntity(ret, i_nOwner);
133 return ret;
136 SglIfcService &
137 CeAdmin::Store_SglIfcService( Ce_id i_nOwner,
138 const String & i_sName,
139 Type_id i_nBaseInterface )
141 SglIfcService &
142 ret = *new SglIfcService( i_sName,
143 i_nOwner,
144 i_nBaseInterface );
145 lhf_Store_NewEntity(ret, i_nOwner);
146 return ret;
149 Interface &
150 CeAdmin::Store_Interface( Ce_id i_nOwner,
151 const String & i_sName,
152 Type_id i_nBase )
154 Interface & ret = *new Interface( i_sName,
155 i_nOwner );
156 lhf_Store_NewEntity(ret, i_nOwner);
157 if (i_nBase.IsValid())
158 ret.Add_Base(i_nBase, 0);
159 return ret;
162 Struct &
163 CeAdmin::Store_Struct( Ce_id i_nOwner,
164 const String & i_sName,
165 Type_id i_nBase,
166 const String & i_sTemplateParam )
168 if (NOT i_sTemplateParam.empty())
170 return lhf_Store_TplStruct( i_nOwner,
171 i_sName,
172 i_nBase,
173 i_sTemplateParam );
176 Struct & ret = *new Struct( i_sName,
177 i_nOwner,
178 i_nBase,
179 String::Null_(),
180 Type_id::Null_() );
181 lhf_Store_NewEntity(ret, i_nOwner);
183 return ret;
186 Exception &
187 CeAdmin::Store_Exception( Ce_id i_nOwner,
188 const String & i_sName,
189 Type_id i_nBase )
191 Exception & ret = *new Exception( i_sName,
192 i_nOwner,
193 i_nBase );
194 lhf_Store_NewEntity(ret, i_nOwner);
195 return ret;
198 Enum &
199 CeAdmin::Store_Enum( Ce_id i_nOwner,
200 const String & i_sName )
202 Enum & ret = *new Enum( i_sName,
203 i_nOwner );
204 lhf_Store_NewEntity(ret, i_nOwner);
205 return ret;
208 Typedef &
209 CeAdmin::Store_Typedef( Ce_id i_nOwner,
210 const String & i_sName,
211 Type_id i_nDefiningType )
213 Typedef & ret = *new Typedef( i_sName,
214 i_nOwner,
215 i_nDefiningType );
216 lhf_Store_NewEntity(ret, i_nOwner);
217 return ret;
221 ConstantsGroup &
222 CeAdmin::Store_ConstantsGroup( Ce_id i_nOwner,
223 const String & i_sName )
225 ConstantsGroup & ret = *new ConstantsGroup( i_sName,
226 i_nOwner );
227 lhf_Store_NewEntity(ret, i_nOwner);
228 return ret;
231 Singleton &
232 CeAdmin::Store_Singleton( Ce_id i_nOwner,
233 const String & i_sName )
235 Singleton & ret = *new Singleton( i_sName,
236 i_nOwner );
237 lhf_Store_NewEntity(ret, i_nOwner);
238 return ret;
241 SglIfcSingleton &
242 CeAdmin::Store_SglIfcSingleton( Ce_id i_nOwner,
243 const String & i_sName,
244 Type_id i_nBaseInterface )
246 SglIfcSingleton &
247 ret = *new SglIfcSingleton( i_sName,
248 i_nOwner,
249 i_nBaseInterface );
250 lhf_Store_NewEntity(ret, i_nOwner);
251 return ret;
254 Constant &
255 CeAdmin::Store_Constant( Ce_id i_nOwner,
256 const String & i_sName,
257 Type_id i_nType,
258 const String & i_sValue )
260 ConstantsGroup &
261 rOwner = ary_cast<ConstantsGroup>(Storage()[i_nOwner]);
262 Constant & ret = *new Constant( i_sName,
263 i_nOwner,
264 rOwner.NameRoom(),
265 i_nType,
266 i_sValue );
267 lhf_Put2Storage_and_AssignId(ret);
268 rOwner.Add_Constant(ret.CeId());
269 return ret;
272 Property &
273 CeAdmin::Store_Property( Ce_id i_nOwner,
274 const String & i_sName,
275 Type_id i_nType,
276 Property::Stereotypes i_stereotypes )
278 Service &
279 rOwner = ary_cast<Service>(Storage()[i_nOwner]);
280 Property & ret = *new Property( i_sName,
281 i_nOwner,
282 rOwner.NameRoom(),
283 i_nType,
284 i_stereotypes );
285 lhf_Put2Storage_and_AssignId(ret);
286 rOwner.Add_Property(ret.CeId());
287 return ret;
290 Function &
291 CeAdmin::Store_Function( Ce_id i_nOwner,
292 const String & i_sName,
293 Type_id i_nReturnType,
294 bool i_bOneWay )
296 Interface &
297 rOwner = ary_cast<Interface>(Storage()[i_nOwner]);
298 Function & ret = *new Function( i_sName,
299 i_nOwner,
300 rOwner.NameRoom(),
301 i_nReturnType,
302 i_bOneWay);
303 lhf_Put2Storage_and_AssignId(ret);
304 rOwner.Add_Function(ret.CeId());
305 return ret;
308 Function &
309 CeAdmin::Store_ServiceConstructor( Ce_id i_nOwner,
310 const String & i_sName )
312 SglIfcService &
313 rOwner = ary_cast<SglIfcService>(Storage()[i_nOwner]);
314 Function & ret = *new Function( i_sName,
315 i_nOwner,
316 rOwner.NameRoom() );
317 lhf_Put2Storage_and_AssignId(ret);
318 rOwner.Add_Constructor(ret.CeId());
319 return ret;
322 StructElement &
323 CeAdmin::Store_StructMember( Ce_id i_nOwner,
324 const String & i_sName,
325 Type_id i_nType )
327 Struct &
328 rOwner = ary_cast<Struct>(Storage()[i_nOwner]);
329 StructElement & ret = *new StructElement( i_sName,
330 i_nOwner,
331 rOwner.NameRoom(),
332 i_nType );
333 lhf_Put2Storage_and_AssignId(ret);
334 rOwner.Add_Member(ret.CeId());
335 return ret;
338 StructElement &
339 CeAdmin::Store_ExceptionMember( Ce_id i_nOwner,
340 const String & i_sName,
341 Type_id i_nType )
343 Exception &
344 rOwner = ary_cast<Exception>(Storage()[i_nOwner]);
345 StructElement & ret = *new StructElement( i_sName,
346 i_nOwner,
347 rOwner.NameRoom(),
348 i_nType );
349 lhf_Put2Storage_and_AssignId(ret);
350 rOwner.Add_Member(ret.CeId());
351 return ret;
354 EnumValue &
355 CeAdmin::Store_EnumValue( Ce_id i_nOwner,
356 const String & i_sName,
357 const String & i_sValue )
359 Enum &
360 rOwner = ary_cast<Enum>(Storage()[i_nOwner]);
361 EnumValue & ret = *new EnumValue( i_sName,
362 i_nOwner,
363 rOwner.NameRoom(),
364 i_sValue );
365 lhf_Put2Storage_and_AssignId(ret);
366 rOwner.Add_Value(ret.CeId());
367 return ret;
370 Attribute &
371 CeAdmin::Store_Attribute( Ce_id i_nOwner,
372 const String & i_sName,
373 Type_id i_nType,
374 bool i_bReadOnly,
375 bool i_bBound )
377 Interface &
378 rOwner = ary_cast<Interface>(Storage()[i_nOwner]);
380 Attribute & ret = *new Attribute ( i_sName,
381 i_nOwner,
382 rOwner.NameRoom(),
383 i_nType,
384 i_bReadOnly,
385 i_bBound );
386 lhf_Put2Storage_and_AssignId(ret);
387 rOwner.Add_Attribute(ret.CeId());
388 return ret;
391 const Module &
392 CeAdmin::GlobalNamespace() const
394 csv_assert(pGlobalNamespace);
395 return *pGlobalNamespace;
398 const CodeEntity &
399 CeAdmin::Find_Ce( Ce_id i_nId ) const
401 return Storage()[i_nId];
405 const Module &
406 CeAdmin::Find_Module( Ce_id i_nId ) const
408 return ary_cast<Module>(Storage()[i_nId]);
411 const Module *
412 CeAdmin::Search_Module( Ce_id i_nId ) const
414 if (NOT i_nId.IsValid())
415 return 0;
416 return ary_cast<Module>( & Storage()[i_nId] );
419 const Function &
420 CeAdmin::Find_Function( Ce_id i_nId ) const
422 return ary_cast<Function>(Storage()[i_nId]);
425 const Property &
426 CeAdmin::Find_Property( Ce_id i_nId ) const
428 return ary_cast<Property>(Storage()[i_nId]);
431 const EnumValue &
432 CeAdmin::Find_EnumValue( Ce_id i_nId ) const
434 return ary_cast<EnumValue>(Storage()[i_nId]);
437 const Constant &
438 CeAdmin::Find_Constant( Ce_id i_nId ) const
440 return ary_cast<Constant>(Storage()[i_nId]);
443 const StructElement &
444 CeAdmin::Find_StructElement( Ce_id i_nId ) const
446 return ary_cast<StructElement>(Storage()[i_nId]);
449 void
450 CeAdmin::Get_Text( StringVector & o_module,
451 String & o_ce,
452 String & o_member,
453 const CodeEntity & i_ce ) const
455 const CodeEntity * pCe = &i_ce;
456 csv::erase_container(o_module);
457 o_ce.clear();
458 o_member.clear();
460 switch ( pCe->SightLevel() )
462 // Here are intentionally no breaks!
463 case sl_Member:
464 if ( is_type<Function>(*pCe) )
465 o_member = StreamLock(200)()
466 << pCe->LocalName()
467 << "()"
468 << c_str;
469 else
470 o_member = pCe->LocalName();
471 pCe = & Storage()[pCe->Owner()];
472 case sl_File:
473 o_ce = pCe->LocalName();
474 pCe = & Storage()[pCe->NameRoom()];
475 case sl_Module:
476 get_ModuleText(o_module,*pCe);
477 break;
478 default:
479 csv_assert(false);
480 } // end switch
483 const NameLookup &
484 CeAdmin::NameDictionary() const
486 return *pNameDictionary;
490 void
491 CeAdmin::Get_AlphabeticalIndex( std::vector<Ce_id> & o_rResult,
492 alphabetical_index::E_Letter i_cLetter ) const
494 const int C_nLowerUpperDiff = 'a'-'A';
496 // Establishing filter:
497 UINT8 filter[256];
499 UINT8 nLetter = static_cast<UINT8>(i_cLetter);
500 memset(filter, 0, 256);
501 filter[nLetter] = 1;
502 if ( i_cLetter != alphabetical_index::non_alpha )
503 filter[nLetter - C_nLowerUpperDiff] = 1;
505 // Gather entities which start with i_cLetter:
506 o_rResult.reserve(1000);
507 idl::Ce_Storage::c_iter
508 itEnd = Storage().End();
509 for ( idl::Ce_Storage::c_iter it = Storage().BeginUnreserved();
510 it != itEnd;
511 ++it )
513 if ( filter[ static_cast<UINT8>(*(*it).LocalName().c_str()) ] == 1 )
514 o_rResult.push_back( (*it).CeId() );
517 std::sort( o_rResult.begin(),
518 o_rResult.end(),
519 IdSorter<Ce_Compare>() );
523 Module &
524 CeAdmin::GlobalNamespace()
526 csv_assert(pGlobalNamespace);
527 return *pGlobalNamespace;
530 CodeEntity &
531 CeAdmin::Find_Ce( Ce_id i_nId )
533 return Storage()[i_nId];
536 void
537 CeAdmin::get_ModuleText( StringVector & o_module,
538 const CodeEntity & i_ce ) const
540 if (i_ce.NameRoom().IsValid())
542 const CodeEntity &
543 rParent = Storage()[i_ce.NameRoom()];
544 get_ModuleText(o_module, rParent);
545 o_module.push_back(i_ce.LocalName());
549 Struct &
550 CeAdmin::lhf_Store_TplStruct( Ce_id i_nOwner,
551 const String & i_sName,
552 Type_id i_nBase,
553 const String & i_sTemplateParam )
555 csv_assert(NOT i_sTemplateParam.empty());
557 TemplateParamType &
558 rTpt = pTypePilot->Store_TemplateParamType(i_sTemplateParam);
560 Struct & ret = *new Struct( i_sName,
561 i_nOwner,
562 i_nBase,
563 i_sTemplateParam,
564 rTpt.TypeId() );
565 lhf_Store_NewEntity(ret, i_nOwner);
566 rTpt.Set_StructId(ret.CeId());
568 return ret;
572 } // namespace idl
573 } // namespace ary
575 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */