xref: /aoo41x/main/autodoc/source/ary/cpp/c_traits.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <precomp.h>
29*cdf0e10cSrcweir #include <ary/cpp/c_traits.hxx>
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
33*cdf0e10cSrcweir #include <ary/namesort.hxx>
34*cdf0e10cSrcweir #include <ary/cpp/c_class.hxx>
35*cdf0e10cSrcweir #include <ary/cpp/c_enuval.hxx>
36*cdf0e10cSrcweir #include <ary/cpp/c_namesp.hxx>
37*cdf0e10cSrcweir #include <ary/cpp/usedtype.hxx>
38*cdf0e10cSrcweir #include <ary/getncast.hxx>
39*cdf0e10cSrcweir #include "cs_ce.hxx"
40*cdf0e10cSrcweir #include "cs_def.hxx"
41*cdf0e10cSrcweir #include "cs_type.hxx"
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir namespace ary
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir namespace cpp
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir //********************      Ce_Traits      ********************//
54*cdf0e10cSrcweir Ce_Traits::entity_base_type &
55*cdf0e10cSrcweir Ce_Traits::EntityOf_(id_type i_id)
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir     csv_assert(i_id.IsValid());
58*cdf0e10cSrcweir     return Ce_Storage::Instance_()[i_id];
59*cdf0e10cSrcweir }
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir //********************      CeNode_Traits      ********************//
62*cdf0e10cSrcweir const symtree::Node<CeNode_Traits> *
63*cdf0e10cSrcweir CeNode_Traits::NodeOf_(const entity_base_type & i_entity)
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir     if (is_type<Namespace>(i_entity))
66*cdf0e10cSrcweir         return & ary_cast<Namespace>(i_entity).AsNode();
67*cdf0e10cSrcweir     else if (is_type<Class>(i_entity))
68*cdf0e10cSrcweir         return & ary_cast<Class>(i_entity).AsNode();
69*cdf0e10cSrcweir     return 0;
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir symtree::Node<CeNode_Traits> *
73*cdf0e10cSrcweir CeNode_Traits::NodeOf_(entity_base_type & io_entity)
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir     if (is_type<Namespace>(io_entity))
76*cdf0e10cSrcweir         return & ary_cast<Namespace>(io_entity).AsNode();
77*cdf0e10cSrcweir     else if (is_type<Class>(io_entity))
78*cdf0e10cSrcweir         return & ary_cast<Class>(io_entity).AsNode();
79*cdf0e10cSrcweir     return 0;
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir Ce_Traits::entity_base_type *
83*cdf0e10cSrcweir CeNode_Traits::ParentOf_(const entity_base_type & i_entity)
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     Ce_Traits::id_type
86*cdf0e10cSrcweir         ret = i_entity.Owner();
87*cdf0e10cSrcweir     if (ret.IsValid())
88*cdf0e10cSrcweir     {
89*cdf0e10cSrcweir         if (is_type<EnumValue>(i_entity))
90*cdf0e10cSrcweir         {   // Return not the Enum, but the owner of the Enum:
91*cdf0e10cSrcweir             ret = EntityOf_(ret).Owner();
92*cdf0e10cSrcweir             csv_assert(ret.IsValid());
93*cdf0e10cSrcweir         }
94*cdf0e10cSrcweir         return &EntityOf_(ret);
95*cdf0e10cSrcweir     }
96*cdf0e10cSrcweir     return 0;
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir Ce_id
100*cdf0e10cSrcweir CeNode_Search( const CodeEntity &  i_entity,
101*cdf0e10cSrcweir                const String &      i_localKey )
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir     if (is_type<Namespace>(i_entity))
104*cdf0e10cSrcweir         return ary_cast<Namespace>(i_entity).Search_Child(i_localKey);
105*cdf0e10cSrcweir     else if (is_type<Class>(i_entity))
106*cdf0e10cSrcweir         return ary_cast<Class>(i_entity).Search_Child(i_localKey);
107*cdf0e10cSrcweir     return Ce_id(0);
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir //********************      Ce_Compare      ********************//
114*cdf0e10cSrcweir const Ce_Compare::key_type &
115*cdf0e10cSrcweir Ce_Compare::KeyOf_(const entity_base_type & i_entity)
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir     return i_entity.LocalName();
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir bool
121*cdf0e10cSrcweir Ce_Compare::Lesser_( const key_type &    i_1,
122*cdf0e10cSrcweir                      const key_type &    i_2 )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     static ::ary::LesserName    less_;
125*cdf0e10cSrcweir     return less_(i_1,i_2);
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir //********************      Ce_GlobalCompare      ********************//
130*cdf0e10cSrcweir void
131*cdf0e10cSrcweir Get_Qualified( StreamStr &          o_out,
132*cdf0e10cSrcweir                const CodeEntity &   i_ce )
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir     if (i_ce.LocalName().empty())
135*cdf0e10cSrcweir         return;
136*cdf0e10cSrcweir     if (i_ce.Owner().IsValid())
137*cdf0e10cSrcweir         Get_Qualified(o_out, Ce_Traits::EntityOf_(i_ce.Owner()));
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     o_out << i_ce.LocalName() << "::";
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir bool
144*cdf0e10cSrcweir Ce_GlobalCompare::Lesser_( const key_type &    i_1,
145*cdf0e10cSrcweir                            const key_type &    i_2 )
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     static ::ary::LesserName    less_;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     if (i_1.LocalName() != i_2.LocalName())
150*cdf0e10cSrcweir         return less_(i_1.LocalName(), i_2.LocalName());
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     csv_assert(i_1.Owner().IsValid() AND i_2.Owner().IsValid());
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     static StreamStr
155*cdf0e10cSrcweir         aBuffer1_(300);
156*cdf0e10cSrcweir     static StreamStr
157*cdf0e10cSrcweir         aBuffer2_(300);
158*cdf0e10cSrcweir     aBuffer1_.reset();
159*cdf0e10cSrcweir     aBuffer2_.reset();
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     Get_Qualified(aBuffer1_, Ce_Traits::EntityOf_(i_1.Owner()));
162*cdf0e10cSrcweir     Get_Qualified(aBuffer2_, Ce_Traits::EntityOf_(i_2.Owner()));
163*cdf0e10cSrcweir     if (aBuffer1_.size() >= 2)
164*cdf0e10cSrcweir         aBuffer1_.pop_back(2);
165*cdf0e10cSrcweir     if (aBuffer2_.size() >= 2)
166*cdf0e10cSrcweir         aBuffer2_.pop_back(2);
167*cdf0e10cSrcweir     return less_(aBuffer1_.c_str(), aBuffer2_.c_str());
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir //********************      Def_Traits      ********************//
173*cdf0e10cSrcweir Def_Traits::entity_base_type &
174*cdf0e10cSrcweir Def_Traits::EntityOf_(id_type i_id)
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir     csv_assert(i_id.IsValid());
177*cdf0e10cSrcweir     return Def_Storage::Instance_()[i_id];
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir //********************      Def_Compare      ********************//
181*cdf0e10cSrcweir const Def_Compare::key_type &
182*cdf0e10cSrcweir Def_Compare::KeyOf_(const entity_base_type & i_entity)
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     return i_entity.LocalName();
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir bool
188*cdf0e10cSrcweir Def_Compare::Lesser_( const key_type &    i_1,
189*cdf0e10cSrcweir                       const key_type &    i_2 )
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir     static ::ary::LesserName    less_;
192*cdf0e10cSrcweir     return less_(i_1,i_2);
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir //********************      Type_Traits      ********************//
198*cdf0e10cSrcweir Type_Traits::entity_base_type &
199*cdf0e10cSrcweir Type_Traits::EntityOf_(id_type i_id)
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir     csv_assert(i_id.IsValid());
202*cdf0e10cSrcweir     return Type_Storage::Instance_()[i_id];
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir //********************      Type_Compare      ********************//
206*cdf0e10cSrcweir const UsedType_Compare::key_type &
207*cdf0e10cSrcweir UsedType_Compare::KeyOf_(const entity_base_type & i_entity)
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir     csv_assert( is_type<UsedType>(i_entity) );
210*cdf0e10cSrcweir     return ary_cast<UsedType>(i_entity);
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir bool
214*cdf0e10cSrcweir UsedType_Compare::Lesser_( const key_type &    i_1,
215*cdf0e10cSrcweir                            const key_type &    i_2 )
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir     return i_1 < i_2;
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir }   // namespace cpp
223*cdf0e10cSrcweir }   // namespace ary
224