Mercurial > hg > orthanc-python
comparison 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 |
comparison
equal
deleted
inserted
replaced
50:70abe3ebbbfc | 51:3dc37a5af1b1 |
---|---|
19 | 19 |
20 #pragma once | 20 #pragma once |
21 | 21 |
22 #include "PythonLock.h" | 22 #include "PythonLock.h" |
23 | 23 |
24 #include <json/value.h> | |
25 | |
24 class PythonObject : public boost::noncopyable | 26 class PythonObject : public boost::noncopyable |
25 { | 27 { |
26 private: | 28 private: |
27 PythonLock& lock_; | 29 PythonLock& lock_; |
28 PyObject *object_; | 30 PyObject *object_; |
29 bool borrowed_; | 31 bool borrowed_; |
30 | 32 |
33 bool ToUtf8String(std::string& target, | |
34 PyObject* value); | |
35 | |
36 void ConvertToJson(Json::Value& target, | |
37 PyObject* source); | |
38 | |
31 public: | 39 public: |
32 PythonObject(PythonLock& lock, | 40 PythonObject(PythonLock& lock, |
33 PyObject *object, | 41 PyObject *object, |
34 bool borrowed = false); | 42 bool borrowed = false); |
35 | 43 |
42 | 50 |
43 PyObject* GetPyObject() const; | 51 PyObject* GetPyObject() const; |
44 | 52 |
45 PythonObject* GetAttribute(const std::string& name); | 53 PythonObject* GetAttribute(const std::string& name); |
46 | 54 |
47 bool ToUtf8String(std::string& target); | 55 bool ToUtf8String(std::string& target) |
56 { | |
57 return ToUtf8String(target, GetPyObject()); | |
58 } | |
48 | 59 |
49 void Format(std::ostream& os); | 60 void Format(std::ostream& os); |
50 | 61 |
51 PyObject* Release(); | 62 PyObject* Release(); |
63 | |
64 void ConvertToJson(Json::Value& target) | |
65 { | |
66 ConvertToJson(target, GetPyObject()); | |
67 } | |
52 }; | 68 }; |