"Fossies" - the Fresh Open Source Software Archive

Member "muscle/python/PythonUtilityFunctions.h" (8 Jun 2019, 3688 Bytes) of package /linux/privat/muscle7.30.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "PythonUtilityFunctions.h" see the Fossies "Dox" file reference documentation.

    1 #ifndef PythonUtilityFunctions_h
    2 #define PythonUtilityFunctions_h
    3 
    4 // Python.h is part of the Python2.2.1 distribution, in the Include folder.
    5 // If you want to include PythonUtilityFunctions.h in your code, you'll need
    6 // to make sure that python/Include is in your includes-path.
    7 #include "support/MuscleSupport.h"
    8 #include "Python.h"  
    9 
   10 namespace muscle {
   11 
   12 /** @defgroup pythonutilityfunctions The PythonUtilityFunctions function API
   13  *  These functions are all defined in PythonUtilityFunctions(.cpp,.h), and are stand-alone
   14  *  functions that are useful when embedding a Python interpreter into MUSCLE code.
   15  *  @{
   16  */
   17 
   18 class Message;
   19 class String;
   20 
   21 /** Given the arguments passed by a Python script back to a C callback method, populates the given Message 
   22  *  with corresponding argument data.  
   23  *  @note This function is only useful if you are trying to interface Python scripts and MUSCLE C++ code in the same executable.
   24  *  @param args The args tuple parameter for the positional arguments in the call.  May be NULL.
   25  *  @param keywords The keywords dictionary parameter for the keyword arguments in the call.  May be NULL.
   26  *  @param msg The Message object where the argument data will be written to on success.
   27  *  @return B_NO_ERROR on success, or B_ERROR on failure.
   28  */
   29 status_t ParsePythonArgs(PyObject * args, PyObject * keywords, Message & msg);
   30 
   31 /** Given a Message with the specified field, attempts to return a newly referenced PyObject that
   32  *  represents the value at the (index)'th position in the field.
   33  *  @note This function is only useful if you are interfacing Python and MUSCLE C++ code together in the same executable.
   34  *  @param msg The Message to look into
   35  *  @param fieldName The field name to look in
   36  *  @param index The index of the item in the field to use (often zero)
   37  *  @return A PyObject on success, or NULL (and sets the exception string) on failure.
   38  */
   39 PyObject * ConvertMessageItemToPyObject(const Message & msg, const String & fieldName, uint32 index);
   40 
   41 /** Adds the given PyObject to the given Message, under the given key.
   42  *  Note that this function will not properly handle all possible Python types, but only
   43  *  the more straightforward ones, including:  Ints (stored as int32s), LongLongs (stored as int64s)
   44  *  Floats (stored as floats), Strings (stored as strings), Complex (stored as Points), Unicode
   45  *  (stored as strings in UTF8 format), dicts (stored as Messages... note that the only the keys/value
   46  *  pairs that use strings as keys will be stored), and lists (note that if the list items are not
   47  *  all of the same type, then the list may be stored in a different order)
   48  *  @param optKey If the length of this string is greater than zero, then this string will be used
   49  *                as the field name under which data is added to the Message.  If (optKey) is "",
   50  *                then an appropriate default name will be chosen (see GetDefaultPythonArgFieldName()).
   51  *  @param pyValue The value to add into the Mesasge.  Should not be NULL.
   52  *  @param addToMsg The Message to add the data to.
   53  *  @return B_NO_ERROR on success, or B_ERROR if the function was unable to add the data to the Message.
   54  */
   55 status_t AddPyObjectToMessage(const String & optKey, PyObject * pyValue, Message & addToMsg);
   56 
   57 /** Given a standard data type code (e.g. B_STRING_TYPE) returns the default field name that will
   58  *  be used in a Message for an arg of that type, if a fieldname wasn't explicitly specified.
   59  *  @param type a B_*_TYPE value indicating the type to inquire about
   60  */
   61 const char * GetDefaultPythonArgFieldName(uint32 type);
   62 
   63 /** @} */ // end of pythonutilityfunctions doxygen group
   64 
   65 } // end namespace muscle
   66 
   67 #endif