merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / ary / idl / ia_ce.cxx
blob3dab380e1ffa7924b48bbbbc4856034b6bc61b78
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ia_ce.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include "ia_ce.hxx"
35 // NOT FULLY DEFINED SERVICES
36 #include <algorithm>
37 #include <cosv/tpl/tpltools.hxx>
38 #include <ary/idl/i_attribute.hxx>
39 #include <ary/idl/i_constant.hxx>
40 #include <ary/idl/i_constgroup.hxx>
41 #include <ary/idl/i_enum.hxx>
42 #include <ary/idl/i_enumvalue.hxx>
43 #include <ary/idl/i_exception.hxx>
44 #include <ary/idl/i_function.hxx>
45 #include <ary/idl/i_interface.hxx>
46 #include <ary/idl/i_module.hxx>
47 #include <ary/idl/i_namelookup.hxx>
48 #include <ary/idl/i_property.hxx>
49 #include <ary/idl/i_service.hxx>
50 #include <ary/idl/i_singleton.hxx>
51 #include <ary/idl/i_siservice.hxx>
52 #include <ary/idl/i_sisingleton.hxx>
53 #include <ary/idl/i_struct.hxx>
54 #include <ary/idl/i_structelem.hxx>
55 #include <ary/idl/i_traits.hxx>
56 #include <ary/idl/i_typedef.hxx>
57 #include <idsort.hxx>
58 #include "ia_type.hxx"
59 #include "is_ce.hxx"
60 #include "it_tplparam.hxx"
65 namespace ary
67 namespace idl
70 inline Module &
71 CeAdmin::lhf_Access_Module( Ce_id i_nId )
72 { return ary_cast<Module>(Storage()[i_nId]); }
74 inline void
75 CeAdmin::lhf_Put2Storage_and_AssignId( CodeEntity & pass_io_rCe )
76 { // This also assigns an ID to pass_io_rCe:
77 Storage().Store_Entity(pass_io_rCe);
78 my_NameDictionary().Add_Name( pass_io_rCe.LocalName(),
79 pass_io_rCe.CeId(),
80 pass_io_rCe.AryClass(),
81 pass_io_rCe.Owner() );
84 inline void
85 CeAdmin::lhf_Store_NewEntity( DYN CodeEntity & pass_io_rCe,
86 Module & i_rOwner )
88 lhf_Put2Storage_and_AssignId(pass_io_rCe);
89 i_rOwner.Add_Name(pass_io_rCe.LocalName(), pass_io_rCe.CeId());
92 inline void
93 CeAdmin::lhf_Store_NewEntity( DYN CodeEntity & pass_io_rCe,
94 Ce_id i_nOwnerModule )
96 lhf_Store_NewEntity(pass_io_rCe, lhf_Access_Module(i_nOwnerModule));
101 CeAdmin::CeAdmin( NameLookup & io_rNameDictionary,
102 TypeAdmin & io_rTypePilot )
103 : pStorage(new Ce_Storage),
104 pGlobalNamespace(0),
105 pNameDictionary(&io_rNameDictionary),
106 pTypePilot(&io_rTypePilot)
108 Storage().Set_Reserved(
109 predefined::ce_GlobalNamespace,
110 *new Module );
111 pGlobalNamespace = &lhf_Access_Module(Ce_id(predefined::ce_GlobalNamespace));
114 CeAdmin::~CeAdmin()
120 Module &
121 CeAdmin::CheckIn_Module( Ce_id i_nParentId,
122 const String & i_sName )
124 Module & rOwner = lhf_Access_Module(i_nParentId);
125 Ce_id nId = rOwner.Search_Name(i_sName);
126 if (nId.IsValid())
128 return lhf_Access_Module(nId);
131 Module & ret = *new Module( i_sName,
132 rOwner );
133 lhf_Store_NewEntity(ret, rOwner);
134 return ret;
137 Service &
138 CeAdmin::Store_Service( Ce_id i_nOwner,
139 const String & i_sName )
141 Service & ret = *new Service( i_sName,
142 i_nOwner );
143 lhf_Store_NewEntity(ret, i_nOwner);
144 return ret;
147 SglIfcService &
148 CeAdmin::Store_SglIfcService( Ce_id i_nOwner,
149 const String & i_sName,
150 Type_id i_nBaseInterface )
152 SglIfcService &
153 ret = *new SglIfcService( i_sName,
154 i_nOwner,
155 i_nBaseInterface );
156 lhf_Store_NewEntity(ret, i_nOwner);
157 return ret;
160 Interface &
161 CeAdmin::Store_Interface( Ce_id i_nOwner,
162 const String & i_sName,
163 Type_id i_nBase )
165 Interface & ret = *new Interface( i_sName,
166 i_nOwner );
167 lhf_Store_NewEntity(ret, i_nOwner);
168 if (i_nBase.IsValid())
169 ret.Add_Base(i_nBase, 0);
170 return ret;
173 Struct &
174 CeAdmin::Store_Struct( Ce_id i_nOwner,
175 const String & i_sName,
176 Type_id i_nBase,
177 const String & i_sTemplateParam )
179 if (NOT i_sTemplateParam.empty())
181 return lhf_Store_TplStruct( i_nOwner,
182 i_sName,
183 i_nBase,
184 i_sTemplateParam );
187 Struct & ret = *new Struct( i_sName,
188 i_nOwner,
189 i_nBase,
190 String::Null_(),
191 Type_id::Null_() );
192 lhf_Store_NewEntity(ret, i_nOwner);
194 return ret;
197 Exception &
198 CeAdmin::Store_Exception( Ce_id i_nOwner,
199 const String & i_sName,
200 Type_id i_nBase )
202 Exception & ret = *new Exception( i_sName,
203 i_nOwner,
204 i_nBase );
205 lhf_Store_NewEntity(ret, i_nOwner);
206 return ret;
209 Enum &
210 CeAdmin::Store_Enum( Ce_id i_nOwner,
211 const String & i_sName )
213 Enum & ret = *new Enum( i_sName,
214 i_nOwner );
215 lhf_Store_NewEntity(ret, i_nOwner);
216 return ret;
219 Typedef &
220 CeAdmin::Store_Typedef( Ce_id i_nOwner,
221 const String & i_sName,
222 Type_id i_nDefiningType )
224 Typedef & ret = *new Typedef( i_sName,
225 i_nOwner,
226 i_nDefiningType );
227 lhf_Store_NewEntity(ret, i_nOwner);
228 return ret;
232 ConstantsGroup &
233 CeAdmin::Store_ConstantsGroup( Ce_id i_nOwner,
234 const String & i_sName )
236 ConstantsGroup & ret = *new ConstantsGroup( i_sName,
237 i_nOwner );
238 lhf_Store_NewEntity(ret, i_nOwner);
239 return ret;
242 Singleton &
243 CeAdmin::Store_Singleton( Ce_id i_nOwner,
244 const String & i_sName )
246 Singleton & ret = *new Singleton( i_sName,
247 i_nOwner );
248 lhf_Store_NewEntity(ret, i_nOwner);
249 return ret;
252 SglIfcSingleton &
253 CeAdmin::Store_SglIfcSingleton( Ce_id i_nOwner,
254 const String & i_sName,
255 Type_id i_nBaseInterface )
257 SglIfcSingleton &
258 ret = *new SglIfcSingleton( i_sName,
259 i_nOwner,
260 i_nBaseInterface );
261 lhf_Store_NewEntity(ret, i_nOwner);
262 return ret;
265 Constant &
266 CeAdmin::Store_Constant( Ce_id i_nOwner,
267 const String & i_sName,
268 Type_id i_nType,
269 const String & i_sValue )
271 ConstantsGroup &
272 rOwner = ary_cast<ConstantsGroup>(Storage()[i_nOwner]);
273 Constant & ret = *new Constant( i_sName,
274 i_nOwner,
275 rOwner.NameRoom(),
276 i_nType,
277 i_sValue );
278 lhf_Put2Storage_and_AssignId(ret);
279 rOwner.Add_Constant(ret.CeId());
280 return ret;
283 Property &
284 CeAdmin::Store_Property( Ce_id i_nOwner,
285 const String & i_sName,
286 Type_id i_nType,
287 Property::Stereotypes i_stereotypes )
289 Service &
290 rOwner = ary_cast<Service>(Storage()[i_nOwner]);
291 Property & ret = *new Property( i_sName,
292 i_nOwner,
293 rOwner.NameRoom(),
294 i_nType,
295 i_stereotypes );
296 lhf_Put2Storage_and_AssignId(ret);
297 rOwner.Add_Property(ret.CeId());
298 return ret;
301 Function &
302 CeAdmin::Store_Function( Ce_id i_nOwner,
303 const String & i_sName,
304 Type_id i_nReturnType,
305 bool i_bOneWay )
307 Interface &
308 rOwner = ary_cast<Interface>(Storage()[i_nOwner]);
309 Function & ret = *new Function( i_sName,
310 i_nOwner,
311 rOwner.NameRoom(),
312 i_nReturnType,
313 i_bOneWay);
314 lhf_Put2Storage_and_AssignId(ret);
315 rOwner.Add_Function(ret.CeId());
316 return ret;
319 Function &
320 CeAdmin::Store_ServiceConstructor( Ce_id i_nOwner,
321 const String & i_sName )
323 SglIfcService &
324 rOwner = ary_cast<SglIfcService>(Storage()[i_nOwner]);
325 Function & ret = *new Function( i_sName,
326 i_nOwner,
327 rOwner.NameRoom() );
328 lhf_Put2Storage_and_AssignId(ret);
329 rOwner.Add_Constructor(ret.CeId());
330 return ret;
333 StructElement &
334 CeAdmin::Store_StructMember( Ce_id i_nOwner,
335 const String & i_sName,
336 Type_id i_nType )
338 Struct &
339 rOwner = ary_cast<Struct>(Storage()[i_nOwner]);
340 StructElement & ret = *new StructElement( i_sName,
341 i_nOwner,
342 rOwner.NameRoom(),
343 i_nType );
344 lhf_Put2Storage_and_AssignId(ret);
345 rOwner.Add_Member(ret.CeId());
346 return ret;
349 StructElement &
350 CeAdmin::Store_ExceptionMember( Ce_id i_nOwner,
351 const String & i_sName,
352 Type_id i_nType )
354 Exception &
355 rOwner = ary_cast<Exception>(Storage()[i_nOwner]);
356 StructElement & ret = *new StructElement( i_sName,
357 i_nOwner,
358 rOwner.NameRoom(),
359 i_nType );
360 lhf_Put2Storage_and_AssignId(ret);
361 rOwner.Add_Member(ret.CeId());
362 return ret;
365 EnumValue &
366 CeAdmin::Store_EnumValue( Ce_id i_nOwner,
367 const String & i_sName,
368 const String & i_sValue )
370 Enum &
371 rOwner = ary_cast<Enum>(Storage()[i_nOwner]);
372 EnumValue & ret = *new EnumValue( i_sName,
373 i_nOwner,
374 rOwner.NameRoom(),
375 i_sValue );
376 lhf_Put2Storage_and_AssignId(ret);
377 rOwner.Add_Value(ret.CeId());
378 return ret;
381 Attribute &
382 CeAdmin::Store_Attribute( Ce_id i_nOwner,
383 const String & i_sName,
384 Type_id i_nType,
385 bool i_bReadOnly,
386 bool i_bBound )
388 Interface &
389 rOwner = ary_cast<Interface>(Storage()[i_nOwner]);
391 Attribute & ret = *new Attribute ( i_sName,
392 i_nOwner,
393 rOwner.NameRoom(),
394 i_nType,
395 i_bReadOnly,
396 i_bBound );
397 lhf_Put2Storage_and_AssignId(ret);
398 rOwner.Add_Attribute(ret.CeId());
399 return ret;
402 const Module &
403 CeAdmin::GlobalNamespace() const
405 csv_assert(pGlobalNamespace);
406 return *pGlobalNamespace;
409 const CodeEntity &
410 CeAdmin::Find_Ce( Ce_id i_nId ) const
412 return Storage()[i_nId];
416 const Module &
417 CeAdmin::Find_Module( Ce_id i_nId ) const
419 return ary_cast<Module>(Storage()[i_nId]);
422 const Module *
423 CeAdmin::Search_Module( Ce_id i_nId ) const
425 if (NOT i_nId.IsValid())
426 return 0;
427 return ary_cast<Module>( & Storage()[i_nId] );
430 const Function &
431 CeAdmin::Find_Function( Ce_id i_nId ) const
433 return ary_cast<Function>(Storage()[i_nId]);
436 const Property &
437 CeAdmin::Find_Property( Ce_id i_nId ) const
439 return ary_cast<Property>(Storage()[i_nId]);
442 const EnumValue &
443 CeAdmin::Find_EnumValue( Ce_id i_nId ) const
445 return ary_cast<EnumValue>(Storage()[i_nId]);
448 const Constant &
449 CeAdmin::Find_Constant( Ce_id i_nId ) const
451 return ary_cast<Constant>(Storage()[i_nId]);
454 const StructElement &
455 CeAdmin::Find_StructElement( Ce_id i_nId ) const
457 return ary_cast<StructElement>(Storage()[i_nId]);
460 void
461 CeAdmin::Get_Text( StringVector & o_module,
462 String & o_ce,
463 String & o_member,
464 const CodeEntity & i_ce ) const
466 const CodeEntity * pCe = &i_ce;
467 csv::erase_container(o_module);
468 o_ce.clear();
469 o_member.clear();
471 switch ( pCe->SightLevel() )
473 // Here are intentionally no breaks!
474 case sl_Member:
475 if ( is_type<Function>(*pCe) )
476 o_member = StreamLock(200)()
477 << pCe->LocalName()
478 << "()"
479 << c_str;
480 else
481 o_member = pCe->LocalName();
482 pCe = & Storage()[pCe->Owner()];
483 case sl_File:
484 o_ce = pCe->LocalName();
485 pCe = & Storage()[pCe->NameRoom()];
486 case sl_Module:
487 get_ModuleText(o_module,*pCe);
488 break;
489 default:
490 csv_assert(false);
491 } // end switch
494 const NameLookup &
495 CeAdmin::NameDictionary() const
497 return *pNameDictionary;
501 void
502 CeAdmin::Get_AlphabeticalIndex( std::vector<Ce_id> & o_rResult,
503 alphabetical_index::E_Letter i_cLetter ) const
505 const int C_nLowerUpperDiff = 'a'-'A';
507 // Establishing filter:
508 UINT8 filter[256];
510 UINT8 nLetter = static_cast<UINT8>(i_cLetter);
511 memset(filter, 0, 256);
512 filter[nLetter] = 1;
513 if ( i_cLetter != alphabetical_index::non_alpha )
514 filter[nLetter - C_nLowerUpperDiff] = 1;
516 // Gather entities which start with i_cLetter:
517 o_rResult.reserve(1000);
518 idl::Ce_Storage::c_iter
519 itEnd = Storage().End();
520 for ( idl::Ce_Storage::c_iter it = Storage().BeginUnreserved();
521 it != itEnd;
522 ++it )
524 if ( filter[ static_cast<UINT8>(*(*it).LocalName().c_str()) ] == 1 )
525 o_rResult.push_back( (*it).CeId() );
528 std::sort( o_rResult.begin(),
529 o_rResult.end(),
530 IdSorter<Ce_Compare>() );
534 Module &
535 CeAdmin::GlobalNamespace()
537 csv_assert(pGlobalNamespace);
538 return *pGlobalNamespace;
541 CodeEntity &
542 CeAdmin::Find_Ce( Ce_id i_nId )
544 return Storage()[i_nId];
547 void
548 CeAdmin::get_ModuleText( StringVector & o_module,
549 const CodeEntity & i_ce ) const
551 if (i_ce.NameRoom().IsValid())
553 const CodeEntity &
554 rParent = Storage()[i_ce.NameRoom()];
555 get_ModuleText(o_module, rParent);
556 o_module.push_back(i_ce.LocalName());
560 Struct &
561 CeAdmin::lhf_Store_TplStruct( Ce_id i_nOwner,
562 const String & i_sName,
563 Type_id i_nBase,
564 const String & i_sTemplateParam )
566 csv_assert(NOT i_sTemplateParam.empty());
568 TemplateParamType &
569 rTpt = pTypePilot->Store_TemplateParamType(i_sTemplateParam);
571 Struct & ret = *new Struct( i_sName,
572 i_nOwner,
573 i_nBase,
574 i_sTemplateParam,
575 rTpt.TypeId() );
576 lhf_Store_NewEntity(ret, i_nOwner);
577 rTpt.Set_StructId(ret.CeId());
579 return ret;
583 } // namespace idl
584 } // namespace ary