diff Sources/PythonObject.h @ 51:3dc37a5af1b1

new method PythonObject::ConvertToJson()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 Dec 2020 16:34:03 +0100
parents 7ed502b17b8f
children 23f3099bed47
line wrap: on
line diff
--- a/Sources/PythonObject.h	Tue Dec 08 19:02:30 2020 +0100
+++ b/Sources/PythonObject.h	Wed Dec 09 16:34:03 2020 +0100
@@ -21,6 +21,8 @@
 
 #include "PythonLock.h"
 
+#include <json/value.h>
+
 class PythonObject : public boost::noncopyable
 {
 private:
@@ -28,6 +30,12 @@
   PyObject    *object_;
   bool         borrowed_;
 
+  bool ToUtf8String(std::string& target,
+                    PyObject* value);
+
+  void ConvertToJson(Json::Value& target,
+                     PyObject* source);
+  
 public:
   PythonObject(PythonLock& lock,
                PyObject *object,
@@ -44,9 +52,17 @@
 
   PythonObject* GetAttribute(const std::string& name);
 
-  bool ToUtf8String(std::string& target);
+  bool ToUtf8String(std::string& target)
+  {
+    return ToUtf8String(target, GetPyObject());
+  }
 
   void Format(std::ostream& os);
 
   PyObject* Release();
+
+  void ConvertToJson(Json::Value& target)
+  {
+    ConvertToJson(target, GetPyObject());
+  }
 };