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: c_reposypart.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 ************************************************************************/
32 #include "c_reposypart.hxx"
35 // NOT FULLY DECLARED SERVICES
36 #include <ary/getncast.hxx>
37 #include <ary/namesort.hxx>
38 #include <ary/cpp/c_builtintype.hxx>
39 #include <ary/cpp/c_class.hxx>
40 #include <ary/cpp/c_cppentity.hxx>
41 #include <ary/cpp/c_define.hxx>
42 #include <ary/cpp/c_enum.hxx>
43 #include <ary/cpp/c_enuval.hxx>
44 #include <ary/cpp/c_funct.hxx>
45 #include <ary/cpp/c_macro.hxx>
46 #include <ary/cpp/c_namesp.hxx>
47 #include <ary/cpp/c_tydef.hxx>
48 #include <ary/cpp/c_type.hxx>
49 #include <ary/cpp/usedtype.hxx>
50 #include <ary/cpp/c_vari.hxx>
51 #include <ary/loc/locp_le.hxx>
52 #include <ary/getncast.hxx>
53 #include <loc_internalgate.hxx>
57 #include "ca_type.hxx"
60 #include "cs_type.hxx"
67 using ::ary::GlobalId
;
69 using namespace ::ary::cpp
;
73 IsDefine( const GlobalId
& i_id
)
75 return i_id
.Class() == Define::class_id
77 i_id
.Class() == Macro::class_id
;
91 Type
& io_rType
) const;
97 /// Find Ces only known from base class name scope.
98 class TypeConnector2ndTry
104 ~TypeConnector2ndTry() {}
107 Type
& io_rType
) const;
113 /// Reconnect (in both directions) base-derived relations of classes.
114 class HierarchyLinker
121 ~HierarchyLinker() {}
124 Class
& io_rCe
) const;
132 /// Helper functor for ->RepositoryPartition::Get_AlphabeticalList().
133 template <class TRAITS
>
137 typename
TRAITS::id_type
140 return GlobalId( TRAITS::EntityOf_(i_id
).AryClass(),
148 /** Compare two {->GlobalId}s.
151 @todo Move this up to the definition of GlobalId<>.
156 const Ce_Storage
& i_ces
,
157 const Def_Storage
& i_des
)
158 : rCes(i_ces
), rDes(i_des
) {}
162 GlobalId i_2
) const;
165 const String
& NameOf(
166 GlobalId i_id
) const;
168 const Ce_Storage
& rCes
;
169 const Def_Storage
& rDes
;
170 ::ary::LesserName aLess
;
175 LesserGlobal::operator()( GlobalId i_1
,
178 String s1
= NameOf(i_1
);
179 String s2
= NameOf(i_2
);
182 return aLess(s1
, s2
);
184 if ( IsDefine(i_1
) != IsDefine(i_2
) )
186 return NOT
IsDefine(i_2
);
188 else if (IsDefine(i_1
))
190 return i_1
.Class() < i_2
.Class();
193 return Ce_GlobalCompare::Lesser_(
199 } // namespace anonymous
212 InternalGate::Create_Partition_(RepositoryCenter
& i_center
)
214 return *new RepositoryPartition(i_center
);
218 RepositoryPartition::RepositoryPartition(RepositoryCenter
& i_center
)
219 : pRepositoryCenter(&i_center
),
223 pLocations(& loc::InternalGate::Create_Locations_())
225 pCes
= new CeAdmin(*this);
226 pTypes
= new TypeAdmin(*this);
227 pDefs
= new DefAdmin(*this);
228 pCes
->Set_Related(*pTypes
);
231 RepositoryPartition::~RepositoryPartition()
236 RepositoryPartition::Calculate_AllSecondaryInformation()
237 // const ::autodoc::Options & )
240 // Forward the options from here.
242 Connect_AllTypes_2_TheirRelated_CodeEntites();
246 RepositoryPartition::RepositoryTitle() const
248 return static_cast< ary::Repository
* >(pRepositoryCenter
)->Title();
252 RepositoryPartition::Search_RelatedCe(Type_id i_type
) const
254 if (NOT i_type
.IsValid())
258 ce_id
= pTypes
->Find_Type(i_type
).RelatedCe();
259 return ce_id
.IsValid()
260 ? & pCes
->Find_Ce(ce_id
)
264 const ::ary::cpp::CppEntity
*
265 RepositoryPartition::Search_Entity(GlobalId i_id
) const
270 if ( NOT
IsDefine(i_id
) )
272 // Shall make sure this is a C++ CodeEntity:
273 csv_assert( i_id
.Class() >= Namespace::class_id
275 i_id
.Class() < BuiltInType::class_id
276 && "Unexpected entity type in cpp::RepositoryPartition"
277 "::Search_Entity()." );
278 return & Ces().Find_Ce( Ce_id(i_id
.Id()) );
282 return & Defs().Find_Def( De_id(i_id
.Id()) );
288 RepositoryPartition::Ces() const
290 csv_assert(pCes
!= 0);
295 RepositoryPartition::Defs() const
297 csv_assert(pDefs
!= 0);
302 RepositoryPartition::Types() const
304 csv_assert(pTypes
!= 0);
308 const loc::LocationPilot
&
309 RepositoryPartition::Locations() const
311 csv_assert(pLocations
!= 0);
316 RepositoryPartition::Ces()
318 csv_assert(pCes
!= 0);
323 RepositoryPartition::Defs()
325 csv_assert(pDefs
!= 0);
330 RepositoryPartition::Types()
332 csv_assert(pTypes
!= 0);
337 RepositoryPartition::Locations()
339 csv_assert(pLocations
!= 0);
345 RepositoryPartition::Connect_AllTypes_2_TheirRelated_CodeEntites()
349 std::for_each( pTypes
->Storage().BeginUnreserved(),
350 pTypes
->Storage().End(),
353 typedef ::ary::stg::filter_iterator
<CodeEntity
,Class
>
357 aHierarchyLinker(*this);
358 filter_class_iter
itEnd( pCes
->Storage().End() );
359 for ( filter_class_iter
it( pCes
->Storage().BeginUnreserved() );
363 if (NOT it
.IsValid())
366 if (is_type
<Class
>(*it
))
367 aHierarchyLinker(ary_cast
<Class
>(*it
));
371 aConnector2ndTry(*this);
372 std::for_each( pTypes
->Storage().BeginUnreserved(),
373 pTypes
->Storage().End(),
377 template <class COMPARE
>
379 List_GlobalIds
& o_result
,
380 const SortedIds
<COMPARE
> &
382 const char * i_begin
,
383 const char * i_end
);
384 template <class COMPARE
>
386 Add2Result( List_GlobalIds
& o_result
,
387 const SortedIds
<COMPARE
> & i_data
,
388 const char * i_begin
,
392 previous_size
= o_result
.size();
393 typename
std::vector
<typename
COMPARE::id_type
>::const_iterator
394 it_beg
= i_data
.LowerBound(i_begin
);
395 typename
std::vector
<typename
COMPARE::id_type
>::const_iterator
396 it_end
= i_data
.LowerBound(i_end
);
398 count_added
= static_cast<size_t>( std::distance(it_beg
,it_end
) );
399 o_result
.insert( o_result
.end(),
402 List_GlobalIds::iterator
403 it_out
= o_result
.begin() + previous_size
;
404 std::transform( it_beg
, it_end
,
406 MakeGlobalId
<COMPARE
>() );
411 RepositoryPartition::Get_AlphabeticalList( List_GlobalIds
& o_result
,
412 const char * i_begin
,
413 const char * i_end
) const
416 ret
= o_result
.size();
419 ce_storage
= pCes
->Storage();
421 def_storage
= pDefs
->Storage();
423 Add2Result( o_result
,
424 ce_storage
.TypeIndex(),
426 Add2Result( o_result
,
427 ce_storage
.OperationIndex(),
429 Add2Result( o_result
,
430 ce_storage
.DataIndex(),
432 Add2Result( o_result
,
433 def_storage
.DefineIndex(),
435 Add2Result( o_result
,
436 def_storage
.MacroIndex(),
440 aLess(ce_storage
, def_storage
);
442 std::sort(o_result
.begin(), o_result
.end(), aLess
);
444 return o_result
.size() - ret
;
462 TypeConnector::operator()( Type
& io_rType
) const
464 csv_assert(pGate
!= 0);
466 pt
= ::ary::ary_cast
<UsedType
>(&io_rType
);
468 pt
->Connect2Ce(pGate
->Ces());
472 TypeConnector2ndTry::operator()( Type
& io_rType
) const
474 csv_assert(pGate
!= 0);
476 pt
= ::ary::ary_cast
<UsedType
>(&io_rType
);
478 pt
->Connect2CeOnlyKnownViaBaseClass(*pGate
);
482 HierarchyLinker::operator()( Class
& io_rCe
) const
484 csv_assert( ::ary::is_type
<Class
>(io_rCe
) );
488 for ( List_Bases::const_iterator it
= rClass
.BaseClasses().begin();
489 it
!= rClass
.BaseClasses().end();
496 for ( pCe
= pGate
->Search_RelatedCe(nTid
);
497 ary::ary_cast
<Typedef
>(pCe
) != 0;
498 pCe
= pGate
->Search_RelatedCe(nTid
) )
500 nTid
= static_cast< const Typedef
* >(pCe
)->DescribingType();
503 pClass
= ary::ary_cast
<Class
>(pCe
);
506 // KORR_FUTURE: we need a non const Find_Class()
507 const_cast< Class
* >(pClass
)->Add_KnownDerivative( io_rCe
.CeId() );
512 LesserGlobal::NameOf(GlobalId i_id
) const
514 if ( NOT
IsDefine(i_id
) )
516 return rCes
[i_id
.Id()].LocalName();
520 return rDes
[i_id
.Id()].LocalName();
526 } // namespace anonymous