OpenLexocad  27.0
PropertyBackLink.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Core/Property.h>
4 #include <Core/Variant.h>
5 #include <Core/core_defines2.h>
6 
7 #include <list>
8 
9 namespace Core
10 {
11 template <typename T>
13 {
14  static const char* Get() { return typeid(T).name(); }
15 };
16 
17 //----------------------------------------------------------------------------
18 // PropertyBackLinkBase
19 //----------------------------------------------------------------------------
20 
22 {
24 
25 public:
27  virtual ~PropertyBackLinkBase(void);
28 
29  void setValue(Core::DocObject* o);
30  bool setValueFromVariant(const Core::Variant& value) override;
31  void copyValue(Core::Property* p) override;
32 
33  Core::DocObject* getValue() const;
34  Core::Variant getVariant(void) const;
35 
36  void save(Base::AbstractWriter& writer, Base::PersistanceVersion& save_version) override;
37  inline void restore(Base::AbstractXMLReader& reader, Base::PersistanceVersion& version) override;
38  bool isEqual(const Property*) const override;
39  std::shared_ptr<Core::DbgInfo> getDbgInfo() const override;
40  virtual const Core::PropertyKind getPropertyKind(void) const override;
41 
42 protected:
44 };
45 
46 //----------------------------------------------------------------------------
47 // PropertyBackLink<T>
48 //----------------------------------------------------------------------------
49 
50 template <typename T>
52 {
53  TYPESYSTEM_PROPERTY_HEADER(PropertyBackLink, Core::PropertyBackLinkBase);
55 
56 public:
57  void setValue(T o) { inherited::setValue(o); }
58  T getValue() const { return static_cast<T>(inherited::getValue()); }
59 };
60 
61 #ifndef SWIG
62 template <typename T>
63 Base::Type PropertyBackLink<T>::classTypeId = Base::Type().createType(Base::Type::badType(), TypeNameBack<PropertyBackLink<T>>::Get());
64 #endif
65 
66 //----------------------------------------------------------------------------
67 // PropertyBackLinkSetBase
68 //----------------------------------------------------------------------------
69 
71 {
73 
74 public:
77 
78  void setValue(const boost::unordered_set<Core::DocObject*>& linkset);
79  bool setValueFromVariant(const Core::Variant& value);
80  void copyValue(Core::Property* p);
81  const boost::unordered_set<Core::DocObject*>& getValue() const;
82 
83  bool addLink(Core::DocObject* o);
84  void addLinks(const boost::unordered_set<Core::DocObject*>& linkset);
85  bool removeLink(Core::DocObject* o);
86  void setEmpty();
87  bool hasLink(Core::DocObject* o) const;
88  bool isEmpty() const;
89  size_t getSize() const;
90 
91  Core::Variant getVariant(void) const;
92 
93  void save(Base::AbstractWriter& writer, Base::PersistanceVersion& save_version) override;
94  inline void restore(Base::AbstractXMLReader& reader, Base::PersistanceVersion& version) override;
95  bool isEqual(const Property*) const override;
96  std::shared_ptr<Core::DbgInfo> getDbgInfo() const override;
97  virtual const Core::PropertyKind getPropertyKind(void) const override;
98 
99 protected:
100  boost::unordered_set<Core::DocObject*> _linkSet;
101 };
102 
103 //----------------------------------------------------------------------------
104 // PropertyBackLinkSet<T>
105 //----------------------------------------------------------------------------
106 
107 template <typename T>
109 {
110  TYPESYSTEM_PROPERTY_HEADER(PropertyBackLinkSet, Core::PropertyBackLinkSetBase);
112 
113 public:
114  void setValue(const boost::unordered_set<T>& linkset) { inherited::setValue(*(const boost::unordered_set<Core::DocObject*>*)(&linkset)); };
115  const boost::unordered_set<T>& getValue() const { return *(const boost::unordered_set<T>*)(&_linkSet); }
116 
117  bool addLink(T link) { return inherited::addLink(link); }
118  bool removeLink(T link) { return inherited::removeLink(link); };
119 
120  void addLinks(const boost::unordered_set<T>& linkset) { inherited::addLinks(*(const boost::unordered_set<Core::DocObject*>*)(&linkset)); }
121 };
122 
123 #ifndef SWIG
124 template <typename T>
125 Base::Type PropertyBackLinkSet<T>::classTypeId = Base::Type().createType(Base::Type::badType(), TypeNameBack<PropertyBackLinkSet<T>>::Get());
126 #endif
127 
128 DECLARE_PROPERTY_FACTORY(PropertyBackLinkBase_Factory, Core::PropertyBackLinkBase);
129 DECLARE_PROPERTY_FACTORY(PropertyBackLinkSetBase_Factory, Core::PropertyBackLinkSetBase);
130 
131 } // namespace Core
#define CORE_EXPORT
Definition: core_defines2.h:10
Core::PropertyText name
Definition: CoreDocument.h:143
Definition: Persistance.h:20
LX_CORE_EXPORT Version & version
Definition: Type.h:56
Definition: Variant.h:90
Definition: AbstractXMLReader.h:10
PropertyKind
Definition: Property.h:54
static const Type createType(const Type parent, const char *name, instantiationMethod method=0)
Definition: Base.h:19
Definition: PropertyBackLink.h:12
static const char * Get()
Definition: PropertyBackLink.h:14
Definition: Writer.h:27
static const Type badType(void)
Definition: Type.h:103
Definition: Property.h:81
TYPESYSTEM_HEADER()
DECLARE_PROPERTY_FACTORY(PropertyAxis1_Factory, Core::PropertyAxis1)
Definition: DocObject.h:28