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