annotate Sources/PythonObject.h @ 170:b49eeb36cd0d

removed generation of code model, now part of orthanc-java
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Jun 2024 14:26:59 +0200
parents 6fada29b6759
children 3678a028f1f6
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
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * 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
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * 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
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #pragma once
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "PythonLock.h"
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 class PythonObject : public boost::noncopyable
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 private:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 PythonLock& lock_;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 PyObject *object_;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 bool borrowed_;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 public:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 PythonObject(PythonLock& lock,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 PyObject *object,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 bool borrowed = false);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 ~PythonObject();
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 bool IsValid() const
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 return object_ != NULL;
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 PyObject* GetPyObject() const;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 PythonObject* GetAttribute(const std::string& name);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 void Format(std::ostream& os);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 };