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