2

I am using boost python for interoperability between C++ and the Python . i have enum and structure in c++ and have function in c++ that can take these structure as a parameter. and i am able to access this function in python by using boost python but i don't know how to send structure as parameter in python. Set is function in c++ that can get structure as parameter.so in python how can i send this structure as a parameter . i am able to get this function in python but not able to send send structure as parameter. thanks for the help.

structure in c++ is as follow:

enum days
{
  friday,
  saturday
};
struct example
 {
    days m_day;
    std: string m_value;
 };

Class Base
 {
   public:
   void Set(example& Result) = 0;
  }
class Derived
{
  public:
  void Set(example& Result) 
  {
    Result.m_day = friday;
   }
5
  • no i want to send structure as pyrameter from python to c++. Commented Nov 12, 2013 at 10:17
  • Maybe this could help you ? send-receive-cstruct-using-python Commented Nov 12, 2013 at 10:22
  • how can i send empty structure from python that it can assess the Structurevalue of c++?not able to send Structure from python Commented Nov 12, 2013 at 10:31
  • Expose the enum and struct via boost::python::enum and boost::python::class_. Boost.Python will handle converting to-and-from the struct and the associated Python types. Commented Nov 12, 2013 at 16:27
  • Problem is that how can i send empty structure from python that it can access the structure in c++. Commented Nov 13, 2013 at 12:43

1 Answer 1

2

You have to expose structure example like this and then create a variable of this structure in python and send this variable as argument.

Class_<example> (“example”)
.def_readwrite(“m_day” , & example:: day)
.def_readwrite(“m_value” , & example:: m_value)
;

Hope this will help..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.