Skip to content

Commit

Permalink
#1844 Added pyobject_as_bool & pyobject_as_string_array
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Dec 28, 2021
1 parent 0d7b731 commit b053f71
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 35 additions & 1 deletion met/src/libcode/vx_python3_utils/python3_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ using namespace std;
#include <cmath>

#include "vx_log.h"
#include "concat_string.h"
#include "vx_math.h"

#include "python3_util.h"
Expand Down Expand Up @@ -125,6 +124,18 @@ return ( k );
////////////////////////////////////////////////////////////////////////


bool pyobject_as_bool (PyObject * obj)

{

return ( 1 == PyObject_IsTrue(obj) );

}


////////////////////////////////////////////////////////////////////////


double pyobject_as_double (PyObject * obj)

{
Expand Down Expand Up @@ -215,6 +226,29 @@ return ( s );
////////////////////////////////////////////////////////////////////////


StringArray pyobject_as_string_array (PyObject * obj)

{

StringArray a;
ConcatString s;
PyObject *item = 0;

int size = PyList_Size (obj);
for (int idx=0; idx<size; idx++) {
item = PyList_GetItem(obj, idx);
s = pyobject_as_concat_string (item);
a.add(s);
}

return a;

}


////////////////////////////////////////////////////////////////////////


void run_python_string(const char * s)

{
Expand Down
2 changes: 2 additions & 0 deletions met/src/libcode/vx_python3_utils/python3_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ extern PyObject * get_attribute(PyObject *, const char * attribute_name);


extern int pyobject_as_int (PyObject *);
extern bool pyobject_as_bool (PyObject *);
extern double pyobject_as_double (PyObject *);
extern std::string pyobject_as_string (PyObject *);
extern ConcatString pyobject_as_concat_string (PyObject *);
extern StringArray pyobject_as_string_array (PyObject *);


////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit b053f71

Please sign in to comment.