[C++-sig] boost.python fails to recognize type
Mateusz Berezecki
mateuszb at gmail.com
Tue Jul 29 00:21:46 CEST 2008
Hello,
That's the complete example code
#include <Common/Compat.h>
#include <Hypertable/Lib/Client.h>
#include <boost/foreach.hpp>
#include <boost/algorithm/string.hpp>
#include <string>
#include <vector>
#include <map>
#include <boost/python.hpp>
#include <boost/python/class.hpp>
#include <boost/python/module.hpp>
#include <boost/python/borrowed.hpp>
#include <boost/python/def.hpp>
using namespace boost::python;
using Hypertable::ScanSpec;
class TableScanner {
private:
Hypertable::TableScannerPtr m_scanner;
public:
TableScanner() {}
TableScanner(Hypertable::TableScannerPtr ptr) : m_scanner(ptr)
{
}
bool next(Hypertable::Cell& cell)
{
return m_scanner->next(cell);
}
};
class Table {
private:
Hypertable::TablePtr m_table_ptr;
public:
Table()
{
}
Table(Hypertable::TablePtr ptr) : m_table_ptr(ptr)
{
}
TableScanner create_scanner(object const &pyspec)
{
extract<ScanSpec&> ex(pyspec);
ScanSpec& spec = ex();
return TableScanner(m_table_ptr->create_scanner(spec, 10));
}
};
class Client {
private:
Hypertable::ClientPtr m_client;
public:
Client(const std::string& argv0)
{
m_client = new Hypertable::Client(argv0.c_str());
}
Client(const std::string& argv0, const std::string& config)
{
m_client = new Hypertable::Client(argv0.c_str(), config);
}
Table open_table(const std::string& name)
{
Hypertable::TablePtr t = m_client->open_table(name);
return Table(t);
}
};
BOOST_PYTHON_MODULE(ht)
{
class_<Client>("Client", init<const std::string& >())
.def(init<const std::string&, const std::string& >())
.def("open_table", &Client::open_table)
;
class_<Table>("Table", "Table representation")
.def("create_scanner", &Table::create_scanner)
;
class_<TableScanner>("TableScanner")
.def("next", &TableScanner::next)
;
class_<ScanSpec>("ScanSpec", "scan spec docstring")
.def_readwrite("row_limit", &ScanSpec::row_limit)
.def_readwrite("max_versions", &ScanSpec::max_versions)
.def_readwrite("columns", &ScanSpec::columns)
.def_readwrite("start_row", &ScanSpec::start_row)
.def_readwrite("start_row_inclusive", &ScanSpec::start_row_inclusive)
.def_readwrite("end_row", &ScanSpec::end_row)
.def_readwrite("end_row_inclusive", &ScanSpec::end_row_inclusive)
;
class_<Hypertable::Cell>("Cell")
.def_readonly("row_key", &Hypertable::Cell::row_key)
.def_readonly("column_family", &Hypertable::Cell::column_family)
.def_readonly("column_qualifier", &Hypertable::Cell::column_qualifier)
.def_readonly("timestamp", &Hypertable::Cell::timestamp)
.def_readonly("value", &Hypertable::Cell::value)
.def_readonly("value_len", &Hypertable::Cell::value_len)
.def_readonly("flag", &Hypertable::Cell::flag)
;
}
and the python code invoking it is:
import ht
client = ht.Client("ht", "/opt/hypertable/0.9.0.7/conf/hypertable.cfg")
table = client.open_table("METADATA")
scan_spec = ht.ScanSpec
scan_spec.start_row = 0
scan_spec.start_row = "\x00"
scan_spec.end_row = "\xff\xff"
scan_spec.start_row_inclusive = True
scan_spec.end_row_inclusive = True
scan_spec.max_versions = 1
print scan_spec.__doc__
print table.__doc__
print scan_spec
scanner = table.create_scanner(scan_spec)
This yields the errors mentioned in the previous post.
I am stuck on this one really badly. I just started playing with Boost.Python
2 days ago.
Mateusz
More information about the Cplusplus-sig
mailing list