OpenLexocad  27.1
GeometryDefaultExtension.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (c) 2019 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> *
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 PART_GEOMETRYDEFAULTEXTENSION_H
25 #define PART_GEOMETRYDEFAULTEXTENSION_H
26 
27 #include <string>
28 #include "Geom/GeometryExtension.h"
29 
30 namespace Geom {
31 
32  template <typename T>
34  {
35  TYPESYSTEM_HEADER_WITH_OVERRIDE();
36  public:
37  inline GeometryDefaultExtension();
38  GeometryDefaultExtension(const T& val, std::string name = std::string());
39  virtual ~GeometryDefaultExtension() override = default;
40 
41  inline void setValue(const T& val) {value = val;};
42  inline const T &getValue() const {return value;};
43 
44  // Persistence implementer ---------------------
45  virtual void save(Base::AbstractWriter& /*writer*/, Base::PersistenceVersion& /*save_version*/) override;
46  virtual void restore(Base::AbstractXMLReader& /*reader*/, Base::PersistenceVersion& /*version*/) override;
47 
48  virtual std::unique_ptr<Part::GeometryExtension> copy(void) const override;
49 
50  private:
52 
53  private:
54  T value;
55  };
56 
57  // Description:
58  //
59  // This template allows to define a geometry extension for a given type (uniform interface for one value of type T).
60  //
61  // Warnings:
62  // - The default constructor relies on the default constructor of T for initialisation. Built-in types
63  // so constructed will be uninitialised. Use the specific constructor from a T to initialise it. Note
64  // that the default constructor is required by the type system (see TYPESYSTEM_SOURCE_TEMPLATE_T).
65  //
66  // Default assumptions:
67  // - T can be constructed from T
68  // - T can be assigned to T
69  // - T is convertible to a std::string
70  // - T is serialisable as a string
71  //
72  // template specialisation:
73  //
74  // If the assumptions do not meet for your type, template specialisation allows you to provide specific code,
75  // look for examples (int/string) in GeometryDefaultExtensions.cpp
76  //
77  // Instructions:
78  //
79  // 1. Read the assumptions above and provide template initialisation if needed.
80  // 2. Add an alias to your type under these comments
81  // 3. Add a TYPESYSTEM_SOURCE_TEMPLATE_T in the cpp file to generate class type information
82  // 4. Provide a specialisation of getPyObject to generate a py object of the corresponding type (cpp file)
83  // 5. Provide specialisations if your type does not meet the assumptions above (e.g. for serialisation) (cpp file)
84  // 6. Register your type and corresponding python type in AppPart.cpp
85 
86  template <typename T>
88 
89  // Specialised constructors go here so that specialisation is before the template instantiation
90  // Specialised default constructors are inline, because a full specialisation otherwise shall go in the cpp file, but there it would be after the template instantiation.
91  template <>
93 
94  template <>
96 
97  // Prefer alias to typedef item 9
102 }
103 
104 #endif // PART_GEOMETRYDEFAULTEXTENSION_H
Definition: Variant.h:60
Definition: GeometryExtension.h:65
Definition: Persistence.h:14
Core::PropertyText name
Definition: CoreDocument.h:167
Definition: GeometryDefaultExtension.h:33
Definition: AbstractXMLReader.h:7
void setValue(const T &val)
Definition: GeometryDefaultExtension.h:41
Definition: Writer.h:16
GeometryDefaultExtension()
Definition: GeometryDefaultExtension.h:87
const T & getValue() const
Definition: GeometryDefaultExtension.h:42