1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
24 // NOT FULLY DEFINED SERVICES
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>
47 #include "ia_type.hxx"
49 #include "it_tplparam.hxx"
60 CeAdmin::lhf_Access_Module( Ce_id i_nId
)
61 { return ary_cast
<Module
>(Storage()[i_nId
]); }
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(),
69 pass_io_rCe
.AryClass(),
70 pass_io_rCe
.Owner() );
74 CeAdmin::lhf_Store_NewEntity( DYN CodeEntity
& pass_io_rCe
,
77 lhf_Put2Storage_and_AssignId(pass_io_rCe
);
78 i_rOwner
.Add_Name(pass_io_rCe
.LocalName(), pass_io_rCe
.CeId());
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
),
94 pNameDictionary(&io_rNameDictionary
),
95 pTypePilot(&io_rTypePilot
)
97 Storage().Set_Reserved(
98 predefined::ce_GlobalNamespace
,
100 pGlobalNamespace
= &lhf_Access_Module(Ce_id(predefined::ce_GlobalNamespace
));
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
);
117 return lhf_Access_Module(nId
);
120 Module
& ret
= *new Module( i_sName
,
122 lhf_Store_NewEntity(ret
, rOwner
);
127 CeAdmin::Store_Service( Ce_id i_nOwner
,
128 const String
& i_sName
)
130 Service
& ret
= *new Service( i_sName
,
132 lhf_Store_NewEntity(ret
, i_nOwner
);
137 CeAdmin::Store_SglIfcService( Ce_id i_nOwner
,
138 const String
& i_sName
,
139 Type_id i_nBaseInterface
)
142 ret
= *new SglIfcService( i_sName
,
145 lhf_Store_NewEntity(ret
, i_nOwner
);
150 CeAdmin::Store_Interface( Ce_id i_nOwner
,
151 const String
& i_sName
,
154 Interface
& ret
= *new Interface( i_sName
,
156 lhf_Store_NewEntity(ret
, i_nOwner
);
157 if (i_nBase
.IsValid())
158 ret
.Add_Base(i_nBase
, 0);
163 CeAdmin::Store_Struct( Ce_id i_nOwner
,
164 const String
& i_sName
,
166 const String
& i_sTemplateParam
)
168 if (NOT i_sTemplateParam
.empty())
170 return lhf_Store_TplStruct( i_nOwner
,
176 Struct
& ret
= *new Struct( i_sName
,
181 lhf_Store_NewEntity(ret
, i_nOwner
);
187 CeAdmin::Store_Exception( Ce_id i_nOwner
,
188 const String
& i_sName
,
191 Exception
& ret
= *new Exception( i_sName
,
194 lhf_Store_NewEntity(ret
, i_nOwner
);
199 CeAdmin::Store_Enum( Ce_id i_nOwner
,
200 const String
& i_sName
)
202 Enum
& ret
= *new Enum( i_sName
,
204 lhf_Store_NewEntity(ret
, i_nOwner
);
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
,
216 lhf_Store_NewEntity(ret
, i_nOwner
);
222 CeAdmin::Store_ConstantsGroup( Ce_id i_nOwner
,
223 const String
& i_sName
)
225 ConstantsGroup
& ret
= *new ConstantsGroup( i_sName
,
227 lhf_Store_NewEntity(ret
, i_nOwner
);
232 CeAdmin::Store_Singleton( Ce_id i_nOwner
,
233 const String
& i_sName
)
235 Singleton
& ret
= *new Singleton( i_sName
,
237 lhf_Store_NewEntity(ret
, i_nOwner
);
242 CeAdmin::Store_SglIfcSingleton( Ce_id i_nOwner
,
243 const String
& i_sName
,
244 Type_id i_nBaseInterface
)
247 ret
= *new SglIfcSingleton( i_sName
,
250 lhf_Store_NewEntity(ret
, i_nOwner
);
255 CeAdmin::Store_Constant( Ce_id i_nOwner
,
256 const String
& i_sName
,
258 const String
& i_sValue
)
261 rOwner
= ary_cast
<ConstantsGroup
>(Storage()[i_nOwner
]);
262 Constant
& ret
= *new Constant( i_sName
,
267 lhf_Put2Storage_and_AssignId(ret
);
268 rOwner
.Add_Constant(ret
.CeId());
273 CeAdmin::Store_Property( Ce_id i_nOwner
,
274 const String
& i_sName
,
276 Property::Stereotypes i_stereotypes
)
279 rOwner
= ary_cast
<Service
>(Storage()[i_nOwner
]);
280 Property
& ret
= *new Property( i_sName
,
285 lhf_Put2Storage_and_AssignId(ret
);
286 rOwner
.Add_Property(ret
.CeId());
291 CeAdmin::Store_Function( Ce_id i_nOwner
,
292 const String
& i_sName
,
293 Type_id i_nReturnType
,
297 rOwner
= ary_cast
<Interface
>(Storage()[i_nOwner
]);
298 Function
& ret
= *new Function( i_sName
,
303 lhf_Put2Storage_and_AssignId(ret
);
304 rOwner
.Add_Function(ret
.CeId());
309 CeAdmin::Store_ServiceConstructor( Ce_id i_nOwner
,
310 const String
& i_sName
)
313 rOwner
= ary_cast
<SglIfcService
>(Storage()[i_nOwner
]);
314 Function
& ret
= *new Function( i_sName
,
317 lhf_Put2Storage_and_AssignId(ret
);
318 rOwner
.Add_Constructor(ret
.CeId());
323 CeAdmin::Store_StructMember( Ce_id i_nOwner
,
324 const String
& i_sName
,
328 rOwner
= ary_cast
<Struct
>(Storage()[i_nOwner
]);
329 StructElement
& ret
= *new StructElement( i_sName
,
333 lhf_Put2Storage_and_AssignId(ret
);
334 rOwner
.Add_Member(ret
.CeId());
339 CeAdmin::Store_ExceptionMember( Ce_id i_nOwner
,
340 const String
& i_sName
,
344 rOwner
= ary_cast
<Exception
>(Storage()[i_nOwner
]);
345 StructElement
& ret
= *new StructElement( i_sName
,
349 lhf_Put2Storage_and_AssignId(ret
);
350 rOwner
.Add_Member(ret
.CeId());
355 CeAdmin::Store_EnumValue( Ce_id i_nOwner
,
356 const String
& i_sName
,
357 const String
& i_sValue
)
360 rOwner
= ary_cast
<Enum
>(Storage()[i_nOwner
]);
361 EnumValue
& ret
= *new EnumValue( i_sName
,
365 lhf_Put2Storage_and_AssignId(ret
);
366 rOwner
.Add_Value(ret
.CeId());
371 CeAdmin::Store_Attribute( Ce_id i_nOwner
,
372 const String
& i_sName
,
378 rOwner
= ary_cast
<Interface
>(Storage()[i_nOwner
]);
380 Attribute
& ret
= *new Attribute ( i_sName
,
386 lhf_Put2Storage_and_AssignId(ret
);
387 rOwner
.Add_Attribute(ret
.CeId());
392 CeAdmin::GlobalNamespace() const
394 csv_assert(pGlobalNamespace
);
395 return *pGlobalNamespace
;
399 CeAdmin::Find_Ce( Ce_id i_nId
) const
401 return Storage()[i_nId
];
406 CeAdmin::Find_Module( Ce_id i_nId
) const
408 return ary_cast
<Module
>(Storage()[i_nId
]);
412 CeAdmin::Search_Module( Ce_id i_nId
) const
414 if (NOT i_nId
.IsValid())
416 return ary_cast
<Module
>( & Storage()[i_nId
] );
420 CeAdmin::Find_Function( Ce_id i_nId
) const
422 return ary_cast
<Function
>(Storage()[i_nId
]);
426 CeAdmin::Find_Property( Ce_id i_nId
) const
428 return ary_cast
<Property
>(Storage()[i_nId
]);
432 CeAdmin::Find_EnumValue( Ce_id i_nId
) const
434 return ary_cast
<EnumValue
>(Storage()[i_nId
]);
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
]);
450 CeAdmin::Get_Text( StringVector
& o_module
,
453 const CodeEntity
& i_ce
) const
455 const CodeEntity
* pCe
= &i_ce
;
456 csv::erase_container(o_module
);
460 switch ( pCe
->SightLevel() )
462 // Here are intentionally no breaks!
464 if ( is_type
<Function
>(*pCe
) )
465 o_member
= StreamLock(200)()
470 o_member
= pCe
->LocalName();
471 pCe
= & Storage()[pCe
->Owner()];
473 o_ce
= pCe
->LocalName();
474 pCe
= & Storage()[pCe
->NameRoom()];
476 get_ModuleText(o_module
,*pCe
);
484 CeAdmin::NameDictionary() const
486 return *pNameDictionary
;
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:
499 UINT8 nLetter
= static_cast<UINT8
>(i_cLetter
);
500 memset(filter
, 0, 256);
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();
513 if ( filter
[ static_cast<UINT8
>(*(*it
).LocalName().c_str()) ] == 1 )
514 o_rResult
.push_back( (*it
).CeId() );
517 std::sort( o_rResult
.begin(),
519 IdSorter
<Ce_Compare
>() );
524 CeAdmin::GlobalNamespace()
526 csv_assert(pGlobalNamespace
);
527 return *pGlobalNamespace
;
531 CeAdmin::Find_Ce( Ce_id i_nId
)
533 return Storage()[i_nId
];
537 CeAdmin::get_ModuleText( StringVector
& o_module
,
538 const CodeEntity
& i_ce
) const
540 if (i_ce
.NameRoom().IsValid())
543 rParent
= Storage()[i_ce
.NameRoom()];
544 get_ModuleText(o_module
, rParent
);
545 o_module
.push_back(i_ce
.LocalName());
550 CeAdmin::lhf_Store_TplStruct( Ce_id i_nOwner
,
551 const String
& i_sName
,
553 const String
& i_sTemplateParam
)
555 csv_assert(NOT i_sTemplateParam
.empty());
558 rTpt
= pTypePilot
->Store_TemplateParamType(i_sTemplateParam
);
560 Struct
& ret
= *new Struct( i_sName
,
565 lhf_Store_NewEntity(ret
, i_nOwner
);
566 rTpt
.Set_StructId(ret
.CeId());
575 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */