xref: /aoo42x/main/autodoc/source/ary/cpp/c_funct.cxx (revision d291ea28)
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/c_funct.hxx>
24 
25 
26 
27 // NOT FULLY DECLARED SERVICES
28 #include <algorithm>
29 #include <ary/cpp/c_funct.hxx>
30 
31 
32 
33 
34 
35 namespace
36 {
37 using namespace ::ary::cpp;
38 
39 
40 class Parameter_2_NonTypeParamInfo
41 {
42   public:
43     String              operator()(
44                             const S_Parameter & i_rParam ) const;
45 };
46 
47 class Parameter_2_Type
48 {
49   public:
operator ()(const S_Parameter & i_rParam) const50     Type_id             operator()(
51                             const S_Parameter & i_rParam ) const
52                                                 { return i_rParam.nType; }
53 };
54 
55 /** @return
56     A vector with Strings like this:
57         "ParamName" or "ParamName[ArraySize]" or "ParamName = InitValue".
58 */
59 StringVector        Create_NonTypeParameterInfos(
60                         const std::vector<S_Parameter> &
61                                             i_rParameters );
62 /** @return
63     A vector of the parameters' type ids.
64 */
65 std::vector<Type_id>
66                     Create_ParameterTypeList(
67                         const std::vector<S_Parameter> &
68                                             i_rParameters );
69 
70 }   // namspace anonymous
71 
72 
73 namespace ary
74 {
75 namespace cpp
76 {
77 
Function(const String & i_sLocalName,Ce_id i_nOwner,E_Protection i_eProtection,Lid i_nFile,Type_id i_nReturnType,const std::vector<S_Parameter> & i_parameters,E_ConVol i_conVol,E_Virtuality i_eVirtuality,FunctionFlags i_aFlags,bool i_bThrowExists,const std::vector<Type_id> & i_rExceptions)78 Function::Function( const String  &             i_sLocalName,
79                     Ce_id                       i_nOwner,
80                     E_Protection                i_eProtection,
81                     Lid                         i_nFile,
82                     Type_id                     i_nReturnType,
83                     const std::vector<S_Parameter> &
84                                                 i_parameters,
85                     E_ConVol                    i_conVol,
86                     E_Virtuality                i_eVirtuality,
87                     FunctionFlags               i_aFlags,
88                     bool                        i_bThrowExists,
89                     const std::vector<Type_id> &
90                                                 i_rExceptions )
91     :   aEssentials( i_sLocalName,
92                      i_nOwner,
93                      i_nFile ),
94         aTemplateParameterTypes(),
95 		aSignature( Create_ParameterTypeList(i_parameters),
96 		            i_conVol ),
97         nReturnType(i_nReturnType),
98 		eProtection(i_eProtection),
99 		eVirtuality(i_eVirtuality),
100 		aFlags(i_aFlags),
101         aParameterInfos( Create_NonTypeParameterInfos(i_parameters) ),
102         pExceptions( i_bThrowExists ? new ExceptionTypeList(i_rExceptions) : 0 )
103 {
104 }
105 
~Function()106 Function::~Function()
107 {
108 }
109 
110 bool
IsIdentical(const Function & i_f) const111 Function::IsIdentical( const Function & i_f ) const
112 {
113     return
114         LocalName() == i_f.LocalName()
115         AND
116         Owner() == i_f.Owner()
117         AND
118         aSignature == i_f.aSignature
119         AND
120         nReturnType == i_f.nReturnType
121         AND
122         eProtection == i_f.eProtection
123         AND
124         eVirtuality == i_f.eVirtuality
125         AND
126         aFlags == i_f.aFlags
127         AND
128         ( ( NOT pExceptions AND NOT i_f.pExceptions )
129           OR
130           ( pExceptions AND i_f.pExceptions
131                 ?   *pExceptions == *i_f.pExceptions
132                 :   false )
133         )
134         AND
135         aTemplateParameterTypes.size() == i_f.aTemplateParameterTypes.size();
136 }
137 
138 void
Add_TemplateParameterType(const String & i_sLocalName,Type_id i_nIdAsType)139 Function::Add_TemplateParameterType( const String  &    i_sLocalName,
140                                      Type_id            i_nIdAsType )
141 {
142 	aTemplateParameterTypes.push_back(
143 		List_TplParam::value_type(i_sLocalName, i_nIdAsType) );
144 }
145 
146 
147 const String  &
inq_LocalName() const148 Function::inq_LocalName() const
149 {
150 	return aEssentials.LocalName();
151 }
152 
153 Cid
inq_Owner() const154 Function::inq_Owner() const
155 {
156 	return aEssentials.Owner();
157 }
158 
159 Lid
inq_Location() const160 Function::inq_Location() const
161 {
162 	return aEssentials.Location();
163 }
164 
165 void
do_Accept(csv::ProcessorIfc & io_processor) const166 Function::do_Accept(csv::ProcessorIfc & io_processor) const
167 {
168     csv::CheckedCall(io_processor,*this);
169 }
170 
171 ClassId
get_AryClass() const172 Function::get_AryClass() const
173 {
174 	return class_id;
175 }
176 
177 
178 
179 }   // namespace cpp
180 }   // namespace ary
181 
182 
183 
184 namespace
185 {
186 
187 String
operator ()(const ary::cpp::S_Parameter & i_rParam) const188 Parameter_2_NonTypeParamInfo::operator()( const ary::cpp::S_Parameter & i_rParam ) const
189 {
190     static StreamStr aParamName_(1020);
191     aParamName_.seekp(0);
192 
193     aParamName_ << i_rParam.sName;
194     if ( i_rParam.sSizeExpression.length() > 0 )
195     {
196         aParamName_ << '['
197                     << i_rParam.sSizeExpression
198                     << ']';
199     }
200     if ( i_rParam.sInitExpression.length() > 0 )
201     {
202         aParamName_ << " = "
203                     << i_rParam.sInitExpression;
204     }
205 
206     return aParamName_.c_str();
207 }
208 
209 
210 StringVector
Create_NonTypeParameterInfos(const std::vector<S_Parameter> & i_rParameters)211 Create_NonTypeParameterInfos( const std::vector<S_Parameter> & i_rParameters )
212 {
213     static Parameter_2_NonTypeParamInfo
214         aTransformFunction_;
215 
216     StringVector
217         ret(i_rParameters.size(), String::Null_());
218     std::transform( i_rParameters.begin(), i_rParameters.end(),
219                     ret.begin(),
220                     aTransformFunction_ );
221     return ret;
222 }
223 
224 std::vector<Type_id>
Create_ParameterTypeList(const std::vector<S_Parameter> & i_rParameters)225 Create_ParameterTypeList( const std::vector<S_Parameter> & i_rParameters )
226 {
227     static Parameter_2_Type
228         aTransformFunction_;
229 
230     std::vector<Type_id>
231         ret(i_rParameters.size(), Type_id(0));
232     std::transform( i_rParameters.begin(), i_rParameters.end(),
233                     ret.begin(),
234                     aTransformFunction_ );
235     return ret;
236 }
237 
238 
239 
240 
241 }   // namespace anonymous
242