1 #ifndef MHO_PyContainerStoreInterface_HH__
2 #define MHO_PyContainerStoreInterface_HH__
11 #include "pybind11_json/pybind11_json.hpp"
12 #include <pybind11/embed.h>
13 #include <pybind11/pybind11.h>
14 namespace py = pybind11;
15 namespace nl = nlohmann;
16 using namespace pybind11::literals;
38 if(fContainerStore !=
nullptr)
49 return fContainerStore->GetNObjects();
56 if(fContainerStore !=
nullptr)
62 msg_error(
"python_bindings",
"error could not convert: " << uuid_string <<
" to valid UUID" << eom);
64 return fContainerStore->IsObjectPresent(uuid);
72 if(fContainerStore !=
nullptr)
76 type_uuid = fContainerStore->GetObjectTypeUUID(uuid);
87 msg_error(
"python_bindings",
"error could not convert: " << uuid_string <<
" to valid UUID" << eom);
89 XClassType* obj = fContainerStore->GetObject< XClassType >(uuid);
90 auto ext_ptr = GetExtension(obj);
91 if(ext_ptr !=
nullptr)
97 msg_error(
"python_bindings",
"object with uuid: " << uuid_string <<
" is either not present, or is not a: "
98 << MHO_ClassIdentity::ClassName< XClassType >() << eom);
107 std::vector< std::tuple< std::string, std::string, std::string > > info = fContainerStore->GetAllObjectInfo();
108 for(std::size_t i = 0; i < info.size(); i++)
111 item_info[
"type_uuid"] = std::get< 0 >(info[i]);
112 item_info[
"object_uuid"] = std::get< 1 >(info[i]);
113 item_info[
"shortname"] = std::get< 2 >(info[i]);
114 info_obj.push_back(item_info);
116 py::list ret_obj = info_obj;
132 return obj->template AsExtension< MHO_PyTableContainer< XClassType > >();
136 return obj->template MakeExtension< MHO_PyTableContainer< XClassType > >();
143 MHO_ContainerStore* fContainerStore;
148 py::class_< MHO_PyContainerStoreInterface >(m, pyclass_name.c_str())
151 "check if the underlying container store object exists and is valid")
153 "get the number of objects present in the container store")
155 "check if an object with the passed UUID is present", py::arg(
"uuid"))
157 "get a list of the object information (list of dict's containing each object's type_uuid, object_uuid, and "
167 MHO_UUID type_id = cStore->GetObjectTypeUUID(uuid);
169 if(type_id == cStore->GetTypeUUID< visibility_type >())
171 return py::cast(*(m.GetObject< visibility_type >(object_uuid)));
175 return py::cast(*(m.GetObject< weight_type >(object_uuid)));
179 return py::cast(*(m.GetObject< station_coord_type >(object_uuid)));
183 return py::cast(*(m.GetObject< visibility_store_type >(object_uuid)));
188 return py::cast(*(m.GetObject< weight_store_type >(object_uuid)));
193 return py::cast(*(m.GetObject< phasor_type >(object_uuid)));
198 return py::cast(*(m.GetObject< multitone_pcal_type >(object_uuid)));
204 MHO_ObjectTags* tags = cStore->GetObject< MHO_ObjectTags >(uuid);
207 mho_json meta_data = tags->GetMetaDataAsJSON();
208 std::set< MHO_UUID > tagged_ids = tags->GetTaggedObjectUUIDSet();
209 std::vector< std::string > id_list;
210 for(auto it = tagged_ids.begin(); it != tagged_ids.end(); it++)
212 id_list.push_back(it->as_string());
215 meta_data[
"tagged_object_uuid_list"] = id_list;
217 py::dict dict_obj = meta_data;
222 py::print(
"MHO_ObjectTags object with uuid: ", object_uuid,
" cannot be loaded.");
226 py::print(
"object uuid ", object_uuid,
" is not recognized, returning None.");
227 return py::object(py::cast(
nullptr));
229 py::return_value_policy::reference,
"return the object matching the specified uuid", py::arg(
"uuid"));
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
Class MHO_ContainerStore.
Definition: MHO_ContainerStore.hh:32
bool IsObjectPresent(const MHO_UUID &obj_id) const
Checks if an object with a given UUID is present in the container store.
Definition: MHO_ContainerStore.cc:18
MHO_UUID GetTypeUUID()
get the type uuid for a specific type (if it is supported) - if unsupported uuid will be zero
Definition: MHO_ContainerStore.hh:394
python binding to the MHO_ContainerStore
Definition: MHO_PyContainerStoreInterface.hh:30
MHO_ContainerStore * GetContainerStore()
Definition: MHO_PyContainerStoreInterface.hh:122
std::size_t GetNObjects()
Definition: MHO_PyContainerStoreInterface.hh:45
std::string GetObjectTypeUUID(const std::string &uuid_string) const
Definition: MHO_PyContainerStoreInterface.hh:69
bool IsValid()
Definition: MHO_PyContainerStoreInterface.hh:36
bool IsObjectPresent(const std::string &uuid_string) const
Definition: MHO_PyContainerStoreInterface.hh:54
py::list GetObjectList()
Definition: MHO_PyContainerStoreInterface.hh:104
MHO_PyContainerStoreInterface()
Definition: MHO_PyContainerStoreInterface.hh:32
MHO_PyContainerStoreInterface(MHO_ContainerStore *conStore)
Definition: MHO_PyContainerStoreInterface.hh:33
virtual ~MHO_PyContainerStoreInterface()
Definition: MHO_PyContainerStoreInterface.hh:34
MHO_PyTableContainer< XClassType > * GetObject(const std::string &uuid_string)
Definition: MHO_PyContainerStoreInterface.hh:81
python bindings for template MHO_TableContainer objects This extension which allows us to present the...
Definition: MHO_PyTableContainer.hh:40
Class MHO_UUID - a class for a 16 byte UUID (for object and type identification)
Definition: MHO_UUID.hh:27
std::string as_string() const
Definition: MHO_UUID.hh:125
bool from_string(const std::string &uuid_str)
Definition: MHO_UUID.hh:143
Definition: MHO_AdhocFlagging.hh:18
void DeclarePyContainerStoreInterface(py::module &m, std::string pyclass_name)
Definition: MHO_PyContainerStoreInterface.hh:146