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_class.hxx> 30 31 32 // NOT FULLY DECLARED SERVICES 33 #include <slots.hxx> 34 #include "c_slots.hxx" 35 36 37 38 namespace ary 39 { 40 namespace cpp 41 { 42 43 Class::Class( const String & i_sLocalName, 44 Ce_id i_nOwner, 45 E_Protection i_eProtection, 46 loc::Le_id i_nFile, 47 E_ClassKey i_eClassKey ) 48 : aEssentials( i_sLocalName, 49 i_nOwner, 50 i_nFile ), 51 aAssignedNode(), 52 aBaseClasses(), 53 aTemplateParameterTypes(), 54 aClasses(), 55 aEnums(), 56 aTypedefs(), 57 aOperations(), 58 aStaticOperations(), 59 aData(), 60 aStaticData(), 61 aFriendClasses(), 62 aFriendOperations(), 63 aKnownDerivatives(), 64 eClassKey(i_eClassKey), 65 eProtection(i_eProtection), 66 eVirtuality(VIRTUAL_none) 67 { 68 aAssignedNode.Assign_Entity(*this); 69 } 70 71 Class::~Class() 72 { 73 } 74 75 void 76 Class::Add_BaseClass( const S_Classes_Base & i_rBaseClass ) 77 { 78 aBaseClasses.push_back(i_rBaseClass); 79 } 80 81 void 82 Class::Add_TemplateParameterType( const String & i_sLocalName, 83 Type_id i_nIdAsType ) 84 { 85 aTemplateParameterTypes.push_back( 86 List_TplParam::value_type(i_sLocalName,i_nIdAsType) ); 87 } 88 89 void 90 Class::Add_LocalClass( const String & i_sLocalName, 91 Cid i_nId ) 92 { 93 aClasses.push_back( S_LocalCe(i_sLocalName, i_nId) ); 94 } 95 96 void 97 Class::Add_LocalEnum( const String & i_sLocalName, 98 Cid i_nId ) 99 { 100 aEnums.push_back( S_LocalCe(i_sLocalName, i_nId) ); 101 } 102 103 void 104 Class::Add_LocalTypedef( const String & i_sLocalName, 105 Cid i_nId ) 106 { 107 aTypedefs.push_back( S_LocalCe(i_sLocalName, i_nId) ); 108 } 109 110 void 111 Class::Add_LocalOperation( const String & i_sLocalName, 112 Cid i_nId ) 113 { 114 aOperations.push_back( S_LocalCe(i_sLocalName, i_nId) ); 115 } 116 117 void 118 Class::Add_LocalStaticOperation( const String & i_sLocalName, 119 Cid i_nId ) 120 { 121 aStaticOperations.push_back( S_LocalCe(i_sLocalName, i_nId) ); 122 } 123 124 void 125 Class::Add_LocalData( const String & i_sLocalName, 126 Cid i_nId ) 127 { 128 aData.push_back( S_LocalCe(i_sLocalName, i_nId) ); 129 } 130 131 void 132 Class::Add_LocalStaticData( const String & i_sLocalName, 133 Cid i_nId ) 134 { 135 aStaticData.push_back( S_LocalCe(i_sLocalName, i_nId) ); 136 } 137 138 139 struct find_name 140 { 141 find_name( 142 const String & i_name ) 143 : sName(i_name) {} 144 145 bool operator()( 146 const S_LocalCe & i_lce ) const 147 { return i_lce.sLocalName == sName; } 148 private: 149 String sName; 150 }; 151 152 Ce_id 153 Class::Search_Child(const String & i_key) const 154 { 155 Ce_id 156 ret = Ce_id(Search_LocalClass(i_key)); 157 if (ret.IsValid()) 158 return ret; 159 160 CIterator_Locals 161 itret = std::find_if(aEnums.begin(), aEnums.end(), find_name(i_key)); 162 if (itret != aEnums.end()) 163 return (*itret).nId; 164 itret = std::find_if(aTypedefs.begin(), aTypedefs.end(), find_name(i_key)); 165 if (itret != aTypedefs.end()) 166 return (*itret).nId; 167 itret = std::find_if(aData.begin(), aData.end(), find_name(i_key)); 168 if (itret != aData.end()) 169 return (*itret).nId; 170 itret = std::find_if(aStaticData.begin(), aStaticData.end(), find_name(i_key)); 171 if (itret != aStaticData.end()) 172 return (*itret).nId; 173 return Ce_id(0); 174 } 175 176 Rid 177 Class::Search_LocalClass( const String & i_sName ) const 178 { 179 CIterator_Locals itFound = PosOfName(aClasses, i_sName); 180 if (itFound != aClasses.end()) 181 return (*itFound).nId.Value(); 182 return 0; 183 } 184 185 const String & 186 Class::inq_LocalName() const 187 { 188 return aEssentials.LocalName(); 189 } 190 191 Cid 192 Class::inq_Owner() const 193 { 194 return aEssentials.Owner(); 195 } 196 197 loc::Le_id 198 Class::inq_Location() const 199 { 200 return aEssentials.Location(); 201 } 202 203 void 204 Class::do_Accept(csv::ProcessorIfc & io_processor) const 205 { 206 csv::CheckedCall(io_processor,*this); 207 } 208 209 ClassId 210 Class::get_AryClass() const 211 { 212 return class_id; 213 } 214 215 Gid 216 Class::inq_Id_Group() const 217 { 218 return static_cast<Gid>(Id()); 219 } 220 221 const ary::cpp::CppEntity & 222 Class::inq_RE_Group() const 223 { 224 return *this; 225 } 226 227 const group::SlotList & 228 Class::inq_Slots() const 229 { 230 static const SlotAccessId aProjectSlotData[] 231 = { SLOT_Bases, 232 SLOT_NestedClasses, 233 SLOT_Enums, 234 SLOT_Typedefs, 235 SLOT_Operations, 236 SLOT_StaticOperations, 237 SLOT_Data, 238 SLOT_StaticData, 239 SLOT_FriendClasses, 240 SLOT_FriendOperations }; 241 static const std::vector< SlotAccessId > 242 aSlots( &aProjectSlotData[0], 243 &aProjectSlotData[0] 244 + sizeof aProjectSlotData / sizeof (SlotAccessId) ); 245 return aSlots; 246 } 247 248 249 DYN Slot * 250 Class::inq_Create_Slot( SlotAccessId i_nSlot ) const 251 { 252 switch ( i_nSlot ) 253 { 254 case SLOT_Bases: return new Slot_BaseClass(aBaseClasses); 255 case SLOT_NestedClasses: return new Slot_ListLocalCe(aClasses); 256 case SLOT_Enums: return new Slot_ListLocalCe(aEnums); 257 case SLOT_Typedefs: return new Slot_ListLocalCe(aTypedefs); 258 case SLOT_Operations: return new Slot_ListLocalCe(aOperations); 259 case SLOT_StaticOperations: return new Slot_ListLocalCe(aStaticOperations); 260 case SLOT_Data: return new Slot_ListLocalCe(aData); 261 case SLOT_StaticData: return new Slot_ListLocalCe(aStaticData); 262 case SLOT_FriendClasses: return new Slot_SequentialIds<Ce_id>(aFriendClasses); 263 case SLOT_FriendOperations: return new Slot_SequentialIds<Ce_id>(aFriendOperations); 264 default: 265 return new Slot_Null; 266 } // end switch 267 } 268 269 Class::CIterator_Locals 270 Class::PosOfName( const List_LocalCe & i_rList, 271 const String & i_sName ) const 272 { 273 for ( CIterator_Locals ret = i_rList.begin(); 274 ret != i_rList.end(); 275 ++ret ) 276 { 277 if ( (*ret).sLocalName == i_sName ) 278 return ret; 279 } 280 return i_rList.end(); 281 } 282 283 } // namespace cpp 284 } // namespace ary 285