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