Mercurial > hg > orthanc-python
annotate Sources/PythonObject.h @ 114:65ec5597ec70
upgrade to year 2023
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 28 Mar 2023 17:35:14 +0200 |
parents | eb6ac5a801d1 |
children | 71d305c29cfa |
rev | line source |
---|---|
0 | 1 /** |
2 * Python plugin for Orthanc | |
114
65ec5597ec70
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
3 * Copyright (C) 2020-2023 Osimis S.A., Belgium |
65ec5597ec70
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
4 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 5 * |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU Affero General Public License | |
8 * as published by the Free Software Foundation, either version 3 of | |
9 * the License, or (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Affero General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Affero General Public License | |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 **/ | |
19 | |
20 | |
21 #pragma once | |
22 | |
23 #include "PythonLock.h" | |
24 | |
51
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
25 #include <json/value.h> |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
26 |
0 | 27 class PythonObject : public boost::noncopyable |
28 { | |
29 private: | |
30 PythonLock& lock_; | |
31 PyObject *object_; | |
32 bool borrowed_; | |
33 | |
51
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
34 bool ToUtf8String(std::string& target, |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
35 PyObject* value); |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
36 |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
37 void ConvertToJson(Json::Value& target, |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
38 PyObject* source); |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
39 |
0 | 40 public: |
41 PythonObject(PythonLock& lock, | |
42 PyObject *object, | |
43 bool borrowed = false); | |
44 | |
45 ~PythonObject(); | |
46 | |
47 bool IsValid() const | |
48 { | |
49 return object_ != NULL; | |
50 } | |
51 | |
52 PyObject* GetPyObject() const; | |
53 | |
54 PythonObject* GetAttribute(const std::string& name); | |
55 | |
51
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
56 bool ToUtf8String(std::string& target) |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
57 { |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
58 return ToUtf8String(target, GetPyObject()); |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
59 } |
0 | 60 |
61 void Format(std::ostream& os); | |
62 | |
63 PyObject* Release(); | |
51
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
64 |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
65 void ConvertToJson(Json::Value& target) |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
66 { |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
67 ConvertToJson(target, GetPyObject()); |
3dc37a5af1b1
new method PythonObject::ConvertToJson()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
68 } |
0 | 69 }; |