merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / ary / cpp / namechain.cxx
blob01a6cc56cbdcd403500e1d73dbfb92fe6bf8eec9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: namechain.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include <ary/cpp/namechain.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <ary/cpp/usedtype.hxx>
37 #include <ary/cpp/c_gate.hxx>
38 #include "tplparam.hxx"
42 namespace ary
44 namespace cpp
46 namespace ut
50 //********************* NameSegment ******************//
52 NameSegment::NameSegment( const char * i_sName )
53 : sName( i_sName )
54 // pTemplate
58 NameSegment::NameSegment( const NameSegment & i_rSeg )
59 : sName(i_rSeg.sName)
60 // pTemplate
62 // KORR_FUTURE : Handling of copying of templates.
63 // csv_assert( NOT i_rSeg.pTemplate );
66 NameSegment& NameSegment::operator=(const NameSegment & i_rSeg)
68 sName = i_rSeg.sName;
69 return *this;
72 NameSegment::~NameSegment()
76 List_TplParameter &
77 NameSegment::AddTemplate()
79 return * (pTemplate = new List_TplParameter);
82 intt
83 NameSegment::Compare( const NameSegment & i_rOther ) const
85 intt nResult = strcmp( sName.c_str(), i_rOther.sName.c_str() );
86 if (nResult != 0)
87 return nResult;
88 if ( bool(pTemplate) != bool(i_rOther.pTemplate) )
90 if ( NOT pTemplate )
91 return -1;
92 else
93 return +1;
95 else if ( NOT pTemplate )
96 return 0;
97 else
98 return pTemplate->Compare( *i_rOther.pTemplate );
101 void
102 NameSegment::Get_Text_AsScope( StreamStr & o_rOut,
103 const Gate & i_rGate ) const
105 o_rOut << sName;
106 if ( pTemplate )
107 pTemplate->Get_Text( o_rOut, i_rGate );
110 void
111 NameSegment::Get_Text_AsMainType( StreamStr & o_rName,
112 StreamStr & o_rPostName,
113 const Gate & i_rGate ) const
115 o_rName << sName;
116 if ( pTemplate )
117 pTemplate->Get_Text( o_rPostName, i_rGate );
121 //********************* NameChain ******************//
123 NameChain::NameChain()
124 // : aSegments
128 NameChain::~NameChain()
132 void
133 NameChain::Add_Segment( const char * i_sSeg )
135 aSegments.push_back( NameSegment(i_sSeg) );
138 List_TplParameter &
139 NameChain::Templatize_LastSegment()
141 csv_assert( aSegments.size() > 0 );
143 return aSegments.back().AddTemplate();
146 intt
147 NameChain::Compare( const NameChain & i_rChain ) const
149 intt nResult = intt(aSegments.size()) - intt(i_rChain.aSegments.size());
150 if (nResult != 0)
151 return nResult;
153 std::vector< NameSegment >::const_iterator it1 = aSegments.begin();
154 std::vector< NameSegment >::const_iterator it1End = aSegments.end();
155 std::vector< NameSegment >::const_iterator it2 = i_rChain.aSegments.begin();
157 for ( ; it1 != it1End; ++it1, ++it2 )
159 nResult = (*it1).Compare(*it2);
160 if (nResult != 0)
161 return nResult;
164 return 0;
167 const String &
168 NameChain::LastSegment() const
170 if ( aSegments.size() > 0 )
171 return aSegments.back().Name();
172 return String::Null_();
175 void
176 NameChain::Get_Text( StreamStr & o_rPreName,
177 StreamStr & o_rName,
178 StreamStr & o_rPostName,
179 const Gate & i_rGate ) const
181 std::vector< NameSegment >::const_iterator it = aSegments.begin();
182 std::vector< NameSegment >::const_iterator itEnd = aSegments.end();
184 if ( it == itEnd )
185 return;
187 for ( --itEnd; it != itEnd; ++it )
189 (*it).Get_Text_AsScope( o_rPreName, i_rGate );
190 o_rPreName << "::";
192 (*it).Get_Text_AsMainType( o_rName, o_rPostName, i_rGate );
197 } // namespace ut
198 } // namespace cpp
199 } // namespace ary