Debian Codegraph @

src/App/PropertyPythonObject.h

raw
1 /***************************************************************************
2 * Copyright (c) 2009 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef APP_PROPERTYPYTHONOBJECT_H
25 #define APP_PROPERTYPYTHONOBJECT_H
26
27 #include <string>
28 #include <CXX/Objects.hxx>
29
30 #include "Property.h"
31
32
33 namespace Base
34 {
35 class Writer;
36 class XMLReader;
37 } // namespace Base
38
39 namespace App
40 {
41
42 /**
43 * PropertyPythonObject is used to manage Py::Object instances as properties.
44 * @author Werner Mayer
45 */
46 class AppExport PropertyPythonObject: public Property
47 {
48 TYPESYSTEM_HEADER_WITH_OVERRIDE();
49
50 public:
51 PropertyPythonObject();
52 ~PropertyPythonObject() override;
53
54 void setValue(const Py::Object& py);
55 Py::Object getValue() const;
56
57 PyObject* getPyObject() override;
58 void setPyObject(PyObject* obj) override;
59
60 /** Use Python's pickle module to save the object */
61 void Save(Base::Writer& writer) const override;
62 /** Use Python's pickle module to restore the object */
63 void Restore(Base::XMLReader& reader) override;
64 void SaveDocFile(Base::Writer& writer) const override;
65 void RestoreDocFile(Base::Reader& reader) override;
66
67 unsigned int getMemSize() const override;
68 Property* Copy() const override;
69 void Paste(const Property& from) override;
70
71 std::string toString() const;
72 void fromString(const std::string&);
73
74 private:
75 void saveObject(Base::Writer& writer) const;
76 void restoreObject(Base::XMLReader& reader);
77 std::string encodeValue(const std::string& str) const;
78 std::string decodeValue(const std::string& str) const;
79 Py::Object object;
80 };
81
82
83 } // namespace App
84
85 #endif // APP_PROPERTYPYTHONOBJECT_H