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