Scarab  v2.11.1
Project 8 C++ Utility Library
param_value_pybind.hh
Go to the documentation of this file.
1 /*
2  *
3  * Created on: Feb 1, 2018
4  * Author: N. Oblath, L. Gladstone, B.H. LaRoque
5  */
6 
7 #ifndef PARAM_VALUE_PYBIND_HH_
8 #define PARAM_VALUE_PYBIND_HH_
9 
10 #include "param.hh"
11 
12 #include "pybind11/pybind11.h"
13 
14 namespace scarab_pybind
15 {
16 
17  std::list< std::string > export_param_value( pybind11::module& mod )
18  {
19  std::list< std::string > all_members;
20 
21  // param_value
22  all_members.push_back( "ParamValue" );
23  pybind11::class_< scarab::param_value, scarab::param >( mod, "ParamValue", "param data structure object for holding a single value" )
24  // initialization overloads by type
25  .def( pybind11::init< bool >() )
26  .def( pybind11::init< unsigned >() )
27  .def( pybind11::init< int >() )
28  .def( pybind11::init< double >() )
29  .def( pybind11::init< const std::string& >() )
30  .def( pybind11::init< const char* >() )
31 
32  // python __ special functions
33  .def( "__str__", &scarab::param_value::to_string )
34  .def( "__eq__", &scarab::param_value::operator== )
35 
36  .def( "type", &scarab::param_value::type, "returns a string representation of the stored data type" )
37  // type checking methods
38  .def( "is_bool", (bool (scarab::param_value::*)() const) &scarab::param_value::is_bool,
39  "Return whether the param_value stores a boolean value" )
40  .def( "is_uint", (bool (scarab::param_value::*)() const) &scarab::param_value::is_uint,
41  "Return whether the param_value stores an unsigned integer value" )
42  .def( "is_int", (bool (scarab::param_value::*)() const) &scarab::param_value::is_int,
43  "Return whether the param_value stores a signed integer value" )
44  .def( "is_double", (bool (scarab::param_value::*)() const) &scarab::param_value::is_double,
45  "Return whether the param_value stores a double value" )
46  .def( "is_string", (bool (scarab::param_value::*)() const) &scarab::param_value::is_string,
47  "Return whether the param_value stores a string value" )
48 
49  // output cast to native types
50  .def( "as_bool", &scarab::param_value::as_bool, "Get parameter value as a bool" )
51  .def( "as_uint", &scarab::param_value::as_uint, "Get parameter value as an unsigned integer" )
52  .def( "as_int", &scarab::param_value::as_int, "Get parameter value as a signed integer" )
53  .def( "as_double", &scarab::param_value::as_double, "Get parameter value as a float" )
54  .def( "as_string", &scarab::param_value::as_string, "Get parameter value as a string" )
55 
56  // set method overloads
57  .def( "set", (void (scarab::param_value::*)(bool)) &scarab::param_value::set,
58  "Set a bool value" )
59  //.def( "set", (void (scarab::param_value::*)(unsigned)) &scarab::param_value::set<uint64_t>, "Set an unsigned integer value" )
60  .def("set",&scarab::param_value::set<uint64_t>,
61  "Set an unsigned integer value")
62  //.def( "set", (void (scarab::param_value::*)(int)) &scarab::param_value::set<int64_t>, "Set a signed integer value" )
63  .def("set", &scarab::param_value::set<int64_t>,
64  "Set a signed integer value")
65  .def( "set", (void (scarab::param_value::*)(double)) &scarab::param_value::set,
66  "Set an float value" )
67  .def( "set", (void (scarab::param_value::*)(std::string)) &scarab::param_value::set,
68  "Set an string value" )
69 
70  //TODO: empty(), clear(), has_subset()
71 
72  ;
73  return all_members;
74  }
75 
76 } /* namespace scarab_pybind */
77 #endif /* PARAM_VALUE_PYBIND_HH_ */
int64_t as_int() const
Definition: param_value.hh:522
bool is_bool() const
Definition: param_value.hh:487
std::string type() const
Definition: param_value.hh:472
bool is_uint() const
Definition: param_value.hh:492
Wrapper for Python extension modules.
Definition: pybind11.h:789
double as_double() const
Definition: param_value.hh:527
virtual std::string to_string() const
Definition: param_value.hh:549
bool as_bool() const
Definition: param_value.hh:512
bool is_double() const
Definition: param_value.hh:502
void set(XValType a_value)
Definition: param_value.hh:543
bool is_string() const
Definition: param_value.hh:507
uint64_t as_uint() const
Definition: param_value.hh:517
std::list< std::string > export_param_value(pybind11::module &mod)
bool is_int() const
Definition: param_value.hh:497
std::string as_string() const
Definition: param_value.hh:532
bool typename Extra class_ & def(const char *name_, Func &&f, const Extra &... extra)
Definition: pybind11.h:1110