1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include <precomp.h> 29*cdf0e10cSrcweir #include <ary/cpp/namechain.hxx> 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES 33*cdf0e10cSrcweir #include <ary/cpp/usedtype.hxx> 34*cdf0e10cSrcweir #include <ary/cpp/c_gate.hxx> 35*cdf0e10cSrcweir #include "tplparam.hxx" 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir namespace ary 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir namespace cpp 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir namespace ut 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir //********************* NameSegment ******************// 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir NameSegment::NameSegment( const char * i_sName ) 50*cdf0e10cSrcweir : sName( i_sName ) 51*cdf0e10cSrcweir // pTemplate 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir NameSegment::NameSegment( const NameSegment & i_rSeg ) 56*cdf0e10cSrcweir : sName(i_rSeg.sName) 57*cdf0e10cSrcweir // pTemplate 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir // KORR_FUTURE : Handling of copying of templates. 60*cdf0e10cSrcweir // csv_assert( NOT i_rSeg.pTemplate ); 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir NameSegment& NameSegment::operator=(const NameSegment & i_rSeg) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir sName = i_rSeg.sName; 66*cdf0e10cSrcweir return *this; 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir NameSegment::~NameSegment() 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir List_TplParameter & 74*cdf0e10cSrcweir NameSegment::AddTemplate() 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir return * (pTemplate = new List_TplParameter); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir intt 80*cdf0e10cSrcweir NameSegment::Compare( const NameSegment & i_rOther ) const 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir intt nResult = strcmp( sName.c_str(), i_rOther.sName.c_str() ); 83*cdf0e10cSrcweir if (nResult != 0) 84*cdf0e10cSrcweir return nResult; 85*cdf0e10cSrcweir if ( bool(pTemplate) != bool(i_rOther.pTemplate) ) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir if ( NOT pTemplate ) 88*cdf0e10cSrcweir return -1; 89*cdf0e10cSrcweir else 90*cdf0e10cSrcweir return +1; 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir else if ( NOT pTemplate ) 93*cdf0e10cSrcweir return 0; 94*cdf0e10cSrcweir else 95*cdf0e10cSrcweir return pTemplate->Compare( *i_rOther.pTemplate ); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir void 99*cdf0e10cSrcweir NameSegment::Get_Text_AsScope( StreamStr & o_rOut, 100*cdf0e10cSrcweir const Gate & i_rGate ) const 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir o_rOut << sName; 103*cdf0e10cSrcweir if ( pTemplate ) 104*cdf0e10cSrcweir pTemplate->Get_Text( o_rOut, i_rGate ); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir void 108*cdf0e10cSrcweir NameSegment::Get_Text_AsMainType( StreamStr & o_rName, 109*cdf0e10cSrcweir StreamStr & o_rPostName, 110*cdf0e10cSrcweir const Gate & i_rGate ) const 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir o_rName << sName; 113*cdf0e10cSrcweir if ( pTemplate ) 114*cdf0e10cSrcweir pTemplate->Get_Text( o_rPostName, i_rGate ); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir //********************* NameChain ******************// 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir NameChain::NameChain() 121*cdf0e10cSrcweir // : aSegments 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir NameChain::~NameChain() 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir void 130*cdf0e10cSrcweir NameChain::Add_Segment( const char * i_sSeg ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir aSegments.push_back( NameSegment(i_sSeg) ); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir List_TplParameter & 136*cdf0e10cSrcweir NameChain::Templatize_LastSegment() 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir csv_assert( aSegments.size() > 0 ); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir return aSegments.back().AddTemplate(); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir intt 144*cdf0e10cSrcweir NameChain::Compare( const NameChain & i_rChain ) const 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir intt nResult = intt(aSegments.size()) - intt(i_rChain.aSegments.size()); 147*cdf0e10cSrcweir if (nResult != 0) 148*cdf0e10cSrcweir return nResult; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir std::vector< NameSegment >::const_iterator it1 = aSegments.begin(); 151*cdf0e10cSrcweir std::vector< NameSegment >::const_iterator it1End = aSegments.end(); 152*cdf0e10cSrcweir std::vector< NameSegment >::const_iterator it2 = i_rChain.aSegments.begin(); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir for ( ; it1 != it1End; ++it1, ++it2 ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir nResult = (*it1).Compare(*it2); 157*cdf0e10cSrcweir if (nResult != 0) 158*cdf0e10cSrcweir return nResult; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir return 0; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir const String & 165*cdf0e10cSrcweir NameChain::LastSegment() const 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir if ( aSegments.size() > 0 ) 168*cdf0e10cSrcweir return aSegments.back().Name(); 169*cdf0e10cSrcweir return String::Null_(); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir void 173*cdf0e10cSrcweir NameChain::Get_Text( StreamStr & o_rPreName, 174*cdf0e10cSrcweir StreamStr & o_rName, 175*cdf0e10cSrcweir StreamStr & o_rPostName, 176*cdf0e10cSrcweir const Gate & i_rGate ) const 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir std::vector< NameSegment >::const_iterator it = aSegments.begin(); 179*cdf0e10cSrcweir std::vector< NameSegment >::const_iterator itEnd = aSegments.end(); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if ( it == itEnd ) 182*cdf0e10cSrcweir return; 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir for ( --itEnd; it != itEnd; ++it ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir (*it).Get_Text_AsScope( o_rPreName, i_rGate ); 187*cdf0e10cSrcweir o_rPreName << "::"; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir (*it).Get_Text_AsMainType( o_rName, o_rPostName, i_rGate ); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir } // namespace ut 195*cdf0e10cSrcweir } // namespace cpp 196*cdf0e10cSrcweir } // namespace ary 197