xref: /aoo41x/main/autodoc/source/ary/cpp/c_traits.cxx (revision d291ea28)
1*d291ea28SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d291ea28SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d291ea28SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d291ea28SAndrew Rist  * distributed with this work for additional information
6*d291ea28SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d291ea28SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d291ea28SAndrew Rist  * "License"); you may not use this file except in compliance
9*d291ea28SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d291ea28SAndrew Rist  *
11*d291ea28SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d291ea28SAndrew Rist  *
13*d291ea28SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d291ea28SAndrew Rist  * software distributed under the License is distributed on an
15*d291ea28SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d291ea28SAndrew Rist  * KIND, either express or implied.  See the License for the
17*d291ea28SAndrew Rist  * specific language governing permissions and limitations
18*d291ea28SAndrew Rist  * under the License.
19*d291ea28SAndrew Rist  *
20*d291ea28SAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir #include <precomp.h>
23cdf0e10cSrcweir #include <ary/cpp/c_traits.hxx>
24cdf0e10cSrcweir 
25cdf0e10cSrcweir 
26cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
27cdf0e10cSrcweir #include <ary/namesort.hxx>
28cdf0e10cSrcweir #include <ary/cpp/c_class.hxx>
29cdf0e10cSrcweir #include <ary/cpp/c_enuval.hxx>
30cdf0e10cSrcweir #include <ary/cpp/c_namesp.hxx>
31cdf0e10cSrcweir #include <ary/cpp/usedtype.hxx>
32cdf0e10cSrcweir #include <ary/getncast.hxx>
33cdf0e10cSrcweir #include "cs_ce.hxx"
34cdf0e10cSrcweir #include "cs_def.hxx"
35cdf0e10cSrcweir #include "cs_type.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace ary
41cdf0e10cSrcweir {
42cdf0e10cSrcweir namespace cpp
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //********************      Ce_Traits      ********************//
48cdf0e10cSrcweir Ce_Traits::entity_base_type &
EntityOf_(id_type i_id)49cdf0e10cSrcweir Ce_Traits::EntityOf_(id_type i_id)
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     csv_assert(i_id.IsValid());
52cdf0e10cSrcweir     return Ce_Storage::Instance_()[i_id];
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir //********************      CeNode_Traits      ********************//
56cdf0e10cSrcweir const symtree::Node<CeNode_Traits> *
NodeOf_(const entity_base_type & i_entity)57cdf0e10cSrcweir CeNode_Traits::NodeOf_(const entity_base_type & i_entity)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir     if (is_type<Namespace>(i_entity))
60cdf0e10cSrcweir         return & ary_cast<Namespace>(i_entity).AsNode();
61cdf0e10cSrcweir     else if (is_type<Class>(i_entity))
62cdf0e10cSrcweir         return & ary_cast<Class>(i_entity).AsNode();
63cdf0e10cSrcweir     return 0;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir symtree::Node<CeNode_Traits> *
NodeOf_(entity_base_type & io_entity)67cdf0e10cSrcweir CeNode_Traits::NodeOf_(entity_base_type & io_entity)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     if (is_type<Namespace>(io_entity))
70cdf0e10cSrcweir         return & ary_cast<Namespace>(io_entity).AsNode();
71cdf0e10cSrcweir     else if (is_type<Class>(io_entity))
72cdf0e10cSrcweir         return & ary_cast<Class>(io_entity).AsNode();
73cdf0e10cSrcweir     return 0;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir Ce_Traits::entity_base_type *
ParentOf_(const entity_base_type & i_entity)77cdf0e10cSrcweir CeNode_Traits::ParentOf_(const entity_base_type & i_entity)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     Ce_Traits::id_type
80cdf0e10cSrcweir         ret = i_entity.Owner();
81cdf0e10cSrcweir     if (ret.IsValid())
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         if (is_type<EnumValue>(i_entity))
84cdf0e10cSrcweir         {   // Return not the Enum, but the owner of the Enum:
85cdf0e10cSrcweir             ret = EntityOf_(ret).Owner();
86cdf0e10cSrcweir             csv_assert(ret.IsValid());
87cdf0e10cSrcweir         }
88cdf0e10cSrcweir         return &EntityOf_(ret);
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir     return 0;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir Ce_id
CeNode_Search(const CodeEntity & i_entity,const String & i_localKey)94cdf0e10cSrcweir CeNode_Search( const CodeEntity &  i_entity,
95cdf0e10cSrcweir                const String &      i_localKey )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     if (is_type<Namespace>(i_entity))
98cdf0e10cSrcweir         return ary_cast<Namespace>(i_entity).Search_Child(i_localKey);
99cdf0e10cSrcweir     else if (is_type<Class>(i_entity))
100cdf0e10cSrcweir         return ary_cast<Class>(i_entity).Search_Child(i_localKey);
101cdf0e10cSrcweir     return Ce_id(0);
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 
107cdf0e10cSrcweir //********************      Ce_Compare      ********************//
108cdf0e10cSrcweir const Ce_Compare::key_type &
KeyOf_(const entity_base_type & i_entity)109cdf0e10cSrcweir Ce_Compare::KeyOf_(const entity_base_type & i_entity)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     return i_entity.LocalName();
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir bool
Lesser_(const key_type & i_1,const key_type & i_2)115cdf0e10cSrcweir Ce_Compare::Lesser_( const key_type &    i_1,
116cdf0e10cSrcweir                      const key_type &    i_2 )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     static ::ary::LesserName    less_;
119cdf0e10cSrcweir     return less_(i_1,i_2);
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //********************      Ce_GlobalCompare      ********************//
124cdf0e10cSrcweir void
Get_Qualified(StreamStr & o_out,const CodeEntity & i_ce)125cdf0e10cSrcweir Get_Qualified( StreamStr &          o_out,
126cdf0e10cSrcweir                const CodeEntity &   i_ce )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     if (i_ce.LocalName().empty())
129cdf0e10cSrcweir         return;
130cdf0e10cSrcweir     if (i_ce.Owner().IsValid())
131cdf0e10cSrcweir         Get_Qualified(o_out, Ce_Traits::EntityOf_(i_ce.Owner()));
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     o_out << i_ce.LocalName() << "::";
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 
137cdf0e10cSrcweir bool
Lesser_(const key_type & i_1,const key_type & i_2)138cdf0e10cSrcweir Ce_GlobalCompare::Lesser_( const key_type &    i_1,
139cdf0e10cSrcweir                            const key_type &    i_2 )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     static ::ary::LesserName    less_;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     if (i_1.LocalName() != i_2.LocalName())
144cdf0e10cSrcweir         return less_(i_1.LocalName(), i_2.LocalName());
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     csv_assert(i_1.Owner().IsValid() AND i_2.Owner().IsValid());
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     static StreamStr
149cdf0e10cSrcweir         aBuffer1_(300);
150cdf0e10cSrcweir     static StreamStr
151cdf0e10cSrcweir         aBuffer2_(300);
152cdf0e10cSrcweir     aBuffer1_.reset();
153cdf0e10cSrcweir     aBuffer2_.reset();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     Get_Qualified(aBuffer1_, Ce_Traits::EntityOf_(i_1.Owner()));
156cdf0e10cSrcweir     Get_Qualified(aBuffer2_, Ce_Traits::EntityOf_(i_2.Owner()));
157cdf0e10cSrcweir     if (aBuffer1_.size() >= 2)
158cdf0e10cSrcweir         aBuffer1_.pop_back(2);
159cdf0e10cSrcweir     if (aBuffer2_.size() >= 2)
160cdf0e10cSrcweir         aBuffer2_.pop_back(2);
161cdf0e10cSrcweir     return less_(aBuffer1_.c_str(), aBuffer2_.c_str());
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 
166cdf0e10cSrcweir //********************      Def_Traits      ********************//
167cdf0e10cSrcweir Def_Traits::entity_base_type &
EntityOf_(id_type i_id)168cdf0e10cSrcweir Def_Traits::EntityOf_(id_type i_id)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     csv_assert(i_id.IsValid());
171cdf0e10cSrcweir     return Def_Storage::Instance_()[i_id];
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir //********************      Def_Compare      ********************//
175cdf0e10cSrcweir const Def_Compare::key_type &
KeyOf_(const entity_base_type & i_entity)176cdf0e10cSrcweir Def_Compare::KeyOf_(const entity_base_type & i_entity)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     return i_entity.LocalName();
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir bool
Lesser_(const key_type & i_1,const key_type & i_2)182cdf0e10cSrcweir Def_Compare::Lesser_( const key_type &    i_1,
183cdf0e10cSrcweir                       const key_type &    i_2 )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir     static ::ary::LesserName    less_;
186cdf0e10cSrcweir     return less_(i_1,i_2);
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 
191cdf0e10cSrcweir //********************      Type_Traits      ********************//
192cdf0e10cSrcweir Type_Traits::entity_base_type &
EntityOf_(id_type i_id)193cdf0e10cSrcweir Type_Traits::EntityOf_(id_type i_id)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     csv_assert(i_id.IsValid());
196cdf0e10cSrcweir     return Type_Storage::Instance_()[i_id];
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir //********************      Type_Compare      ********************//
200cdf0e10cSrcweir const UsedType_Compare::key_type &
KeyOf_(const entity_base_type & i_entity)201cdf0e10cSrcweir UsedType_Compare::KeyOf_(const entity_base_type & i_entity)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     csv_assert( is_type<UsedType>(i_entity) );
204cdf0e10cSrcweir     return ary_cast<UsedType>(i_entity);
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir bool
Lesser_(const key_type & i_1,const key_type & i_2)208cdf0e10cSrcweir UsedType_Compare::Lesser_( const key_type &    i_1,
209cdf0e10cSrcweir                            const key_type &    i_2 )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir     return i_1 < i_2;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 
216cdf0e10cSrcweir }   // namespace cpp
217cdf0e10cSrcweir }   // namespace ary
218