Skip to content

Commit

Permalink
update bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
finger563 committed Jul 31, 2024
1 parent 2b1dccc commit 6245807
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 75 deletions.
8 changes: 5 additions & 3 deletions lib/autogenerate_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def my_litgen_options() -> litgen.LitgenOptions:
# To prevent the generation of the default constructor with named parameters
# for a specific struct, you can use the following option:
options.struct_create_default_named_ctor__regex = r".*" # default
options.class_create_default_named_ctor__regex = r"" # default
options.class_create_default_named_ctor__regex = r".*"

# ///////////////////////////////////////////////////////////////////
# Exclude functions and/or parameters from the bindings
Expand All @@ -55,9 +55,9 @@ def my_litgen_options() -> litgen.LitgenOptions:
# Override virtual methods in python
# ////////////////////////////////////////////////////////////////////
# The virtual methods of this class can be overriden in python
options.class_template_options.add_specialization(r"WeightedConfig", ["espp::Vector2f"]) # NOTE: this doesn't seem to work
options.class_template_options.add_specialization(r"Bezier", ["espp::Vector2f"])
options.class_template_options.add_specialization(r"Bezier::Config", ["espp::Vector2f"]) # NOTE: this doesn't seem to work
options.class_template_options.add_specialization(r"Bezier::WeightedConfig", ["espp::Vector2f"]) # NOTE: this doesn't seem to work
options.class_template_options.add_specialization(r"RangeMapper", ["int", "float"])
options.class_template_options.add_specialization(r"RangeMapper::Config", ["int", "float"]) # NOTE: this doesn't seem to work
options.class_template_options.add_specialization(r"Vector2d", ["int", "float"]) # NOTE: this still generates some bindings which are not specialized for some reason
Expand Down Expand Up @@ -106,7 +106,6 @@ def autogenerate() -> None:
include_dir = repository_dir + "/components/"
header_files = [include_dir + "base_component/include/base_component.hpp",
include_dir + "color/include/color.hpp",
include_dir + "csv/include/csv.hpp",
include_dir + "event_manager/include/event_manager.hpp",
# include_dir + "file_system/include/file_system.hpp", # can't deal with singleton that does not support constructor / destructor
include_dir + "ftp/include/ftp_server.hpp",
Expand All @@ -133,6 +132,9 @@ def autogenerate() -> None:
# include_dir + "state_machine/include/state_base.hpp",
# include_dir + "state_machine/include/magic_enum.hpp",

# csv (template header):
# include_dir + "csv/include/csv.hpp",

# tabulate (template header):
# include_dir + "tabulate/include/tabulate.hpp",

Expand Down
87 changes: 43 additions & 44 deletions lib/python_bindings/espp/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class BaseComponent:




class Rgb:
"""*
* @brief Class representing a color using RGB color space.
Expand Down Expand Up @@ -125,17 +126,18 @@ class Rgb:
def __init__(self, hsv: Hsv) -> None:
"""*
* @brief Construct an Rgb object from the provided Hsv object.
* @note This calls hsv.rgb() on the provided object, which means fthat
* invalid HSV data (not in the ranges [0,360], [0,1], and [0,1])
* could lead to bad RGB data. The Rgb constructor will automatically
* convert the values to be in the proper range, but the perceived
* color will be changed.
* @note This calls hsv.rgb() on the provided object, which means that invalid
* HSV data (not in the ranges [0,360], [0,1], and [0,1]) could lead to
* bad RGB data. The Rgb constructor will automatically convert the
* values to be in the proper range, but the perceived color will be
* changed.
* @param hsv Hsv object to copy.
"""
pass



def __add__(self, rhs: Rgb) -> Rgb:
"""*
* @brief Perform additive color blending (averaging)
Expand Down Expand Up @@ -217,6 +219,7 @@ class Hsv:
def __ne__(self, rhs: Hsv) -> bool:
pass


def rgb(self) -> Rgb:
"""*
* @brief Get a RGB representation of this HSV color.
Expand All @@ -225,39 +228,23 @@ class Hsv:
"""
pass

# namespace espp

#################### </generated_from:color.hpp> ####################


#################### <generated_from:csv.hpp> ####################



@overload
def color_code(rgb: Rgb) -> Any:
"""
(C++ auto return type)
"""
pass
@overload
def color_code(hsv: Hsv) -> Any:
"""
(C++ auto return type)
"""
pass

class __csv_documentation__:
"""*
* @brief Comma Separated Value (CSV) reader/writer convenience wrapper around
* <a href="https://github.com/p-ranav/csv2">p-ranav/csv2</a> which
* exposes csv2::Reader and csv2::Writer classes for managing efficient
* (lazy-loaded) parsing and serizaliztion of human-readable
* CSV-formatted data.
*
* @note This class does not really exist or do anything, but it's the only
* way I could figure out how to get this documentation built into the
* system :(
*
* \section csv_ex1 CSV Reader Example
* \snippet csv_example.cpp csv reader example
* \section csv_ex2 Complex CSV Writer Example
* \snippet csv_example.cpp csv writer example

"""
def __init__(self) -> None:
"""Autogenerated default constructor"""
pass
# namespace espp

#################### </generated_from:csv.hpp> ####################
#################### </generated_from:color.hpp> ####################


#################### <generated_from:event_manager.hpp> ####################
Expand Down Expand Up @@ -555,7 +542,7 @@ class Logger:


def __init__(self) -> None:
"""Autogenerated default constructor"""
"""Auto-generated default constructor"""
pass

#################### </generated_from:logger.hpp> ####################
Expand Down Expand Up @@ -626,7 +613,7 @@ class Bezier_espp_Vector2f: # Python specialization for Bezier<espp::Vector2f>
pass

def __init__(self) -> None:
"""Autogenerated default constructor"""
"""Auto-generated default constructor"""
pass
# </template specializations for class Bezier>
# ------------------------------------------------------------------------
Expand Down Expand Up @@ -805,6 +792,9 @@ class Gaussian:
#/< max output (alpha), 1 is more of a small wave around the max output (alpha).
alpha: float = float(1.0) #/< Max amplitude of the gaussian output, defautls to 1.0.
beta: float = float(0.5) #/< Beta value for the gaussian, default to be symmetric at 0.5 in range [0,1].

def __eq__(self, rhs: Gaussian.Config) -> bool:
pass
def __init__(
self,
gamma: float = float(),
Expand All @@ -830,8 +820,13 @@ class Gaussian:
alpha: float #/<! Max amplitude of the gaussian output, defautls to 1.0.
beta: float #/<! Shifting / Beta value for the gaussian, default to be
#/ symmetric at 0.5 in range [0,1].
def __init__(self) -> None:
"""Autogenerated default constructor"""
def __init__(
self,
gamma: float = float(),
alpha: float = float(),
beta: float = float()
) -> None:
"""Auto-generated default constructor with named params"""
pass

#################### </generated_from:gaussian.hpp> ####################
Expand Down Expand Up @@ -1805,6 +1800,8 @@ class Vector2d_float: # Python specialization for Vector2d<float>
#################### <generated_from:socket.hpp> ####################


# if we're on windows, we cannot include netinet/in.h and instead need to use
# winsock2.h



Expand Down Expand Up @@ -1986,7 +1983,7 @@ class Socket:
pass

def __init__(self) -> None:
"""Autogenerated default constructor"""
"""Auto-generated default constructor"""
pass

# namespace espp
Expand All @@ -1997,6 +1994,8 @@ class Socket:
#################### <generated_from:tcp_socket.hpp> ####################


# if we're on windows, we cannot include netinet/in.h and instead need to use
# winsock2.h


class TcpSocket:
Expand Down Expand Up @@ -2234,7 +2233,7 @@ class TcpSocket:
pass

def __init__(self) -> None:
"""Autogenerated default constructor"""
"""Auto-generated default constructor"""
pass

#################### </generated_from:tcp_socket.hpp> ####################
Expand Down Expand Up @@ -2403,7 +2402,7 @@ class UdpSocket:
pass

def __init__(self) -> None:
"""Autogenerated default constructor"""
"""Auto-generated default constructor"""
pass

#################### </generated_from:udp_socket.hpp> ####################
Expand Down Expand Up @@ -2613,7 +2612,7 @@ class Task:


def __init__(self) -> None:
"""Autogenerated default constructor"""
"""Auto-generated default constructor"""
pass

# namespace espp
Expand Down Expand Up @@ -2747,7 +2746,7 @@ class Timer:
pass

def __init__(self) -> None:
"""Autogenerated default constructor"""
"""Auto-generated default constructor"""
pass

#################### </generated_from:timer.hpp> ####################
Expand Down
48 changes: 20 additions & 28 deletions lib/python_bindings/pybind_espp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ void py_init_module_espp(py::module &m) {
"the values to copy.\n")
.def(py::init<const espp::Hsv &>(), py::arg("hsv"),
"*\n * @brief Construct an Rgb object from the provided Hsv object.\n * @note "
"This calls hsv.rgb() on the provided object, which means fthat\n * invalid "
"HSV data (not in the ranges [0,360], [0,1], and [0,1])\n * could lead to "
"bad RGB data. The Rgb constructor will automatically\n * convert the "
"values to be in the proper range, but the perceived\n * color will be "
"This calls hsv.rgb() on the provided object, which means that invalid\n * "
"HSV data (not in the ranges [0,360], [0,1], and [0,1]) could lead to\n * "
"bad RGB data. The Rgb constructor will automatically convert the\n * "
"values to be in the proper range, but the perceived color will be\n * "
"changed.\n * @param hsv Hsv object to copy.\n")
.def("__add__", &espp::Rgb::operator+, py::arg("rhs"),
"*\n * @brief Perform additive color blending (averaging)\n * @param rhs Other "
Expand Down Expand Up @@ -121,24 +121,13 @@ void py_init_module_espp(py::module &m) {
.def("rgb", &espp::Hsv::rgb,
"*\n * @brief Get a RGB representation of this HSV color.\n * @return An RGB "
"object containing the RGB representation.\n");
//////////////////// </generated_from:color.hpp> ////////////////////

//////////////////// <generated_from:csv.hpp> ////////////////////
auto pyClass__csv_documentation__ =
py::class_<espp::__csv_documentation__>(
m, "__csv_documentation__", py::dynamic_attr(),
"*\n * @brief Comma Separated Value (CSV) reader/writer convenience wrapper around\n * "
" <a href=\"https://github.com/p-ranav/csv2\">p-ranav/csv2</a> which\n * "
"exposes csv2::Reader and csv2::Writer classes for managing efficient\n * "
"(lazy-loaded) parsing and serizaliztion of human-readable\n * CSV-formatted "
"data.\n *\n * @note This class does not really exist or do anything, but it's the "
"only\n * way I could figure out how to get this documentation built into the\n * "
" system :(\n *\n * \\section csv_ex1 CSV Reader Example\n * \\snippet "
"csv_example.cpp csv reader example\n * \\section csv_ex2 Complex CSV Writer Example\n * "
"\\snippet csv_example.cpp csv writer example\n")
.def(py::init<>()) // implicit default constructor
;
//////////////////// </generated_from:csv.hpp> ////////////////////
m.def("color_code", py::overload_cast<const espp::Rgb &>(espp::color_code), py::arg("rgb"),
"\n(C++ auto return type)");

m.def("color_code", py::overload_cast<const espp::Hsv &>(espp::color_code), py::arg("hsv"),
"\n(C++ auto return type)");
//////////////////// </generated_from:color.hpp> ////////////////////

//////////////////// <generated_from:event_manager.hpp> ////////////////////
auto pyClassEventManager =
Expand Down Expand Up @@ -349,11 +338,13 @@ void py_init_module_espp(py::module &m) {
"/< Array of 4 weights, default is array of 1.0");
} // end of inner classes & enums of Bezier_espp_Vector2f

pyClassBezier_espp_Vector2f.def(
"__call__", &espp::Bezier<espp::Vector2f>::operator(), py::arg("t"),
"*\n * @brief Evaluate the bezier at \\p t.\n * @note Convienience wrapper around "
"the at() method.\n * @param t The evaluation parameter, [0, 1].\n * @return The "
"bezier evaluated at \\p t.\n");
pyClassBezier_espp_Vector2f.def(py::init<const espp::Bezier<espp::Vector2f>::Config &>())
.def(py::init<const espp::Bezier<espp::Vector2f>::WeightedConfig &>())
.def("__call__", &espp::Bezier<espp::Vector2f>::operator(), py::arg("t"),
"*\n * @brief Evaluate the bezier at \\p t.\n * @note Convienience wrapper around "
"the "
"at() method.\n * @param t The evaluation parameter, [0, 1].\n * @return The bezier "
"evaluated at \\p t.\n");
//////////////////// </generated_from:bezier.hpp> ////////////////////

//////////////////// <generated_from:fast_math.hpp> ////////////////////
Expand Down Expand Up @@ -457,10 +448,11 @@ void py_init_module_espp(py::module &m) {
"/< Max amplitude of the gaussian output, defautls to 1.0.")
.def_readwrite(
"beta", &espp::Gaussian::Config::beta,
"/< Beta value for the gaussian, default to be symmetric at 0.5 in range [0,1].");
"/< Beta value for the gaussian, default to be symmetric at 0.5 in range [0,1].")
.def("__eq__", &espp::Gaussian::Config::operator==, py::arg("rhs"));
} // end of inner classes & enums of Gaussian

pyClassGaussian
pyClassGaussian.def(py::init<const espp::Gaussian::Config &>())
.def("__call__", &espp::Gaussian::operator(), py::arg("t"),
"*\n * @brief Evaluate the gaussian at \\p t.\n * @note Convienience wrapper around "
"the at() method.\n * @param t The evaluation parameter, [0, 1].\n * @return The "
Expand Down

0 comments on commit 6245807

Please sign in to comment.