/usr/include/openturns/WrapperObject.hxx is in libopenturns-dev 1.5-7build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | // -*- C++ -*-
/**
* @file WrapperObject.hxx
* @brief An object that binds itself to an external shared library
*
* Copyright 2005-2015 Airbus-EDF-IMACS-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* @author schueller
* @date 2012-02-17 19:35:43 +0100 (Fri, 17 Feb 2012)
*/
#ifndef OPENTURNS_WRAPPEROBJECT_HXX
#define OPENTURNS_WRAPPEROBJECT_HXX
#include "PersistentObject.hxx"
#include "Library.hxx"
#include "WrapperData.hxx"
#include "NumericalPoint.hxx"
#include "NumericalSample.hxx"
#include "Field.hxx"
#include "Matrix.hxx"
#include "SymmetricTensor.hxx"
#include "Description.hxx"
#include "Pointer.hxx"
/* Forward declarations */
struct WrapperExchangedData;
struct WrapperError;
struct WrapperInformation;
BEGIN_NAMESPACE_OPENTURNS
/* Forward declaration */
struct WrapperSymbols;
/**
* @class WrapperObject
* @brief An object that binds itself to an external shared library
*
* A WrapperObject offers an interface for any object (function,
* gradient, hessian) that is located in a external shared
* library.
*/
class OT_API WrapperObject
: public PersistentObject
{
CLASSNAME;
public:
// For test
//static const UnsignedInteger NBCPUS_;
enum ObjectType
{
FUNCTION = 0,
GRADIENT,
HESSIAN,
ObjectPrefixSize
};
enum FunctionType
{
STATE_CREATION = 0,
STATE_DELETION,
INFORMATION,
INITIALIZATION,
EXECUTION,
EXECUTION_SAMPLE,
EXECUTION_FIELD,
FINALIZATION,
FunctionPrefixSize
};
private:
class ObjectPrefix : public std::vector<String>
{
public:
ObjectPrefix();
}; /* class ObjectPrefix */
/** Array of prefix according to object type */
static const ObjectPrefix ObjectPrefix_;
class FunctionPrefix : public std::vector<String>
{
public:
FunctionPrefix();
}; /* class FunctionPrefix */
/** Array of prefix according to function type */
static const FunctionPrefix FunctionPrefix_;
class Error
{
Pointer<struct WrapperError> p_error_;
public :
Error();
~Error();
const struct WrapperError * get() const;
struct WrapperError * get();
};
public:
/**
* Constructor
*
* @param libraryPath the path of the library to load
* @param symbolName the name of the symbol to bind to
* @param data the data to send to the wrapper
* @param o the kind of this object
*/
WrapperObject(const FileName & libraryPath,
const String & symbolName,
const WrapperData & data,
ObjectType o);
/** Destructor */
~WrapperObject();
/** Copy constructor */
WrapperObject(const WrapperObject & other);
/* Virtual constructor */
virtual WrapperObject * clone() const;
/* Comparison operator */
Bool operator ==(const WrapperObject & other) const;
/* String converter */
virtual String __repr__() const;
String __str__(const String & offset = "") const;
/**
* @brief Returns the name of the symbol in the shared library.
* @param f the kind of function we want to bind to
* @return The name of the symbol in the library
* @see Library::getSymbol(String) const
*/
String getFunctionName(FunctionType f) const;
/** Returns the dimension of the input point.
* @param p_state An hidden opaque pointer that points to the storage allocated by the wrapper as an internal state.
* @throw WrapperInternalException
*/
UnsignedInteger getInNumericalPointDimension(void * p_state) const;
/** Returns the dimension of the output point.
* @param p_state An hidden opaque pointer that points to the storage allocated by the wrapper as an internal state.
* @throw WrapperInternalException
*/
UnsignedInteger getOutNumericalPointDimension(void * p_state) const;
/** Returns the description of the input and output variables of the functions.
* @return The description of the input and output variables of the functions.
* @throw WrapperInternalException
*/
Description getDescription() const;
/** @brief Initializes the wrapper in order to start further computations.
*
* The method is where all preliminary actions should be done before lauching the first computation:
* creating directories, copying files, connecting to servers, etc.
* @param p_state An hidden opaque pointer that points to the storage allocated by the wrapper as an internal state.
* The meaning of this internal state is wrapper specific, so Open TURNS doesn't need to know anything about it.
* This internal state is allocated during the call to the createNewState method.
* @throw WrapperInternalException
* @see createNewState()
*/
void initialize(void * p_state) const;
/** @brief Realizes the desired computation within the wrapper.
*
* Initialization must have occured before the call to execute().
* @param p_state The internal state
* @param in A numerical point where the computation must be done
* @return A numerical point which is the result of the computation
* @throw InvalidArgumentException
* @throw WrapperInternalException
* @see createNewState()
* @see initialize(void*) const
*/
NumericalPoint execute(void * p_state, const NumericalPoint & inP) const;
/** @brief Realizes the desired computation within the wrapper.
*
* Initialization must have occured before the call to execute().
* This method acts as if the execute method was repeatedly called on the successive points of the sample,
* but it may use (or not) some specific method of the wrapper to run the whole computation on the sample.
* See func_exec_sample_ wrapper method for more detail.
* @param p_state The internal state
* @param in A numerical sample where the computation must be done
* @return A numerical sample which is the result of the computation
* @throw InvalidArgumentException
* @throw WrapperInternalException
* @see createNewState()
* @see initialize(void*) const
* @see execute(void*,const NumericalPoint&) const
*/
NumericalSample execute(void * p_state, const NumericalSample & inS) const;
/** @brief Realizes the desired computation within the wrapper.
*
* Initialization must have occured before the call to execute().
* This method acts as if the execute method was repeatedly called on the successive points of the sample,
* but it may use (or not) some specific method of the wrapper to run the whole computation on the sample.
* See func_exec_field_ wrapper method for more detail.
* @param p_state The internal state
* @param in A field where the computation must be done
* @return A field which is the result of the computation
* @throw InvalidArgumentException
* @throw WrapperInternalException
* @see createNewState()
* @see initialize(void*) const
* @see execute(void*,const NumericalPoint&) const
*/
Field execute(void * p_state, const Field & inField) const;
/** @brief Realizes the computation of the gradient within the wrapper.
*
* Initialization must have occured before the call to gradient().
* @param p_state The internal state
* @param in A numerical point where the computation must be done
* @return A matrix which is the result of the computation
* @throw InvalidArgumentException
* @throw WrapperInternalException
* @see createNewState()
* @see initialize(void*) const
*/
Matrix gradient(void * p_state, const NumericalPoint & inP) const;
/** @brief Realizes the computation of the hessian within the wrapper.
*
* Initialization must have occured before the call to hessian().
* @param p_state The internal state
* @param in A numerical point where the computation must be done
* @return A tensor which is the result of the computation
* @throw InvalidArgumentException
* @throw WrapperInternalException
* @see createNewState()
* @see initialize(void*) const
*/
SymmetricTensor hessian(void * p_state, const NumericalPoint & inP) const;
/** @brief Finalizes the wrapper in order to stop computations.
*
* The method is where all ultimate actions should be done when all computations are done:
* removing files or directories, closing connections, etc.
* @param p_state An hidden opaque pointer that points to the storage allocated by the wrapper as an internal state.
* The meaning of this internal state is wrapper specific, so Open TURNS doesn't need to know anything about it.
* This internal state is allocated during the call to the createNewState method.
* @throw WrapperInternalException
* @see createNewState()
*/
void finalize(void * p_state) const;
/** @brief Asks the wrapper to build a brand new internal state.
*
* The internal state is a heap allocated storage managed by the wrapper. Open TURNS doesn't know anything
* about it except that it must pass it to every wrapper function. If the wrapper has no use of an internal
* state it may return a null pointer: this isn't an error and shouldn't be treated so.
* The internal state must be deleted by a call to deleteState().
* @return An hidden opaque pointer that points to the storage allocated by the wrapper as an internal state.
* @throw WrapperInternalException
* @see deleteState(void*)
*/
void * createNewState();
/** @brief Asks the wrapper to delete a previously allocated internal state.
*
* The wrapper is in charge of deleting the internal state it allocated before. Don't delete it by yourself !
* @param p_state An hidden opaque pointer that points to the storage allocated by the wrapper as an internal state.
* @throw WrapperInternalException
* @see createNewState()
*/
void deleteState(void * p_state);
protected:
/** Symbol accessor */
LibrarySymbol getSymbol(const String & name, Bool optional = false, LibrarySymbol alternateSymbol = 0) const;
private:
/** The library handle */
Library handle_;
/** The data send to the wrapper */
WrapperData data_;
struct WrapperExchangedData * p_exchangedData_;
/** The kind of object we are */
ObjectType type_;
/** The error emited by the wrapper */
mutable Error error_;
/** The pointer to the library symbols structure */
Pointer<struct WrapperSymbols> wrapperSymbols_;
/* The information structure */
mutable Pointer<struct WrapperInformation> wrapperInfo_;
}; /* class WrapperObject */
END_NAMESPACE_OPENTURNS
#endif /* OPENTURNS_WRAPPEROBJECT_HXX */
|