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_traits.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 <ary/cpp/c_traits.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <ary/namesort.hxx>
37 #include <ary/cpp/c_class.hxx>
38 #include <ary/cpp/c_enuval.hxx>
39 #include <ary/cpp/c_namesp.hxx>
40 #include <ary/cpp/usedtype.hxx>
41 #include <ary/getncast.hxx>
44 #include "cs_type.hxx"
56 //******************** Ce_Traits ********************//
57 Ce_Traits::entity_base_type
&
58 Ce_Traits::EntityOf_(id_type i_id
)
60 csv_assert(i_id
.IsValid());
61 return Ce_Storage::Instance_()[i_id
];
64 //******************** CeNode_Traits ********************//
65 const symtree::Node
<CeNode_Traits
> *
66 CeNode_Traits::NodeOf_(const entity_base_type
& i_entity
)
68 if (is_type
<Namespace
>(i_entity
))
69 return & ary_cast
<Namespace
>(i_entity
).AsNode();
70 else if (is_type
<Class
>(i_entity
))
71 return & ary_cast
<Class
>(i_entity
).AsNode();
75 symtree::Node
<CeNode_Traits
> *
76 CeNode_Traits::NodeOf_(entity_base_type
& io_entity
)
78 if (is_type
<Namespace
>(io_entity
))
79 return & ary_cast
<Namespace
>(io_entity
).AsNode();
80 else if (is_type
<Class
>(io_entity
))
81 return & ary_cast
<Class
>(io_entity
).AsNode();
85 Ce_Traits::entity_base_type
*
86 CeNode_Traits::ParentOf_(const entity_base_type
& i_entity
)
89 ret
= i_entity
.Owner();
92 if (is_type
<EnumValue
>(i_entity
))
93 { // Return not the Enum, but the owner of the Enum:
94 ret
= EntityOf_(ret
).Owner();
95 csv_assert(ret
.IsValid());
97 return &EntityOf_(ret
);
103 CeNode_Search( const CodeEntity
& i_entity
,
104 const String
& i_localKey
)
106 if (is_type
<Namespace
>(i_entity
))
107 return ary_cast
<Namespace
>(i_entity
).Search_Child(i_localKey
);
108 else if (is_type
<Class
>(i_entity
))
109 return ary_cast
<Class
>(i_entity
).Search_Child(i_localKey
);
116 //******************** Ce_Compare ********************//
117 const Ce_Compare::key_type
&
118 Ce_Compare::KeyOf_(const entity_base_type
& i_entity
)
120 return i_entity
.LocalName();
124 Ce_Compare::Lesser_( const key_type
& i_1
,
125 const key_type
& i_2
)
127 static ::ary::LesserName less_
;
128 return less_(i_1
,i_2
);
132 //******************** Ce_GlobalCompare ********************//
134 Get_Qualified( StreamStr
& o_out
,
135 const CodeEntity
& i_ce
)
137 if (i_ce
.LocalName().empty())
139 if (i_ce
.Owner().IsValid())
140 Get_Qualified(o_out
, Ce_Traits::EntityOf_(i_ce
.Owner()));
142 o_out
<< i_ce
.LocalName() << "::";
147 Ce_GlobalCompare::Lesser_( const key_type
& i_1
,
148 const key_type
& i_2
)
150 static ::ary::LesserName less_
;
152 if (i_1
.LocalName() != i_2
.LocalName())
153 return less_(i_1
.LocalName(), i_2
.LocalName());
155 csv_assert(i_1
.Owner().IsValid() AND i_2
.Owner().IsValid());
164 Get_Qualified(aBuffer1_
, Ce_Traits::EntityOf_(i_1
.Owner()));
165 Get_Qualified(aBuffer2_
, Ce_Traits::EntityOf_(i_2
.Owner()));
166 if (aBuffer1_
.size() >= 2)
167 aBuffer1_
.pop_back(2);
168 if (aBuffer2_
.size() >= 2)
169 aBuffer2_
.pop_back(2);
170 return less_(aBuffer1_
.c_str(), aBuffer2_
.c_str());
175 //******************** Def_Traits ********************//
176 Def_Traits::entity_base_type
&
177 Def_Traits::EntityOf_(id_type i_id
)
179 csv_assert(i_id
.IsValid());
180 return Def_Storage::Instance_()[i_id
];
183 //******************** Def_Compare ********************//
184 const Def_Compare::key_type
&
185 Def_Compare::KeyOf_(const entity_base_type
& i_entity
)
187 return i_entity
.LocalName();
191 Def_Compare::Lesser_( const key_type
& i_1
,
192 const key_type
& i_2
)
194 static ::ary::LesserName less_
;
195 return less_(i_1
,i_2
);
200 //******************** Type_Traits ********************//
201 Type_Traits::entity_base_type
&
202 Type_Traits::EntityOf_(id_type i_id
)
204 csv_assert(i_id
.IsValid());
205 return Type_Storage::Instance_()[i_id
];
208 //******************** Type_Compare ********************//
209 const UsedType_Compare::key_type
&
210 UsedType_Compare::KeyOf_(const entity_base_type
& i_entity
)
212 csv_assert( is_type
<UsedType
>(i_entity
) );
213 return ary_cast
<UsedType
>(i_entity
);
217 UsedType_Compare::Lesser_( const key_type
& i_1
,
218 const key_type
& i_2
)