~ubuntu-branches/ubuntu/maverick/openturns/maverick

« back to all changes in this revision

Viewing changes to lib/src/Base/Func/WrapperData.hxx

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2008-11-18 06:32:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20081118063222-pa0qncclrerrqkg2
Tags: 0.12.2-1
* New upstream release
* Bug fix: "New upstream release available (0.12.2)", thanks to Jerome
  Robert (Closes: #506005).
* Applied patch by J. Robert.
* debian/control: build-depends on libxml2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//                                               -*- C++ -*-
 
2
/**
 
3
 *  @file  WrapperData.hxx
 
4
 *  @brief This class declares the wrapper data that are exchanged with the platform
 
5
 *
 
6
 *  (C) Copyright 2005-2007 EDF-EADS-Phimeca
 
7
 *
 
8
 *  This library is free software; you can redistribute it and/or
 
9
 *  modify it under the terms of the GNU Lesser General Public
 
10
 *  License as published by the Free Software Foundation; either
 
11
 *  version 2.1 of the License.
 
12
 *
 
13
 *  This library is distributed in the hope that it will be useful
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 *  Lesser General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU Lesser General Public
 
19
 *  License along with this library; if not, write to the Free Software
 
20
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
21
 *
 
22
 *  @author: $LastChangedBy: dutka $
 
23
 *  @date:   $LastChangedDate: 2008-10-29 18:54:45 +0100 (mer 29 oct 2008) $
 
24
 *  Id:      $Id: WrapperData.hxx 990 2008-10-29 17:54:45Z dutka $
 
25
 */
 
26
#ifndef OPENTURNS_WRAPPERDATA_HXX
 
27
#define OPENTURNS_WRAPPERDATA_HXX
 
28
 
 
29
#include <iostream>              // for std::ostream
 
30
#include "OT.hxx"
 
31
#include "Object.hxx"
 
32
#include "Pointer.hxx"           // for shared pointer
 
33
#include "WrapperInterface.h"
 
34
#include "Collection.hxx"
 
35
 
 
36
namespace OpenTURNS
 
37
{
 
38
 
 
39
  namespace Base
 
40
  {
 
41
 
 
42
    namespace Func
 
43
    {
 
44
 
 
45
      /**
 
46
       * @struct WrapperSymbolProvided
 
47
       *
 
48
       * Stores information about the presence or no of symbols in the wrapper
 
49
       */
 
50
      struct WrapperSymbolProvided 
 
51
      {
 
52
        typedef Bool Value;
 
53
        static const Value NO  = WRAPPER_NO;
 
54
        static const Value YES = WRAPPER_YES;
 
55
      };
 
56
 
 
57
 
 
58
      /**
 
59
       * @struct WrapperComputedGradient
 
60
       *
 
61
       * Stores information about the computation of gradient for a variable
 
62
       */
 
63
      struct WrapperComputedGradient
 
64
      {
 
65
        typedef Bool Value;
 
66
        static const Value NO  = WRAPPER_NO;
 
67
        static const Value YES = WRAPPER_YES;
 
68
      };
 
69
 
 
70
 
 
71
      /** 
 
72
       * @struct WrapperFunctionDescription
 
73
       *
 
74
       * WrapperFunctionDescription describes what is the interface af a numerical function
 
75
       */
 
76
      struct WrapperFunctionDescription
 
77
        : public Common::Object
 
78
      {
 
79
        String name_;
 
80
        WrapperSymbolProvided::Value provided_;
 
81
 
 
82
        WrapperFunctionDescription();
 
83
        virtual String str() const;
 
84
      };
 
85
 
 
86
 
 
87
      /**
 
88
       * @struct WrapperDataFileType
 
89
       *
 
90
       * Stores the type (input or output) of the file
 
91
       */
 
92
      struct WrapperDataFileType
 
93
      {
 
94
        typedef unsigned long Value;
 
95
        static const Value IN  = WRAPPER_IN;
 
96
        static const Value OUT = WRAPPER_OUT;
 
97
      };
 
98
 
 
99
      /**
 
100
       * @struct WrapperDataFile
 
101
       *
 
102
       * This struct holds the name and the path of any file passed as argument to the wrapper
 
103
       */
 
104
      struct WrapperDataFile
 
105
        : public Common::Object
 
106
      {
 
107
        String id_;                       ///< The id of the file (any string to distinguish each file from another)
 
108
        String name_;                     ///< The name of the file (stdin, stdout, log, etc.)
 
109
        FileName path_;                   ///< The path of the file (/tmp/stdin, /var/log/mylog, etc.)
 
110
        String subst_;                    ///< The list of variable's ids to be substituted in the file
 
111
        WrapperDataFileType::Value type_; ///< The type of the file (input or output)
 
112
 
 
113
        WrapperDataFile();
 
114
        virtual String str() const;
 
115
      }; /* struct WrapperDataFile */
 
116
 
 
117
 
 
118
 
 
119
 
 
120
      /**
 
121
       * @struct WrapperDataVariableType
 
122
       *
 
123
       * Stores the type (input or output) of the variable
 
124
       */
 
125
      struct WrapperDataVariableType {
 
126
        typedef unsigned long Value;
 
127
        static const Value IN  = WRAPPER_IN;
 
128
        static const Value OUT = WRAPPER_OUT;
 
129
      };
 
130
 
 
131
      /**
 
132
       * @struct WrapperDataVariable
 
133
       *
 
134
       * This struct holds information of any variable passed as argument to the wrapper
 
135
       */
 
136
      struct WrapperDataVariable
 
137
        : public Common::Object
 
138
      {
 
139
        String id_;                               ///< The id of the variable (any string to distinguish each variable from another)
 
140
        String comment_;                          ///< A comment to inform on the variable
 
141
        String unit_;                             ///< The unit which the variable is expressed in
 
142
        String regexp_;                           ///< The regular expression used to find the variable location in files
 
143
        String format_;                           ///< The format in which the variable must be printed in files
 
144
        WrapperDataVariableType::Value type_;     ///< The type of the variable (input or output)
 
145
        WrapperComputedGradient::Value gradient_; ///< The gradient of this variable is computed if true
 
146
 
 
147
        WrapperDataVariable();
 
148
        virtual String str() const;
 
149
      }; /* struct WrapperDataVariable */
 
150
 
 
151
 
 
152
 
 
153
 
 
154
      /**
 
155
       * @struct WrapperState
 
156
       *
 
157
       * Stores the mode of invocation of the external code
 
158
       */
 
159
      struct WrapperState
 
160
      {
 
161
        typedef unsigned long Value;
 
162
        static const Value SHARED   = WRAPPER_SHAREDSTATE;
 
163
        static const Value SPECIFIC = WRAPPER_SPECIFICSTATE;
 
164
      };
 
165
 
 
166
 
 
167
      /**
 
168
       * @struct WrapperMode
 
169
       *
 
170
       * Stores the mode of invocation of the external code
 
171
       */
 
172
      struct WrapperMode
 
173
      {
 
174
        typedef unsigned long Value;
 
175
        static const Value STATICLINK  = WRAPPER_STATICLINK;
 
176
        static const Value DYNAMICLINK = WRAPPER_DYNAMICLINK;
 
177
        static const Value FORK        = WRAPPER_FORK;
 
178
      };
 
179
 
 
180
 
 
181
      /**
 
182
       * @struct WrapperDataTransfer
 
183
       *
 
184
       * Stores the mode of transmission for the arguments
 
185
       */
 
186
      struct WrapperDataTransfer
 
187
      {
 
188
        typedef unsigned long Value;
 
189
        static const Value FILES     = WRAPPER_FILES;
 
190
        static const Value PIPE      = WRAPPER_PIPE;
 
191
        static const Value ARGUMENTS = WRAPPER_ARGUMENTS;
 
192
        static const Value SOCKET    = WRAPPER_SOCKET;
 
193
        static const Value CORBA     = WRAPPER_CORBA;
 
194
      };
 
195
 
 
196
 
 
197
      /**
 
198
       * struct WrapperParameter
 
199
       *
 
200
       * This structure holds the configuration of the wrapper
 
201
       */
 
202
      struct WrapperParameter
 
203
        : public Common::Object
 
204
      {
 
205
        WrapperState::Value        state_; ///< The sharing mode of internal state
 
206
        WrapperMode::Value         mode_;  ///< The mode of invocation of the external code
 
207
        WrapperDataTransfer::Value in_;    ///< The transmission mode for input arguments
 
208
        WrapperDataTransfer::Value out_;   ///< The transmission mode for output arguments
 
209
        String command_;                   ///< The command that should invoque the external code according to mode
 
210
 
 
211
        WrapperParameter();
 
212
        virtual String str() const;
 
213
      }; /* struct WrapperParameter */
 
214
 
 
215
 
 
216
 
 
217
      /**
 
218
       * @class WrapperData
 
219
       *
 
220
       * This class declares the wrapper data that are exchanged with the platform
 
221
       */
 
222
      class WrapperData 
 
223
        : public Common::Object
 
224
      {
 
225
        CLASSNAME;
 
226
      public:
 
227
        typedef Type::Collection<WrapperDataFile>     FileListType;
 
228
        typedef Type::Collection<WrapperDataVariable> VariableListType;
 
229
 
 
230
        /** Default constructor */
 
231
        WrapperData();
 
232
 
 
233
        /** String converter */
 
234
        virtual String str() const;
 
235
 
 
236
        /** Library path accessor */
 
237
        void setLibraryPath(const FileName & path);
 
238
        FileName getLibraryPath() const;
 
239
 
 
240
        /** Function description accessor */
 
241
        void setFunctionDescription(const WrapperFunctionDescription & funcDescription);
 
242
        WrapperFunctionDescription getFunctionDescription() const;
 
243
 
 
244
        /** Gradient description accessor */
 
245
        void setGradientDescription(const WrapperFunctionDescription & gradDescription);
 
246
        WrapperFunctionDescription getGradientDescription() const;
 
247
 
 
248
        /** Hessian description accessor */
 
249
        void setHessianDescription(const WrapperFunctionDescription & hessDescription);
 
250
        WrapperFunctionDescription getHessianDescription() const;
 
251
 
 
252
        /** Accessor */
 
253
        void setFileList(const FileListType & fileList);
 
254
        const FileListType & getFileList() const;
 
255
 
 
256
        /** Conversion method for C interface */
 
257
        struct WrapperFileList * getNewFileListForCInterface() const;
 
258
 
 
259
        /** Frees the memory allocated by getNewFileListForCInterface() method */
 
260
        void freeFileListForCInterface(const struct WrapperFileList * fileList) const;
 
261
 
 
262
        /** Accessor */
 
263
        void setVariableList(const VariableListType & variableList);
 
264
        const VariableListType & getVariableList() const;
 
265
 
 
266
        /** Conversion method for C interface */
 
267
        struct WrapperVariableList * getNewVariableListForCInterface() const;
 
268
 
 
269
        /** Frees the memory allocated by getNewVariableListForCInterface() method */
 
270
        void freeVariableListForCInterface(const struct WrapperVariableList * variableList) const;
 
271
 
 
272
        /** Accessor */
 
273
        void setParameters(const WrapperParameter & parameters);
 
274
        const WrapperParameter & getParameters() const;
 
275
 
 
276
        /** Conversion method for C interface */
 
277
        struct WrapperConfiguration * getNewParametersForCInterface() const;
 
278
 
 
279
        /** Frees the memory allocated by getNewParametersForCInterface() method */
 
280
        void freeParametersForCInterface(const struct WrapperConfiguration * parameters) const;
 
281
 
 
282
      protected:
 
283
 
 
284
      private:
 
285
 
 
286
        /** Where the library that hold the function is located */
 
287
        FileName libraryPath_;
 
288
 
 
289
        /** The description of the function to be bound to */
 
290
        WrapperFunctionDescription function_;
 
291
 
 
292
        /** The description of the gradient of the function */
 
293
        WrapperFunctionDescription gradient_;
 
294
 
 
295
        /** The description of the hessian of the function */
 
296
        WrapperFunctionDescription hessian_;
 
297
 
 
298
        /** A shared pointer on the list of files that are exchanged between the platform and the wrapper */
 
299
        Common::Pointer<FileListType> p_fileList_;
 
300
 
 
301
        /** A shared pointer on the list of variables that are exchanged between the platform and the wrapper */
 
302
        Common::Pointer<VariableListType> p_variableList_;
 
303
 
 
304
        /** A shared pointer on the parameters for the wrapper */
 
305
        Common::Pointer<WrapperParameter> p_parameters_;
 
306
 
 
307
      }; /* class WrapperData */
 
308
 
 
309
 
 
310
    } /* namespace Func */
 
311
  } /* namespace Base */
 
312
} /* namespace OpenTURNS */
 
313
 
 
314
#endif /* OPENTURNS_WRAPPERDATA_HXX */