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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU Affero General Public License
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * as published by the Free Software Foundation, either version 3 of
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * the License, or (at your option) any later version.
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * Affero General Public License for more details.
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 *
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * You should have received a copy of the GNU Affero General Public License
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 **/
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 #pragma once
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "PythonLock.h"
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 class PythonObject : public boost::noncopyable
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 private:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 PythonLock& lock_;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 PyObject *object_;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 bool borrowed_;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 public:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 PythonObject(PythonLock& lock,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 PyObject *object,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 bool borrowed = false);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 ~PythonObject();
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 bool IsValid() const
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 return object_ != NULL;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 PyObject* GetPyObject() const;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 PythonObject* GetAttribute(const std::string& name);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 void Format(std::ostream& os);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 };