7 py::class_<DataContainer> py_data_container(m,
"DataContainer", R
"(
8 Container to hold data that is associated with an entity.
11 py_data_container.def(py::init<>(), R"(
12 Construct a new data container.
15 py_data_container.def("set_data", &
DataContainer::set_data, py::arg(
"category"), py::arg(
"key"), py::arg(
"data_type"), py::arg(
"value"), py::arg(
"log_with_info_level") =
false, R
"(
17 May overwrite an existing entry.
19 :param str category: The data category.
20 :param str key: The data key.
21 :param str data_type: The data type.
22 :param str value: The data value.
23 :param bool log_with_info_level: Force explicit logging channel 'netlist' with log level 'info' to trace GUI events.
24 :returns: ``True`` on success, ``False`` otherwise.
29 Determine whether an entry of given category and key exists.
31 :param str category: The data category.
32 :param str key: The data key.
33 :returns: ``True`` if the entry exists, ``False`` otherwise.
38 Get the data entry specified by the given category and key.
40 :param str category: The data category.
41 :param str key: The data key.
42 :returns: The tuple ((1) type, (2) value).
43 :rtype: tuple(str,str)
46 py_data_container.def("delete_data", &
DataContainer::delete_data, py::arg(
"category"), py::arg(
"key"), py::arg(
"log_with_info_level") =
false, R
"(
49 :param str category: The data category.
50 :param str key: The data key.
51 :param bool log_with_info_level: Force explicit logging channel 'netlist' with log level 'info' to trace GUI events.
52 :returns: ``True`` on success, ``False`` otherwise.
57 A dict from ((1) category, (2) key) to ((1) type, (2) value) containing all stored data entries.
59 :type: dict[tuple(str,str),tuple(str,str)]
63 Get a dict from ((1) category, (2) key) to ((1) type, (2) value) containing all stored data entries.
65 :returns: The stored data as a dict.
66 :rtype: dict[tuple(str,str),tuple(str,str)]
69 py_data_container.def("set_parameter", [](
DataContainer&
self,
const Parameter& param,
const std::string& value) ->
bool {
70 auto res =
self.set_parameter(param, value);
77 log_error(
"python_context",
"{}", res.get_error().get());
80 }, py::arg(
"param"), py::arg(
"value"), R
"(
81 Set (or overwrite) the value of a typed parameter as a string. The value is validated, normalized, and stored; any existing entry with the same name is replaced.
83 :param hal_py.Parameter param: The parameter declaration.
84 :param str value: The value to store as a string.
85 :returns: ``True`` on success, ``False`` otherwise.
89 py_data_container.def("get_parameter_value", [](
DataContainer&
self,
const std::string&
name) -> std::optional<std::string> {
90 auto res =
self.get_parameter_value(
name);
97 log_error(
"python_context",
"{}", res.get_error().get());
100 }, py::arg(
"name"), R
"(
101 Get the value of a typed parameter. Returns the explicitly-stored value or ``None`` if the parameter does not exist.
103 :param str name: The parameter name.
104 :returns: The value string on success, ``None`` otherwise.
108 py_data_container.def("get_parameter_value", [](
DataContainer&
self,
const Parameter& param) -> std::optional<std::string> {
109 auto res =
self.get_parameter_value(param);
116 log_error(
"python_context",
"{}", res.get_error().get());
119 }, py::arg(
"name"), R
"(
120 Get the value of a typed parameter. Returns the explicitly-stored value or ``None`` if the parameter does not exist.
122 :param hal_py.Parameter param: The parameter.
123 :returns: The value string on success, ``None`` otherwise.
127 py_data_container.def("get_parameter_declaration", [](
DataContainer&
self,
const std::string&
name) -> std::optional<Parameter> {
128 auto res =
self.get_parameter_declaration(
name);
135 log_error(
"python_context",
"{}", res.get_error().get());
138 }, py::arg(
"name"), R
"(
139 Get the full declaration of a typed parameter.
141 :param str name: The parameter name.
142 :returns: The parameter declaration on success, ``None`` otherwise.
143 :rtype: hal_py.Parameter or None
146 py_data_container.def("has_parameter", py::overload_cast<const std::string&>(&
DataContainer::has_parameter, py::const_), py::arg(
"name"), R
"(
147 Check whether a parameter with the given name exists and has an explicitly stored value.
149 :param str name: The parameter name.
150 :returns: ``True`` if the parameter is explicitly set, ``False`` otherwise.
154 py_data_container.def("has_parameter", py::overload_cast<const Parameter&>(&
DataContainer::has_parameter, py::const_), py::arg(
"param"), R
"(
155 Check whether a parameter exists and has an explicitly stored value.
157 :param hal_py.Parameter param: The parameter.
158 :returns: ``True`` if the parameter is explicitly set, ``False`` otherwise.
163 Delete an explicitly stored parameter value, if any.
165 :param str name: The parameter name.
166 :returns: ``True`` if a value was deleted, ``False`` otherwise.
171 All explicitly stored parameter values as a dict from ``name`` to `(declaration, value)`.
173 :type: dict[str,tuple(hal_py.Parameter,str)]
177 Get all explicitly stored parameter values as a dict from ``name`` to `(declaration, value)`.
179 :returns: The parameter dict.
180 :rtype: dict[str,tuple(hal_py.Parameter,str)]
const std::map< std::tuple< std::string, std::string >, std::tuple< std::string, std::string > > & get_data_map() const
std::tuple< std::string, std::string > get_data(const std::string &category, const std::string &key) const
bool has_parameter(const Parameter ¶m) const
const std::unordered_map< std::string, std::pair< Parameter, std::string > > & get_parameters() const
bool set_data(const std::string &category, const std::string &key, const std::string &data_type, const std::string &value, const bool log_with_info_level=false)
bool has_data(const std::string &category, const std::string &key) const
bool delete_data(const std::string &category, const std::string &key, const bool log_with_info_level=false)
bool delete_parameter(const std::string &name)
void data_container_init(py::module &m)
#define log_error(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)