xref: /aoo42x/main/autodoc/source/ary/cpp/namechain.cxx (revision a0d53b35)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <precomp.h>
23 #include <ary/cpp/namechain.hxx>
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/cpp/usedtype.hxx>
28 #include <ary/cpp/c_gate.hxx>
29 #include "tplparam.hxx"
30 
31 
32 
33 namespace ary
34 {
35 namespace cpp
36 {
37 namespace ut
38 {
39 
40 
41 //*********************		NameSegment		******************//
42 
NameSegment(const char * i_sName)43 NameSegment::NameSegment( const char * i_sName )
44 	:	sName( i_sName )
45 		// pTemplate
46 {
47 }
48 
NameSegment(const NameSegment & i_rSeg)49 NameSegment::NameSegment( const NameSegment & i_rSeg )
50 	:	sName(i_rSeg.sName)
51 		// pTemplate
52 {
53     // KORR_FUTURE :   Handling of copying of templates.
54 //	csv_assert( NOT i_rSeg.pTemplate );
55 }
56 
operator =(const NameSegment & i_rSeg)57 NameSegment& NameSegment::operator=(const NameSegment & i_rSeg)
58 {
59 	sName = i_rSeg.sName;
60 	return *this;
61 }
62 
~NameSegment()63 NameSegment::~NameSegment()
64 {
65 }
66 
67 List_TplParameter &
AddTemplate()68 NameSegment::AddTemplate()
69 {
70 	return * (pTemplate = new List_TplParameter);
71 }
72 
73 intt
Compare(const NameSegment & i_rOther) const74 NameSegment::Compare( const NameSegment & i_rOther ) const
75 {
76 	intt nResult = strcmp( sName.c_str(), i_rOther.sName.c_str() );
77 	if (nResult != 0)
78 		return nResult;
79 	if ( bool(pTemplate) != bool(i_rOther.pTemplate) )
80 	{
81 		if ( NOT pTemplate )
82 			return -1;
83 		else
84 			return +1;
85 	}
86 	else if ( NOT pTemplate )
87 		return 0;
88 	else
89 		return pTemplate->Compare( *i_rOther.pTemplate );
90 }
91 
92 void
Get_Text_AsScope(StreamStr & o_rOut,const Gate & i_rGate) const93 NameSegment::Get_Text_AsScope( StreamStr &   o_rOut,
94 						       const Gate &  i_rGate ) const
95 {
96 	o_rOut << sName;
97 	if ( pTemplate )
98 		pTemplate->Get_Text( o_rOut, i_rGate );
99 }
100 
101 void
Get_Text_AsMainType(StreamStr & o_rName,StreamStr & o_rPostName,const Gate & i_rGate) const102 NameSegment::Get_Text_AsMainType( StreamStr &   o_rName,
103 						          StreamStr &   o_rPostName,
104 						          const Gate &  i_rGate ) const
105 {
106 	o_rName << sName;
107 	if ( pTemplate )
108 		pTemplate->Get_Text( o_rPostName, i_rGate );
109 }
110 
111 
112 //*********************		NameChain     ******************//
113 
NameChain()114 NameChain::NameChain()
115 //  :   aSegments
116 {
117 }
118 
~NameChain()119 NameChain::~NameChain()
120 {
121 }
122 
123 void
Add_Segment(const char * i_sSeg)124 NameChain::Add_Segment( const char * i_sSeg )
125 {
126 	aSegments.push_back( NameSegment(i_sSeg) );
127 }
128 
129 List_TplParameter &
Templatize_LastSegment()130 NameChain::Templatize_LastSegment()
131 {
132 	csv_assert( ! aSegments.empty() );
133 
134 	return aSegments.back().AddTemplate();
135 }
136 
137 intt
Compare(const NameChain & i_rChain) const138 NameChain::Compare( const NameChain & i_rChain ) const
139 {
140 	intt nResult = intt(aSegments.size()) - intt(i_rChain.aSegments.size());
141 	if (nResult != 0)
142 		return nResult;
143 
144 	std::vector< NameSegment >::const_iterator it1 = aSegments.begin();
145 	std::vector< NameSegment >::const_iterator it1End = aSegments.end();
146 	std::vector< NameSegment >::const_iterator it2 = i_rChain.aSegments.begin();
147 
148 	for ( ; it1 != it1End; ++it1, ++it2 )
149 	{
150 		nResult = (*it1).Compare(*it2);
151 		if (nResult != 0)
152 			return nResult;
153 	}
154 
155 	return 0;
156 }
157 
158 const String  &
LastSegment() const159 NameChain::LastSegment() const
160 {
161 	if ( ! aSegments.empty() )
162 		return aSegments.back().Name();
163 	return String::Null_();
164 }
165 
166 void
Get_Text(StreamStr & o_rPreName,StreamStr & o_rName,StreamStr & o_rPostName,const Gate & i_rGate) const167 NameChain::Get_Text( StreamStr &    o_rPreName,
168 					 StreamStr &    o_rName,
169 					 StreamStr &    o_rPostName,
170 					 const Gate &   i_rGate ) const
171 {
172 	std::vector< NameSegment >::const_iterator it = aSegments.begin();
173 	std::vector< NameSegment >::const_iterator itEnd = aSegments.end();
174 
175 	if ( it == itEnd )
176 		return;
177 
178 	for ( --itEnd; it != itEnd; ++it )
179 	{
180 		(*it).Get_Text_AsScope( o_rPreName, i_rGate );
181 		o_rPreName << "::";
182 	}
183 	(*it).Get_Text_AsMainType( o_rName, o_rPostName, i_rGate );
184 }
185 
186 
187 
188 }   // namespace ut
189 }   // namespace cpp
190 }   // namespace ary
191