Scarab  v2.9.0
Project 8 C++ Utility Library
param_pybind.hh
Go to the documentation of this file.
1 /*
2  * param_pybind.hh
3  *
4  * Created on: Feb 1, 2018
5  * Author: N. Oblath, L. Gladstone, B.H. LaRoque
6  */
7 
8 #ifndef PARAM_PYBIND_HH_
9 #define PARAM_PYBIND_HH_
10 
11 #include "param.hh"
12 #include "param_binding_helpers.hh"
13 #include "error.hh"
14 
15 #include "pybind11/pybind11.h"
16 #include "pybind11/pytypes.h"
17 
18 
19 namespace scarab_pybind
20 {
21  std::list< std::string > export_param( pybind11::module& mod )
22  {
23  std::list< std::string > all_members;
24 
25  all_members.push_back( "to_param" );
26  mod.def( "to_param",
27  &to_param,
28  pybind11::arg( "object"),
29  pybind11::arg( "hyphenate_keys" ) = false,
30  "Convert native python types to a param structure." );
31 
32  // param
33  all_members.push_back( "Param" );
34  pybind11::class_< scarab::param >( mod, "Param", "param data structure base class and null object" )
35  .def( pybind11::init< >() )
36  .def( pybind11::init< scarab::param_value >() )
37 
38  .def( "__str__", &scarab::param::to_string )
39  .def( "__call__", (scarab::param_value& (scarab::param::*)()) &scarab::param::operator(),
41 
42  .def( "is_null", &scarab::param::is_null, "return whether the param object is an empty param type" )
43  .def( "is_node", &scarab::param::is_node, "return whether the param object is a ParamNode" )
44  .def( "is_array", &scarab::param::is_array, "return whether the param object is a ParamArray" )
45  .def( "is_value", &scarab::param::is_value, "return whether the param object is a ParamValue" )
46 
47  .def( "as_array",
50  "returns Param object as a ParamArray" )
51  .def( "as_node",
54  "returns Param object as ParamNode" )
55  .def( "as_value",
58  "returns Param object as ParamValue" )
59 
60  .def( "to_python",
61  &to_python,
62  pybind11::arg( "underscore_keys" ) = false,
63  "recursively converts param object to native python data structure" )
64 
65  //TODO: has_subset()
66 
67  //TODO: get_value() in its various types
68 
69  //TODO: merge()
70 
71  ;
72  return all_members;
73  }
74 
75 } /* namespace scarab_pybind */
76 #endif /* PARAM_PYBIND_HH_ */
virtual bool is_value() const
pybind11::object to_python(const scarab::param &a_param, bool underscore_keys=false)
scarab::param_ptr_t to_param(const pybind11::object &an_object, bool hyphenate_keys=false)
std::list< std::string > export_param(pybind11::module &mod)
Definition: param_pybind.hh:21
Wrapper for Python extension modules.
Definition: pybind11.h:789
virtual bool is_null() const
param_value & as_value()
virtual bool is_array() const
virtual bool is_node() const
param_node & as_node()
param_array & as_array()
virtual std::string to_string() const
bool typename Extra class_ & def(const char *name_, Func &&f, const Extra &... extra)
Definition: pybind11.h:1110