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