1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #include <precomp.h> 23 #include <ary/cpp/c_class.hxx> 24 25 26 // NOT FULLY DECLARED SERVICES 27 #include <slots.hxx> 28 #include "c_slots.hxx" 29 30 31 32 namespace ary 33 { 34 namespace cpp 35 { 36 37 Class::Class( const String & i_sLocalName, 38 Ce_id i_nOwner, 39 E_Protection i_eProtection, 40 loc::Le_id i_nFile, 41 E_ClassKey i_eClassKey ) 42 : aEssentials( i_sLocalName, 43 i_nOwner, 44 i_nFile ), 45 aAssignedNode(), 46 aBaseClasses(), 47 aTemplateParameterTypes(), 48 aClasses(), 49 aEnums(), 50 aTypedefs(), 51 aOperations(), 52 aStaticOperations(), 53 aData(), 54 aStaticData(), 55 aFriendClasses(), 56 aFriendOperations(), 57 aKnownDerivatives(), 58 eClassKey(i_eClassKey), 59 eProtection(i_eProtection), 60 eVirtuality(VIRTUAL_none) 61 { 62 aAssignedNode.Assign_Entity(*this); 63 } 64 65 Class::~Class() 66 { 67 } 68 69 void 70 Class::Add_BaseClass( const S_Classes_Base & i_rBaseClass ) 71 { 72 aBaseClasses.push_back(i_rBaseClass); 73 } 74 75 void 76 Class::Add_TemplateParameterType( const String & i_sLocalName, 77 Type_id i_nIdAsType ) 78 { 79 aTemplateParameterTypes.push_back( 80 List_TplParam::value_type(i_sLocalName,i_nIdAsType) ); 81 } 82 83 void 84 Class::Add_LocalClass( const String & i_sLocalName, 85 Cid i_nId ) 86 { 87 aClasses.push_back( S_LocalCe(i_sLocalName, i_nId) ); 88 } 89 90 void 91 Class::Add_LocalEnum( const String & i_sLocalName, 92 Cid i_nId ) 93 { 94 aEnums.push_back( S_LocalCe(i_sLocalName, i_nId) ); 95 } 96 97 void 98 Class::Add_LocalTypedef( const String & i_sLocalName, 99 Cid i_nId ) 100 { 101 aTypedefs.push_back( S_LocalCe(i_sLocalName, i_nId) ); 102 } 103 104 void 105 Class::Add_LocalOperation( const String & i_sLocalName, 106 Cid i_nId ) 107 { 108 aOperations.push_back( S_LocalCe(i_sLocalName, i_nId) ); 109 } 110 111 void 112 Class::Add_LocalStaticOperation( const String & i_sLocalName, 113 Cid i_nId ) 114 { 115 aStaticOperations.push_back( S_LocalCe(i_sLocalName, i_nId) ); 116 } 117 118 void 119 Class::Add_LocalData( const String & i_sLocalName, 120 Cid i_nId ) 121 { 122 aData.push_back( S_LocalCe(i_sLocalName, i_nId) ); 123 } 124 125 void 126 Class::Add_LocalStaticData( const String & i_sLocalName, 127 Cid i_nId ) 128 { 129 aStaticData.push_back( S_LocalCe(i_sLocalName, i_nId) ); 130 } 131 132 133 struct find_name 134 { 135 find_name( 136 const String & i_name ) 137 : sName(i_name) {} 138 139 bool operator()( 140 const S_LocalCe & i_lce ) const 141 { return i_lce.sLocalName == sName; } 142 private: 143 String sName; 144 }; 145 146 Ce_id 147 Class::Search_Child(const String & i_key) const 148 { 149 Ce_id 150 ret = Ce_id(Search_LocalClass(i_key)); 151 if (ret.IsValid()) 152 return ret; 153 154 CIterator_Locals 155 itret = std::find_if(aEnums.begin(), aEnums.end(), find_name(i_key)); 156 if (itret != aEnums.end()) 157 return (*itret).nId; 158 itret = std::find_if(aTypedefs.begin(), aTypedefs.end(), find_name(i_key)); 159 if (itret != aTypedefs.end()) 160 return (*itret).nId; 161 itret = std::find_if(aData.begin(), aData.end(), find_name(i_key)); 162 if (itret != aData.end()) 163 return (*itret).nId; 164 itret = std::find_if(aStaticData.begin(), aStaticData.end(), find_name(i_key)); 165 if (itret != aStaticData.end()) 166 return (*itret).nId; 167 return Ce_id(0); 168 } 169 170 Rid 171 Class::Search_LocalClass( const String & i_sName ) const 172 { 173 CIterator_Locals itFound = PosOfName(aClasses, i_sName); 174 if (itFound != aClasses.end()) 175 return (*itFound).nId.Value(); 176 return 0; 177 } 178 179 const String & 180 Class::inq_LocalName() const 181 { 182 return aEssentials.LocalName(); 183 } 184 185 Cid 186 Class::inq_Owner() const 187 { 188 return aEssentials.Owner(); 189 } 190 191 loc::Le_id 192 Class::inq_Location() const 193 { 194 return aEssentials.Location(); 195 } 196 197 void 198 Class::do_Accept(csv::ProcessorIfc & io_processor) const 199 { 200 csv::CheckedCall(io_processor,*this); 201 } 202 203 ClassId 204 Class::get_AryClass() const 205 { 206 return class_id; 207 } 208 209 Gid 210 Class::inq_Id_Group() const 211 { 212 return static_cast<Gid>(Id()); 213 } 214 215 const ary::cpp::CppEntity & 216 Class::inq_RE_Group() const 217 { 218 return *this; 219 } 220 221 const group::SlotList & 222 Class::inq_Slots() const 223 { 224 static const SlotAccessId aProjectSlotData[] 225 = { SLOT_Bases, 226 SLOT_NestedClasses, 227 SLOT_Enums, 228 SLOT_Typedefs, 229 SLOT_Operations, 230 SLOT_StaticOperations, 231 SLOT_Data, 232 SLOT_StaticData, 233 SLOT_FriendClasses, 234 SLOT_FriendOperations }; 235 static const std::vector< SlotAccessId > 236 aSlots( &aProjectSlotData[0], 237 &aProjectSlotData[0] 238 + sizeof aProjectSlotData / sizeof (SlotAccessId) ); 239 return aSlots; 240 } 241 242 243 DYN Slot * 244 Class::inq_Create_Slot( SlotAccessId i_nSlot ) const 245 { 246 switch ( i_nSlot ) 247 { 248 case SLOT_Bases: return new Slot_BaseClass(aBaseClasses); 249 case SLOT_NestedClasses: return new Slot_ListLocalCe(aClasses); 250 case SLOT_Enums: return new Slot_ListLocalCe(aEnums); 251 case SLOT_Typedefs: return new Slot_ListLocalCe(aTypedefs); 252 case SLOT_Operations: return new Slot_ListLocalCe(aOperations); 253 case SLOT_StaticOperations: return new Slot_ListLocalCe(aStaticOperations); 254 case SLOT_Data: return new Slot_ListLocalCe(aData); 255 case SLOT_StaticData: return new Slot_ListLocalCe(aStaticData); 256 case SLOT_FriendClasses: return new Slot_SequentialIds<Ce_id>(aFriendClasses); 257 case SLOT_FriendOperations: return new Slot_SequentialIds<Ce_id>(aFriendOperations); 258 default: 259 return new Slot_Null; 260 } // end switch 261 } 262 263 Class::CIterator_Locals 264 Class::PosOfName( const List_LocalCe & i_rList, 265 const String & i_sName ) const 266 { 267 for ( CIterator_Locals ret = i_rList.begin(); 268 ret != i_rList.end(); 269 ++ret ) 270 { 271 if ( (*ret).sLocalName == i_sName ) 272 return ret; 273 } 274 return i_rList.end(); 275 } 276 277 } // namespace cpp 278 } // namespace ary 279