OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
PythonObjectBuilder.h
Go to the documentation of this file.
1/*****************************************************************/
8#pragma once
9#include <Python.h>
10#include "CPythonObjectNew.h"
12#include "OTCore/Variable.h"
13#include "OTCore/JSON.h"
14#include "OTCore/Variable.h"
16
17#include <stdint.h>
18#include <string>
19#include <list>
20#include <map>
21#include <memory>
22#include <optional>
23
28{
29public:
31 ~PythonObjectBuilder() { Py_XDECREF(_assembly); };
32 void StartTupleAssemply(int size);
33 void operator<<(CPythonObject* newEntry);
35
36 int32_t getInt32Value(const CPythonObject& pValue, const std::string& varName);
37 double getDoubleValue(const CPythonObject& pValue, const std::string& varName);
38 std::string getStringValue(const CPythonObject& pValue, const std::string& varName);
39 bool getBoolValue(const CPythonObject& pValue, const std::string& varName);
40
41 CPythonObjectBorrowed getTupleItem(const CPythonObject& pValue, int position, const std::string& varName);
42 int32_t getInt32ValueFromTuple(const CPythonObject& pValue, int position, const std::string& varName);
43 double getDoubleValueFromTuple(const CPythonObject& pValue, int position, const std::string& varName);
44 std::string getStringValueFromTuple(const CPythonObject& pValue, int position, const std::string& varName);
45 bool getBoolValueFromTuple(const CPythonObject& pValue, int position, const std::string& varName);
46
48 CPythonObjectBorrowed getListItem(const CPythonObject& pValue, int position);
49
50 std::list<int32_t> getInt32List(const CPythonObject& pValue, const std::string& varName);
51 std::list<double> getDoubleList(const CPythonObject& pValue, const std::string& varName);
52 std::list<std::string> getStringList(const CPythonObject& pValue, const std::string& varName);
53 std::list<bool> getBoolList(const CPythonObject& pValue, const std::string& varName);
54
56 ot::GenericDataStruct* getGenericDataStruct(CPythonObject& pValue);
57 std::list<ot::Variable> getVariableList(CPythonObject& pValue);
58 std::optional<ot::Variable> getVariable(CPythonObject& pValue);
59
60 CPythonObjectNew setInt32(const int32_t value);
61 CPythonObjectNew setInt64(const int64_t value);
63 CPythonObjectNew setString(const std::string& value);
64 CPythonObjectNew setBool(const bool value);
65
66 CPythonObjectNew setVariableTuple(const std::list<ot::Variable>& values);
67 CPythonObjectNew setVariableList(const std::list<ot::Variable>& values);
68 CPythonObjectNew setVariableList(const std::vector<ot::Variable>& values);
69 CPythonObjectNew setVariableList(rapidjson::GenericArray<false,rapidjson::Value> & values);
70
72
73 CPythonObjectNew setGenericDataStruct(ot::GenericDataStruct* genericDataStruct);
75
76private:
77 PyObject* _assembly = nullptr;
78 int _assemblySize = 0;
79 int _currentSize = 0;
80
81 void* variableArrayToVoidArray(const ot::Variable* values, const uint32_t size, int& pType);
82 const ot::Variable* voidArrayToVariableArray(void* data, const uint32_t size, int pType);
83};
84
85
Wrapper around a PyObject* that is a borrowed reference. This increments the reference count on const...
Wrapper around a PyObject* that is a new reference. This owns the reference so does not increment it ...
bsoncxx::types::value value
Definition DocumentManager.h:16
Definition CPythonObjectBorrowed.h:15
Definition CPythonObject.h:13
Definition CPythonObjectNew.h:14
PyObjects don't distingiush between float and double and int32 and int64. All floating point values a...
Definition PythonObjectBuilder.h:28
CPythonObjectBorrowed getDictItem(const CPythonObject &pValue)
Definition PythonObjectBuilder.cpp:260
CPythonObjectNew setVariableTuple(const std::list< ot::Variable > &values)
Definition PythonObjectBuilder.cpp:535
int32_t getInt32Value(const CPythonObject &pValue, const std::string &varName)
Definition PythonObjectBuilder.cpp:173
CPythonObjectNew setGenericDataStruct(ot::GenericDataStruct *genericDataStruct)
Definition PythonObjectBuilder.cpp:669
int32_t getInt32ValueFromTuple(const CPythonObject &pValue, int position, const std::string &varName)
Definition PythonObjectBuilder.cpp:220
std::string getStringValueFromTuple(const CPythonObject &pValue, int position, const std::string &varName)
Definition PythonObjectBuilder.cpp:240
bool getBoolValueFromTuple(const CPythonObject &pValue, int position, const std::string &varName)
Definition PythonObjectBuilder.cpp:250
double getDoubleValue(const CPythonObject &pValue, const std::string &varName)
Definition PythonObjectBuilder.cpp:182
void StartTupleAssemply(int size)
Definition PythonObjectBuilder.cpp:140
std::list< double > getDoubleList(const CPythonObject &pValue, const std::string &varName)
Definition PythonObjectBuilder.cpp:296
CPythonObjectNew setInt64(const int64_t value)
Definition PythonObjectBuilder.cpp:501
std::optional< ot::Variable > getVariable(CPythonObject &pValue)
Definition PythonObjectBuilder.cpp:472
ot::GenericDataStruct * getGenericDataStruct(CPythonObject &pValue)
Definition PythonObjectBuilder.cpp:376
void operator<<(CPythonObject *newEntry)
Definition PythonObjectBuilder.cpp:150
CPythonObjectBorrowed getTupleItem(const CPythonObject &pValue, int position, const std::string &varName)
Definition PythonObjectBuilder.cpp:210
std::list< bool > getBoolList(const CPythonObject &pValue, const std::string &varName)
Definition PythonObjectBuilder.cpp:330
CPythonObjectNew setBool(const bool value)
Definition PythonObjectBuilder.cpp:527
std::string getStringValue(const CPythonObject &pValue, const std::string &varName)
Definition PythonObjectBuilder.cpp:191
CPythonObjectNew setVariableList(const std::list< ot::Variable > &values)
Definition PythonObjectBuilder.cpp:552
CPythonObjectNew setGenericDataStructList(ot::GenericDataStructList &values)
Definition PythonObjectBuilder.cpp:704
~PythonObjectBuilder()
Definition PythonObjectBuilder.h:31
std::list< int32_t > getInt32List(const CPythonObject &pValue, const std::string &varName)
Definition PythonObjectBuilder.cpp:280
ot::GenericDataStructList getGenericDataStructList(CPythonObject &pValue)
Definition PythonObjectBuilder.cpp:346
PythonObjectBuilder()
Definition PythonObjectBuilder.cpp:135
CPythonObjectNew setInt32(const int32_t value)
Definition PythonObjectBuilder.cpp:507
CPythonObjectNew setVariable(const ot::Variable &value)
Definition PythonObjectBuilder.cpp:586
CPythonObjectNew setDouble(double value)
Definition PythonObjectBuilder.cpp:513
CPythonObjectNew setString(const std::string &value)
Definition PythonObjectBuilder.cpp:521
double getDoubleValueFromTuple(const CPythonObject &pValue, int position, const std::string &varName)
Definition PythonObjectBuilder.cpp:230
CPythonObjectNew getAssembledTuple()
Definition PythonObjectBuilder.cpp:165
std::list< ot::Variable > getVariableList(CPythonObject &pValue)
Definition PythonObjectBuilder.cpp:426
CPythonObjectBorrowed getListItem(const CPythonObject &pValue, int position)
Definition PythonObjectBuilder.cpp:271
bool getBoolValue(const CPythonObject &pValue, const std::string &varName)
Definition PythonObjectBuilder.cpp:200
std::list< std::string > getStringList(const CPythonObject &pValue, const std::string &varName)
Definition PythonObjectBuilder.cpp:312
Definition Variable.h:107
std::list< ot::GenericDataStruct * > GenericDataStructList
Definition GenericDataStruct.h:27