OpenLexocad  28.0
DynamicProperty.h
Go to the documentation of this file.
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 #pragma once
25 
26 #include <map>
27 #include <vector>
28 #include <string>
29 #include <memory>
30 namespace Base { class AbstractWriter; }
31 namespace Base { class AbstractXMLReader; }
32 namespace Base { class PersistenceVersion; }
33 
34 namespace Core
35 {
36 class Property;
37 class PropertyContainer;
38 class DynamicPropertyP;
39 
40 struct LX_CORE_EXPORT CStringHasher
41 {
42  std::size_t operator()(const char* s) const;
43  bool operator()(const char* a, const char* b) const;
44 };
45 
50 class LX_CORE_EXPORT DynamicProperty
51 {
52 public:
54  virtual ~DynamicProperty();
55 
58  void getPropertyList(std::vector<Property*> &List) const;
61  void getPropertyMap(std::map<std::string,Property*> &Map) const;
63  Property *getDynamicPropertyByName(const char* name) const;
81  Property* addDynamicProperty(PropertyContainer &pc, const char* type, const char* name=0, const char* group=0,
82  const char* doc=0, short attr=0, bool ro=false, bool hidden=false);
89  bool addProperty(Property *prop);
94  bool removeDynamicProperty(const char* name);
96  bool removeProperty(const Property *prop);
98  std::vector<std::string> getDynamicPropertyNames() const;
100  const char* getPropertyName(const Property* prop) const;
102 
105  short getPropertyType(const Property* prop) const;
108  short getPropertyType(const char *name) const;
110  const char* getPropertyGroup(const Property* prop) const;
112  const char* getPropertyGroup(const char *name) const;
114  const char* getPropertyDocumentation(const Property* prop) const;
116  const char* getPropertyDocumentation(const char *name) const;
118 
120  void clear();
121 
123  size_t size() const;
124 
126 
128  const char *PropName, const char *TypeName, Base::AbstractXMLReader& reader, Base::PersistenceVersion& version);
129 
130 #ifndef SWIG
131  struct PropData {
133  std::string name;
134  const char *pName;
135  std::string group;
136  std::string doc;
137  short attr;
138  bool readonly;
139  bool hidden;
140 
141  PropData(Property *prop=0, std::string &&n=std::string(), const char *pn=0,
142  const char *g=0, const char *d=0, short a=0, bool ro=false, bool h=false)
143  :property(prop),name(std::move(n)),pName(pn)
144  ,group(g?g:""),doc(d?d:""),attr(a),readonly(ro),hidden(h)
145  {}
146 
147  const char *getName() const {
148  return pName?pName:name.c_str();
149  }
150  };
151 
153 #endif
154 private:
155  std::string getUniquePropertyName(PropertyContainer &pc, const char *Name) const;
156 
157 private:
158  std::unique_ptr<DynamicPropertyP> mPimpl;
159 };
160 
161 } // namespace Core
162 
163 
Core::DynamicProperty::getPropertyGroup
const char * getPropertyGroup(const char *name) const
Get the group name of a named property.
Core::DynamicProperty::removeDynamicProperty
bool removeDynamicProperty(const char *name)
Core::DynamicProperty::getPropertyDocumentation
const char * getPropertyDocumentation(const Property *prop) const
Get the documentation of a property.
Core::CStringHasher::operator()
std::size_t operator()(const char *s) const
Core::CStringHasher
Definition: DynamicProperty.h:41
Core::DynamicProperty::PropData::attr
short attr
Definition: DynamicProperty.h:137
Core::DynamicProperty::clear
void clear()
Remove all properties.
Core::DynamicProperty::PropData::property
Property * property
Definition: DynamicProperty.h:132
Core::DynamicProperty::PropData::group
std::string group
Definition: DynamicProperty.h:135
Core::DynamicProperty::addDynamicProperty
Property * addDynamicProperty(PropertyContainer &pc, const char *type, const char *name=0, const char *group=0, const char *doc=0, short attr=0, bool ro=false, bool hidden=false)
Core::DynamicProperty::DynamicProperty
DynamicProperty()
entt::group
basic_group< entity, Types... > group
Alias declaration for the most common use case.
Definition: entt.hpp:3822
Core::DynamicProperty::getPropertyName
const char * getPropertyName(const Property *prop) const
Get the name of a property.
Core::PropertyContainer
Definition: PropertyContainer.h:93
Core::DynamicProperty::PropData::doc
std::string doc
Definition: DynamicProperty.h:136
Core::DynamicProperty::size
size_t size() const
Get property count.
Core::CStringHasher::operator()
bool operator()(const char *a, const char *b) const
Base::PersistenceVersion
Definition: Persistence.h:13
Core::DynamicProperty::PropData
Definition: DynamicProperty.h:131
Core::DynamicProperty::PropData::readonly
bool readonly
Definition: DynamicProperty.h:138
Core
Definition: Base.h:5
Core::DynamicProperty::PropData::hidden
bool hidden
Definition: DynamicProperty.h:139
Core::DynamicProperty::getPropertyMap
void getPropertyMap(std::map< std::string, Property * > &Map) const
Get all properties of the class (including parent)
Core::DynamicProperty::PropData::name
std::string name
Definition: DynamicProperty.h:133
Base::AbstractWriter
Definition: Writer.h:13
Core::DynamicProperty::getDynamicPropertyNames
std::vector< std::string > getDynamicPropertyNames() const
Get a list of all dynamic properties.
Core::DynamicProperty::restore
Property * restore(PropertyContainer &pc, const char *PropName, const char *TypeName, Base::AbstractXMLReader &reader, Base::PersistenceVersion &version)
Core::DynamicProperty::save
void save(const Property *prop, Base::AbstractWriter &writer, Base::PersistenceVersion &version)
Base::AbstractXMLReader
Definition: AbstractXMLReader.h:7
Core::DynamicProperty::getPropertyDocumentation
const char * getPropertyDocumentation(const char *name) const
Get the documentation of a named property.
Core::DynamicProperty::addProperty
bool addProperty(Property *prop)
Core::DynamicProperty::getPropertyGroup
const char * getPropertyGroup(const Property *prop) const
Get the group name of a property.
Core::DynamicProperty::getPropertyType
short getPropertyType(const char *name) const
Get the attributes of a named property.
Core::DynamicProperty::PropData::pName
const char * pName
Definition: DynamicProperty.h:134
Core::DynamicProperty::getDynamicPropertyData
PropData getDynamicPropertyData(const Property *prop) const
Core::version
LX_CORE_EXPORT Version & version
std
Definition: GlobalId.h:64
Core::Property
Definition: Property.h:72
Core::DynamicProperty::getDynamicPropertyByName
Property * getDynamicPropertyByName(const char *name) const
Find a dynamic property by its name.
Core::DynamicProperty::PropData::getName
const char * getName() const
Definition: DynamicProperty.h:147
Core::DynamicProperty::PropData::PropData
PropData(Property *prop=0, std::string &&n=std::string(), const char *pn=0, const char *g=0, const char *d=0, short a=0, bool ro=false, bool h=false)
Definition: DynamicProperty.h:141
Core::DynamicProperty
Definition: DynamicProperty.h:51
Core::DynamicProperty::~DynamicProperty
virtual ~DynamicProperty()
Base
Definition: AbstractXMLReader.h:5
Core::TypeName
Definition: PropertyLink.h:16
Core::DynamicProperty::removeProperty
bool removeProperty(const Property *prop)
Remove pre-existing property, which will not be deleted.