Update ooo320-m1
[ooovba.git] / autodoc / source / ary / cpp / c_reposypart.cxx
blob294dffe3c009ca741bdf0a8de038554d0477f569
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: c_reposypart.cxx,v $
10 * $Revision: 1.6 $
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 "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>
54 #include <reposy.hxx>
55 #include "ca_ce.hxx"
56 #include "ca_def.hxx"
57 #include "ca_type.hxx"
58 #include "cs_ce.hxx"
59 #include "cs_def.hxx"
60 #include "cs_type.hxx"
64 namespace
67 using ::ary::GlobalId;
68 using ::ary::Rid;
69 using namespace ::ary::cpp;
72 inline bool
73 IsDefine( const GlobalId & i_id )
75 return i_id.Class() == Define::class_id
77 i_id.Class() == Macro::class_id;
81 /// Find Ces
82 class TypeConnector
84 public:
85 TypeConnector(
86 Gate & i_gate )
87 : pGate(&i_gate) {}
88 ~TypeConnector() {}
90 void operator()(
91 Type & io_rType ) const;
92 private:
93 // DATA
94 Gate * pGate;
97 /// Find Ces only known from base class name scope.
98 class TypeConnector2ndTry
100 public:
101 TypeConnector2ndTry(
102 Gate & i_gate )
103 : pGate(&i_gate) {}
104 ~TypeConnector2ndTry() {}
106 void operator()(
107 Type & io_rType ) const;
108 private:
109 // DATA
110 Gate * pGate;
113 /// Reconnect (in both directions) base-derived relations of classes.
114 class HierarchyLinker
116 public:
117 HierarchyLinker(
118 Gate & i_gate )
119 : pGate(&i_gate) {}
121 ~HierarchyLinker() {}
123 void operator()(
124 Class & io_rCe ) const;
125 private:
126 // DATA
127 Gate * pGate;
132 /// Helper functor for ->RepositoryPartition::Get_AlphabeticalList().
133 template <class TRAITS>
134 struct MakeGlobalId
136 GlobalId operator()(
137 typename TRAITS::id_type
138 i_id ) const
140 return GlobalId( TRAITS::EntityOf_(i_id).AryClass(),
141 i_id.Value() );
148 /** Compare two {->GlobalId}s.
151 @todo Move this up to the definition of GlobalId<>.
153 struct LesserGlobal
155 LesserGlobal(
156 const Ce_Storage & i_ces,
157 const Def_Storage & i_des )
158 : rCes(i_ces), rDes(i_des) {}
160 bool operator()(
161 GlobalId i_1,
162 GlobalId i_2 ) const;
164 private:
165 const String & NameOf(
166 GlobalId i_id ) const;
167 // DATA
168 const Ce_Storage & rCes;
169 const Def_Storage & rDes;
170 ::ary::LesserName aLess;
174 bool
175 LesserGlobal::operator()( GlobalId i_1,
176 GlobalId i_2 ) const
178 String s1 = NameOf(i_1);
179 String s2 = NameOf(i_2);
181 if (s1 != s2)
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_(
194 rCes[i_1.Id()],
195 rCes[i_2.Id()] );
199 } // namespace anonymous
206 namespace ary
208 namespace cpp
211 DYN InternalGate &
212 InternalGate::Create_Partition_(RepositoryCenter & i_center)
214 return *new RepositoryPartition(i_center);
218 RepositoryPartition::RepositoryPartition(RepositoryCenter & i_center)
219 : pRepositoryCenter(&i_center),
220 pCes(0),
221 pTypes(0),
222 pDefs(0),
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()
235 void
236 RepositoryPartition::Calculate_AllSecondaryInformation()
237 // const ::autodoc::Options & )
239 // KORR_FUTURE
240 // Forward the options from here.
242 Connect_AllTypes_2_TheirRelated_CodeEntites();
245 const String &
246 RepositoryPartition::RepositoryTitle() const
248 return static_cast< ary::Repository* >(pRepositoryCenter)->Title();
251 const CodeEntity *
252 RepositoryPartition::Search_RelatedCe(Type_id i_type) const
254 if (NOT i_type.IsValid())
255 return 0;
257 Ce_id
258 ce_id = pTypes->Find_Type(i_type).RelatedCe();
259 return ce_id.IsValid()
260 ? & pCes->Find_Ce(ce_id)
261 : (CodeEntity*)(0);
264 const ::ary::cpp::CppEntity *
265 RepositoryPartition::Search_Entity(GlobalId i_id) const
267 if (i_id.Id() == 0)
268 return 0;
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()) );
280 else
282 return & Defs().Find_Def( De_id(i_id.Id()) );
287 const CePilot &
288 RepositoryPartition::Ces() const
290 csv_assert(pCes != 0);
291 return *pCes;
294 const DefPilot &
295 RepositoryPartition::Defs() const
297 csv_assert(pDefs != 0);
298 return *pDefs;
301 const TypePilot &
302 RepositoryPartition::Types() const
304 csv_assert(pTypes != 0);
305 return *pTypes;
308 const loc::LocationPilot &
309 RepositoryPartition::Locations() const
311 csv_assert(pLocations != 0);
312 return *pLocations;
315 CePilot &
316 RepositoryPartition::Ces()
318 csv_assert(pCes != 0);
319 return *pCes;
322 DefPilot &
323 RepositoryPartition::Defs()
325 csv_assert(pDefs != 0);
326 return *pDefs;
329 TypePilot &
330 RepositoryPartition::Types()
332 csv_assert(pTypes != 0);
333 return *pTypes;
336 loc::LocationPilot &
337 RepositoryPartition::Locations()
339 csv_assert(pLocations != 0);
340 return *pLocations;
344 void
345 RepositoryPartition::Connect_AllTypes_2_TheirRelated_CodeEntites()
347 TypeConnector
348 aConnector(*this);
349 std::for_each( pTypes->Storage().BeginUnreserved(),
350 pTypes->Storage().End(),
351 aConnector );
353 typedef ::ary::stg::filter_iterator<CodeEntity,Class>
354 filter_class_iter;
356 HierarchyLinker
357 aHierarchyLinker(*this);
358 filter_class_iter itEnd( pCes->Storage().End() );
359 for ( filter_class_iter it( pCes->Storage().BeginUnreserved() );
360 it != itEnd;
361 ++it )
363 if (NOT it.IsValid())
364 continue;
366 if (is_type<Class>(*it))
367 aHierarchyLinker(ary_cast<Class>(*it));
370 TypeConnector2ndTry
371 aConnector2ndTry(*this);
372 std::for_each( pTypes->Storage().BeginUnreserved(),
373 pTypes->Storage().End(),
374 aConnector2ndTry );
377 template <class COMPARE>
378 void Add2Result(
379 List_GlobalIds & o_result,
380 const SortedIds<COMPARE> &
381 i_data,
382 const char * i_begin,
383 const char * i_end );
384 template <class COMPARE>
385 void
386 Add2Result( List_GlobalIds & o_result,
387 const SortedIds<COMPARE> & i_data,
388 const char * i_begin,
389 const char * i_end )
391 const size_t
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);
397 size_t
398 count_added = static_cast<size_t>( std::distance(it_beg,it_end) );
399 o_result.insert( o_result.end(),
400 count_added,
401 GlobalId() );
402 List_GlobalIds::iterator
403 it_out = o_result.begin() + previous_size;
404 std::transform( it_beg, it_end,
405 it_out,
406 MakeGlobalId<COMPARE>() );
410 uintt
411 RepositoryPartition::Get_AlphabeticalList( List_GlobalIds & o_result,
412 const char * i_begin,
413 const char * i_end ) const
415 size_t
416 ret = o_result.size();
418 const Ce_Storage &
419 ce_storage = pCes->Storage();
420 const Def_Storage &
421 def_storage = pDefs->Storage();
423 Add2Result( o_result,
424 ce_storage.TypeIndex(),
425 i_begin, i_end );
426 Add2Result( o_result,
427 ce_storage.OperationIndex(),
428 i_begin, i_end );
429 Add2Result( o_result,
430 ce_storage.DataIndex(),
431 i_begin, i_end );
432 Add2Result( o_result,
433 def_storage.DefineIndex(),
434 i_begin, i_end );
435 Add2Result( o_result,
436 def_storage.MacroIndex(),
437 i_begin, i_end );
439 LesserGlobal
440 aLess(ce_storage, def_storage);
442 std::sort(o_result.begin(), o_result.end(), aLess);
444 return o_result.size() - ret;
450 } // namespace cpp
451 } // namespace ary
457 namespace
461 void
462 TypeConnector::operator()( Type & io_rType ) const
464 csv_assert(pGate != 0);
465 UsedType *
466 pt = ::ary::ary_cast<UsedType>(&io_rType);
467 if (pt != 0)
468 pt->Connect2Ce(pGate->Ces());
471 void
472 TypeConnector2ndTry::operator()( Type & io_rType ) const
474 csv_assert(pGate != 0);
475 UsedType *
476 pt = ::ary::ary_cast<UsedType>(&io_rType);
477 if (pt != 0)
478 pt->Connect2CeOnlyKnownViaBaseClass(*pGate);
481 void
482 HierarchyLinker::operator()( Class & io_rCe ) const
484 csv_assert( ::ary::is_type<Class>(io_rCe) );
485 Class &
486 rClass = io_rCe;
488 for ( List_Bases::const_iterator it = rClass.BaseClasses().begin();
489 it != rClass.BaseClasses().end();
490 ++it )
492 const CodeEntity *
493 pCe = 0;
494 Type_id
495 nTid = (*it).nId;
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();
502 const Class *
503 pClass = ary::ary_cast<Class>(pCe);
504 if (pClass == 0)
505 return;
506 // KORR_FUTURE: we need a non const Find_Class()
507 const_cast< Class* >(pClass)->Add_KnownDerivative( io_rCe.CeId() );
511 const String &
512 LesserGlobal::NameOf(GlobalId i_id) const
514 if ( NOT IsDefine(i_id) )
516 return rCes[i_id.Id()].LocalName();
518 else
520 return rDes[i_id.Id()].LocalName();
526 } // namespace anonymous