1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: namechain.cxx,v $
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 ************************************************************************/
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"
50 //********************* NameSegment ******************//
52 NameSegment::NameSegment( const char * i_sName
)
58 NameSegment::NameSegment( const NameSegment
& i_rSeg
)
62 // KORR_FUTURE : Handling of copying of templates.
63 // csv_assert( NOT i_rSeg.pTemplate );
66 NameSegment
& NameSegment::operator=(const NameSegment
& i_rSeg
)
72 NameSegment::~NameSegment()
77 NameSegment::AddTemplate()
79 return * (pTemplate
= new List_TplParameter
);
83 NameSegment::Compare( const NameSegment
& i_rOther
) const
85 intt nResult
= strcmp( sName
.c_str(), i_rOther
.sName
.c_str() );
88 if ( bool(pTemplate
) != bool(i_rOther
.pTemplate
) )
95 else if ( NOT pTemplate
)
98 return pTemplate
->Compare( *i_rOther
.pTemplate
);
102 NameSegment::Get_Text_AsScope( StreamStr
& o_rOut
,
103 const Gate
& i_rGate
) const
107 pTemplate
->Get_Text( o_rOut
, i_rGate
);
111 NameSegment::Get_Text_AsMainType( StreamStr
& o_rName
,
112 StreamStr
& o_rPostName
,
113 const Gate
& i_rGate
) const
117 pTemplate
->Get_Text( o_rPostName
, i_rGate
);
121 //********************* NameChain ******************//
123 NameChain::NameChain()
128 NameChain::~NameChain()
133 NameChain::Add_Segment( const char * i_sSeg
)
135 aSegments
.push_back( NameSegment(i_sSeg
) );
139 NameChain::Templatize_LastSegment()
141 csv_assert( aSegments
.size() > 0 );
143 return aSegments
.back().AddTemplate();
147 NameChain::Compare( const NameChain
& i_rChain
) const
149 intt nResult
= intt(aSegments
.size()) - intt(i_rChain
.aSegments
.size());
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
);
168 NameChain::LastSegment() const
170 if ( aSegments
.size() > 0 )
171 return aSegments
.back().Name();
172 return String::Null_();
176 NameChain::Get_Text( StreamStr
& o_rPreName
,
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();
187 for ( --itEnd
; it
!= itEnd
; ++it
)
189 (*it
).Get_Text_AsScope( o_rPreName
, i_rGate
);
192 (*it
).Get_Text_AsMainType( o_rName
, o_rPostName
, i_rGate
);