1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ia_ce.cxx,v $
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 ************************************************************************/
35 // NOT FULLY DEFINED SERVICES
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>
58 #include "ia_type.hxx"
60 #include "it_tplparam.hxx"
71 CeAdmin::lhf_Access_Module( Ce_id i_nId
)
72 { return ary_cast
<Module
>(Storage()[i_nId
]); }
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(),
80 pass_io_rCe
.AryClass(),
81 pass_io_rCe
.Owner() );
85 CeAdmin::lhf_Store_NewEntity( DYN CodeEntity
& pass_io_rCe
,
88 lhf_Put2Storage_and_AssignId(pass_io_rCe
);
89 i_rOwner
.Add_Name(pass_io_rCe
.LocalName(), pass_io_rCe
.CeId());
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
),
105 pNameDictionary(&io_rNameDictionary
),
106 pTypePilot(&io_rTypePilot
)
108 Storage().Set_Reserved(
109 predefined::ce_GlobalNamespace
,
111 pGlobalNamespace
= &lhf_Access_Module(Ce_id(predefined::ce_GlobalNamespace
));
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
);
128 return lhf_Access_Module(nId
);
131 Module
& ret
= *new Module( i_sName
,
133 lhf_Store_NewEntity(ret
, rOwner
);
138 CeAdmin::Store_Service( Ce_id i_nOwner
,
139 const String
& i_sName
)
141 Service
& ret
= *new Service( i_sName
,
143 lhf_Store_NewEntity(ret
, i_nOwner
);
148 CeAdmin::Store_SglIfcService( Ce_id i_nOwner
,
149 const String
& i_sName
,
150 Type_id i_nBaseInterface
)
153 ret
= *new SglIfcService( i_sName
,
156 lhf_Store_NewEntity(ret
, i_nOwner
);
161 CeAdmin::Store_Interface( Ce_id i_nOwner
,
162 const String
& i_sName
,
165 Interface
& ret
= *new Interface( i_sName
,
167 lhf_Store_NewEntity(ret
, i_nOwner
);
168 if (i_nBase
.IsValid())
169 ret
.Add_Base(i_nBase
, 0);
174 CeAdmin::Store_Struct( Ce_id i_nOwner
,
175 const String
& i_sName
,
177 const String
& i_sTemplateParam
)
179 if (NOT i_sTemplateParam
.empty())
181 return lhf_Store_TplStruct( i_nOwner
,
187 Struct
& ret
= *new Struct( i_sName
,
192 lhf_Store_NewEntity(ret
, i_nOwner
);
198 CeAdmin::Store_Exception( Ce_id i_nOwner
,
199 const String
& i_sName
,
202 Exception
& ret
= *new Exception( i_sName
,
205 lhf_Store_NewEntity(ret
, i_nOwner
);
210 CeAdmin::Store_Enum( Ce_id i_nOwner
,
211 const String
& i_sName
)
213 Enum
& ret
= *new Enum( i_sName
,
215 lhf_Store_NewEntity(ret
, i_nOwner
);
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
,
227 lhf_Store_NewEntity(ret
, i_nOwner
);
233 CeAdmin::Store_ConstantsGroup( Ce_id i_nOwner
,
234 const String
& i_sName
)
236 ConstantsGroup
& ret
= *new ConstantsGroup( i_sName
,
238 lhf_Store_NewEntity(ret
, i_nOwner
);
243 CeAdmin::Store_Singleton( Ce_id i_nOwner
,
244 const String
& i_sName
)
246 Singleton
& ret
= *new Singleton( i_sName
,
248 lhf_Store_NewEntity(ret
, i_nOwner
);
253 CeAdmin::Store_SglIfcSingleton( Ce_id i_nOwner
,
254 const String
& i_sName
,
255 Type_id i_nBaseInterface
)
258 ret
= *new SglIfcSingleton( i_sName
,
261 lhf_Store_NewEntity(ret
, i_nOwner
);
266 CeAdmin::Store_Constant( Ce_id i_nOwner
,
267 const String
& i_sName
,
269 const String
& i_sValue
)
272 rOwner
= ary_cast
<ConstantsGroup
>(Storage()[i_nOwner
]);
273 Constant
& ret
= *new Constant( i_sName
,
278 lhf_Put2Storage_and_AssignId(ret
);
279 rOwner
.Add_Constant(ret
.CeId());
284 CeAdmin::Store_Property( Ce_id i_nOwner
,
285 const String
& i_sName
,
287 Property::Stereotypes i_stereotypes
)
290 rOwner
= ary_cast
<Service
>(Storage()[i_nOwner
]);
291 Property
& ret
= *new Property( i_sName
,
296 lhf_Put2Storage_and_AssignId(ret
);
297 rOwner
.Add_Property(ret
.CeId());
302 CeAdmin::Store_Function( Ce_id i_nOwner
,
303 const String
& i_sName
,
304 Type_id i_nReturnType
,
308 rOwner
= ary_cast
<Interface
>(Storage()[i_nOwner
]);
309 Function
& ret
= *new Function( i_sName
,
314 lhf_Put2Storage_and_AssignId(ret
);
315 rOwner
.Add_Function(ret
.CeId());
320 CeAdmin::Store_ServiceConstructor( Ce_id i_nOwner
,
321 const String
& i_sName
)
324 rOwner
= ary_cast
<SglIfcService
>(Storage()[i_nOwner
]);
325 Function
& ret
= *new Function( i_sName
,
328 lhf_Put2Storage_and_AssignId(ret
);
329 rOwner
.Add_Constructor(ret
.CeId());
334 CeAdmin::Store_StructMember( Ce_id i_nOwner
,
335 const String
& i_sName
,
339 rOwner
= ary_cast
<Struct
>(Storage()[i_nOwner
]);
340 StructElement
& ret
= *new StructElement( i_sName
,
344 lhf_Put2Storage_and_AssignId(ret
);
345 rOwner
.Add_Member(ret
.CeId());
350 CeAdmin::Store_ExceptionMember( Ce_id i_nOwner
,
351 const String
& i_sName
,
355 rOwner
= ary_cast
<Exception
>(Storage()[i_nOwner
]);
356 StructElement
& ret
= *new StructElement( i_sName
,
360 lhf_Put2Storage_and_AssignId(ret
);
361 rOwner
.Add_Member(ret
.CeId());
366 CeAdmin::Store_EnumValue( Ce_id i_nOwner
,
367 const String
& i_sName
,
368 const String
& i_sValue
)
371 rOwner
= ary_cast
<Enum
>(Storage()[i_nOwner
]);
372 EnumValue
& ret
= *new EnumValue( i_sName
,
376 lhf_Put2Storage_and_AssignId(ret
);
377 rOwner
.Add_Value(ret
.CeId());
382 CeAdmin::Store_Attribute( Ce_id i_nOwner
,
383 const String
& i_sName
,
389 rOwner
= ary_cast
<Interface
>(Storage()[i_nOwner
]);
391 Attribute
& ret
= *new Attribute ( i_sName
,
397 lhf_Put2Storage_and_AssignId(ret
);
398 rOwner
.Add_Attribute(ret
.CeId());
403 CeAdmin::GlobalNamespace() const
405 csv_assert(pGlobalNamespace
);
406 return *pGlobalNamespace
;
410 CeAdmin::Find_Ce( Ce_id i_nId
) const
412 return Storage()[i_nId
];
417 CeAdmin::Find_Module( Ce_id i_nId
) const
419 return ary_cast
<Module
>(Storage()[i_nId
]);
423 CeAdmin::Search_Module( Ce_id i_nId
) const
425 if (NOT i_nId
.IsValid())
427 return ary_cast
<Module
>( & Storage()[i_nId
] );
431 CeAdmin::Find_Function( Ce_id i_nId
) const
433 return ary_cast
<Function
>(Storage()[i_nId
]);
437 CeAdmin::Find_Property( Ce_id i_nId
) const
439 return ary_cast
<Property
>(Storage()[i_nId
]);
443 CeAdmin::Find_EnumValue( Ce_id i_nId
) const
445 return ary_cast
<EnumValue
>(Storage()[i_nId
]);
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
]);
461 CeAdmin::Get_Text( StringVector
& o_module
,
464 const CodeEntity
& i_ce
) const
466 const CodeEntity
* pCe
= &i_ce
;
467 csv::erase_container(o_module
);
471 switch ( pCe
->SightLevel() )
473 // Here are intentionally no breaks!
475 if ( is_type
<Function
>(*pCe
) )
476 o_member
= StreamLock(200)()
481 o_member
= pCe
->LocalName();
482 pCe
= & Storage()[pCe
->Owner()];
484 o_ce
= pCe
->LocalName();
485 pCe
= & Storage()[pCe
->NameRoom()];
487 get_ModuleText(o_module
,*pCe
);
495 CeAdmin::NameDictionary() const
497 return *pNameDictionary
;
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:
510 UINT8 nLetter
= static_cast<UINT8
>(i_cLetter
);
511 memset(filter
, 0, 256);
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();
524 if ( filter
[ static_cast<UINT8
>(*(*it
).LocalName().c_str()) ] == 1 )
525 o_rResult
.push_back( (*it
).CeId() );
528 std::sort( o_rResult
.begin(),
530 IdSorter
<Ce_Compare
>() );
535 CeAdmin::GlobalNamespace()
537 csv_assert(pGlobalNamespace
);
538 return *pGlobalNamespace
;
542 CeAdmin::Find_Ce( Ce_id i_nId
)
544 return Storage()[i_nId
];
548 CeAdmin::get_ModuleText( StringVector
& o_module
,
549 const CodeEntity
& i_ce
) const
551 if (i_ce
.NameRoom().IsValid())
554 rParent
= Storage()[i_ce
.NameRoom()];
555 get_ModuleText(o_module
, rParent
);
556 o_module
.push_back(i_ce
.LocalName());
561 CeAdmin::lhf_Store_TplStruct( Ce_id i_nOwner
,
562 const String
& i_sName
,
564 const String
& i_sTemplateParam
)
566 csv_assert(NOT i_sTemplateParam
.empty());
569 rTpt
= pTypePilot
->Store_TemplateParamType(i_sTemplateParam
);
571 Struct
& ret
= *new Struct( i_sName
,
576 lhf_Store_NewEntity(ret
, i_nOwner
);
577 rTpt
.Set_StructId(ret
.CeId());