Go to the documentation of this file.
22 #ifndef REPEATED_FIELD_PROXY_H
23 #define REPEATED_FIELD_PROXY_H
25 #include "google/protobuf/message.h"
26 #include <boost/python.hpp>
31 namespace bpy = boost::python;
32 namespace gpb = google::protobuf;
40 Py_ssize_t
ExtractIndices(PyObject* indices, Py_ssize_t& from, Py_ssize_t& to, Py_ssize_t& step, Py_ssize_t length);
57 bpy::class_<RepeatedScalarFieldProxy> binder(
"RepeatedScalarField", bpy::no_init);
75 : _m(msg), _f(field) {
76 if(!field->is_repeated())
78 else if(field->cpp_type() == gpb::FieldDescriptor::CPPTYPE_MESSAGE)
86 {
return _m.GetReflection()->FieldSize(_m, _f); }
91 bpy::object GetItem(PyObject* indices);
96 void SetItem(PyObject* indices, PyObject* value);
113 for(
int i=0; i<bpy::len(value); ++i)
121 { _m.GetReflection()->ClearField(&_m,_f); }
127 { _m.GetReflection()->RemoveLast(&_m, _f); }
132 const gpb::FieldDescriptor * _f;
147 bpy::class_<RepeatedScalarFieldIterProxy> binder(
"RepeatedScalarFieldIter", bpy::no_init);
155 : _p(msg, field), _ind(0) { }
161 if(_ind == _p.Len()) {
162 PyErr_SetObject(PyExc_StopIteration, Py_None);
163 boost::python::throw_error_already_set();
166 return _p.GetItem(Py_BuildValue(
"i", _ind++));
175 #endif // REPEATED_FIELD_PROXY_H
RepeatedScalarFieldProxy(gpb::Message &msg, const gpb::FieldDescriptor *field)
Constructor.
Definition: repeated_field_proxy.h:74
void SetItem(PyObject *indices, PyObject *value)
Definition: repeated_field_proxy.cpp:69
static void create()
Creates the python wrapper.
Definition: repeated_field_proxy.h:56
void Pop()
Definition: repeated_field_proxy.h:126
static void create()
Creates the python wrapper.
Definition: repeated_field_proxy.h:146
Proxy class implementing a list-like python wrapper for a protobuf repeated scalar field (ie....
Definition: repeated_field_proxy.h:45
int Len()
Definition: repeated_field_proxy.h:85
void Append(const bpy::object &value)
Definition: repeated_field_proxy.h:106
Implement single field Get/Set operations using field descriptor and reflection interface.
Definition: proto_field_ops.cpp:25
bpy::object Next()
Implementation of next
Definition: repeated_field_proxy.h:160
static EXCEPTION logCreate(LOG_EXCEPTION_T &exception, const std::string &msg, NRPLogger::spdlog_out_fcn_t spdlogCall=NRPLogger::critical)
Definition: nrp_exceptions.h:73
void Clear()
Definition: repeated_field_proxy.h:120
void Extend(const bpy::object &value)
Definition: repeated_field_proxy.h:112
void AddRepeatedScalarField(gpb::Message &m, const gpb::FieldDescriptor *field, const bpy::object &value)
Append repeated scalar field.
Definition: proto_field_ops.cpp:211
RepeatedScalarFieldIterProxy(gpb::Message &msg, const gpb::FieldDescriptor *field)
Constructor.
Definition: repeated_field_proxy.h:154
bpy::object Iter()
Definition: repeated_field_proxy.cpp:122
bpy::object GetItem(PyObject *indices)
Definition: repeated_field_proxy.cpp:44
Class implementing a python iterator for a RepeatedScalarFieldProxy.
Definition: repeated_field_proxy.h:139
Py_ssize_t ExtractIndices(PyObject *indices, Py_ssize_t &from, Py_ssize_t &to, Py_ssize_t &step, Py_ssize_t length)
Function which processes an index or slice object and sets from, to and step appropriately.
Definition: repeated_field_proxy.cpp:24