/* ---------------------------------------------------------------------------- * GTSAM Copyright 2010, Georgia Tech Research Corporation, * Atlanta, Georgia 30332-0415 * All Rights Reserved * Authors: Frank Dellaert, et al. (see THANKS for the full author list) * See LICENSE for the license information * -------------------------------------------------------------------------- */ /** * @brief wraps Symbol class to python * @author Ellon Paiva Mendes (LAAS-CNRS) **/ #include #include #define NO_IMPORT_ARRAY #include #include // for stringstream #include "gtsam/inference/Symbol.h" using namespace boost::python; using namespace gtsam; BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(print_overloads, Symbol::print, 0, 1) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(equals_overloads, Symbol::equals, 1, 2) // Helper function to allow building a symbol from a python string and a index. static boost::shared_ptr makeSymbol(const std::string &str, size_t j) { if(str.size() > 1) throw std::runtime_error("string argument must have one character only"); return boost::make_shared(str.at(0),j); } // Helper function to print the symbol as "char-and-index" in python std::string selfToString(const Symbol & self) { return (std::string)self; } // Helper function to convert a Symbol to int using int() cast in python size_t selfToKey(const Symbol & self) { return self.key(); } // Helper function to recover symbol's unsigned char as string std::string chrFromSelf(const Symbol & self) { std::stringstream ss; ss << self.chr(); return ss.str(); } void exportSymbol(){ class_ >("Symbol") .def(init<>()) .def(init()) .def("__init__", make_constructor(makeSymbol)) .def(init()) .def("print", &Symbol::print, print_overloads(args("s"))) .def("equals", &Symbol::equals, equals_overloads(args("q","tol"))) .def("key", &Symbol::key) .def("index", &Symbol::index) .def(self < self) .def(self == self) .def(self == other()) .def(self != self) .def(self != other()) .def("__repr__", &selfToString) .def("__int__", &selfToKey) .def("chr", &chrFromSelf) ; }