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 10cdf0e10cSrcweir * 11*d291ea28SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 20*d291ea28SAndrew Rist *************************************************************/ 21cdf0e10cSrcweir 22cdf0e10cSrcweir #include <precomp.h> 23cdf0e10cSrcweir #include <ary/cpp/namechain.hxx> 24cdf0e10cSrcweir 25cdf0e10cSrcweir 26cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES 27cdf0e10cSrcweir #include <ary/cpp/usedtype.hxx> 28cdf0e10cSrcweir #include <ary/cpp/c_gate.hxx> 29cdf0e10cSrcweir #include "tplparam.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir 32cdf0e10cSrcweir 33cdf0e10cSrcweir namespace ary 34cdf0e10cSrcweir { 35cdf0e10cSrcweir namespace cpp 36cdf0e10cSrcweir { 37cdf0e10cSrcweir namespace ut 38cdf0e10cSrcweir { 39cdf0e10cSrcweir 40cdf0e10cSrcweir 41cdf0e10cSrcweir //********************* NameSegment ******************// 42cdf0e10cSrcweir 43cdf0e10cSrcweir NameSegment::NameSegment( const char * i_sName ) 44cdf0e10cSrcweir : sName( i_sName ) 45cdf0e10cSrcweir // pTemplate 46cdf0e10cSrcweir { 47cdf0e10cSrcweir } 48cdf0e10cSrcweir 49cdf0e10cSrcweir NameSegment::NameSegment( const NameSegment & i_rSeg ) 50cdf0e10cSrcweir : sName(i_rSeg.sName) 51cdf0e10cSrcweir // pTemplate 52cdf0e10cSrcweir { 53cdf0e10cSrcweir // KORR_FUTURE : Handling of copying of templates. 54cdf0e10cSrcweir // csv_assert( NOT i_rSeg.pTemplate ); 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir NameSegment& NameSegment::operator=(const NameSegment & i_rSeg) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir sName = i_rSeg.sName; 60cdf0e10cSrcweir return *this; 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir NameSegment::~NameSegment() 64cdf0e10cSrcweir { 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir List_TplParameter & 68cdf0e10cSrcweir NameSegment::AddTemplate() 69cdf0e10cSrcweir { 70cdf0e10cSrcweir return * (pTemplate = new List_TplParameter); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir intt 74cdf0e10cSrcweir NameSegment::Compare( const NameSegment & i_rOther ) const 75cdf0e10cSrcweir { 76cdf0e10cSrcweir intt nResult = strcmp( sName.c_str(), i_rOther.sName.c_str() ); 77cdf0e10cSrcweir if (nResult != 0) 78cdf0e10cSrcweir return nResult; 79cdf0e10cSrcweir if ( bool(pTemplate) != bool(i_rOther.pTemplate) ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir if ( NOT pTemplate ) 82cdf0e10cSrcweir return -1; 83cdf0e10cSrcweir else 84cdf0e10cSrcweir return +1; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir else if ( NOT pTemplate ) 87cdf0e10cSrcweir return 0; 88cdf0e10cSrcweir else 89cdf0e10cSrcweir return pTemplate->Compare( *i_rOther.pTemplate ); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir void 93cdf0e10cSrcweir NameSegment::Get_Text_AsScope( StreamStr & o_rOut, 94cdf0e10cSrcweir const Gate & i_rGate ) const 95cdf0e10cSrcweir { 96cdf0e10cSrcweir o_rOut << sName; 97cdf0e10cSrcweir if ( pTemplate ) 98cdf0e10cSrcweir pTemplate->Get_Text( o_rOut, i_rGate ); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir void 102cdf0e10cSrcweir NameSegment::Get_Text_AsMainType( StreamStr & o_rName, 103cdf0e10cSrcweir StreamStr & o_rPostName, 104cdf0e10cSrcweir const Gate & i_rGate ) const 105cdf0e10cSrcweir { 106cdf0e10cSrcweir o_rName << sName; 107cdf0e10cSrcweir if ( pTemplate ) 108cdf0e10cSrcweir pTemplate->Get_Text( o_rPostName, i_rGate ); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir 112cdf0e10cSrcweir //********************* NameChain ******************// 113cdf0e10cSrcweir 114cdf0e10cSrcweir NameChain::NameChain() 115cdf0e10cSrcweir // : aSegments 116cdf0e10cSrcweir { 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir NameChain::~NameChain() 120cdf0e10cSrcweir { 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir void 124cdf0e10cSrcweir NameChain::Add_Segment( const char * i_sSeg ) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir aSegments.push_back( NameSegment(i_sSeg) ); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir List_TplParameter & 130cdf0e10cSrcweir NameChain::Templatize_LastSegment() 131cdf0e10cSrcweir { 132cdf0e10cSrcweir csv_assert( aSegments.size() > 0 ); 133cdf0e10cSrcweir 134cdf0e10cSrcweir return aSegments.back().AddTemplate(); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir intt 138cdf0e10cSrcweir NameChain::Compare( const NameChain & i_rChain ) const 139cdf0e10cSrcweir { 140cdf0e10cSrcweir intt nResult = intt(aSegments.size()) - intt(i_rChain.aSegments.size()); 141cdf0e10cSrcweir if (nResult != 0) 142cdf0e10cSrcweir return nResult; 143cdf0e10cSrcweir 144cdf0e10cSrcweir std::vector< NameSegment >::const_iterator it1 = aSegments.begin(); 145cdf0e10cSrcweir std::vector< NameSegment >::const_iterator it1End = aSegments.end(); 146cdf0e10cSrcweir std::vector< NameSegment >::const_iterator it2 = i_rChain.aSegments.begin(); 147cdf0e10cSrcweir 148cdf0e10cSrcweir for ( ; it1 != it1End; ++it1, ++it2 ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir nResult = (*it1).Compare(*it2); 151cdf0e10cSrcweir if (nResult != 0) 152cdf0e10cSrcweir return nResult; 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir return 0; 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir const String & 159cdf0e10cSrcweir NameChain::LastSegment() const 160cdf0e10cSrcweir { 161cdf0e10cSrcweir if ( aSegments.size() > 0 ) 162cdf0e10cSrcweir return aSegments.back().Name(); 163cdf0e10cSrcweir return String::Null_(); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir void 167cdf0e10cSrcweir NameChain::Get_Text( StreamStr & o_rPreName, 168cdf0e10cSrcweir StreamStr & o_rName, 169cdf0e10cSrcweir StreamStr & o_rPostName, 170cdf0e10cSrcweir const Gate & i_rGate ) const 171cdf0e10cSrcweir { 172cdf0e10cSrcweir std::vector< NameSegment >::const_iterator it = aSegments.begin(); 173cdf0e10cSrcweir std::vector< NameSegment >::const_iterator itEnd = aSegments.end(); 174cdf0e10cSrcweir 175cdf0e10cSrcweir if ( it == itEnd ) 176cdf0e10cSrcweir return; 177cdf0e10cSrcweir 178cdf0e10cSrcweir for ( --itEnd; it != itEnd; ++it ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir (*it).Get_Text_AsScope( o_rPreName, i_rGate ); 181cdf0e10cSrcweir o_rPreName << "::"; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir (*it).Get_Text_AsMainType( o_rName, o_rPostName, i_rGate ); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir 187cdf0e10cSrcweir 188cdf0e10cSrcweir } // namespace ut 189cdf0e10cSrcweir } // namespace cpp 190cdf0e10cSrcweir } // namespace ary 191