OpenLexocad  27.1
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 <Base/Persistence.h>
27 #include <map>
28 #include <vector>
29 #include <string>
30 
31 namespace Base {
32 class Writer;
33 class XMLWriter;
34 }
35 
36 namespace Core
37 {
38 class Property;
39 class PropertyContainer;
40 class DynamicPropertyP;
41 
42 struct CStringHasher {
43  inline std::size_t operator()(const char *s) const {
44  if(!s) return 0;
45  return boost::hash_range(s,s+std::strlen(s));
46  }
47  inline bool operator()(const char *a, const char *b) const {
48  if(!a) return !b;
49  if(!b) return false;
50  return std::strcmp(a,b)==0;
51  }
52 };
53 
58 class LX_CORE_EXPORT DynamicProperty
59 {
60 public:
62  virtual ~DynamicProperty();
63 
66  void getPropertyList(std::vector<Property*> &List) const;
69  void getPropertyMap(std::map<std::string,Property*> &Map) const;
71  Property *getDynamicPropertyByName(const char* name) const;
89  Property* addDynamicProperty(PropertyContainer &pc, const char* type, const char* name=0, const char* group=0,
90  const char* doc=0, short attr=0, bool ro=false, bool hidden=false);
97  bool addProperty(Property *prop);
102  bool removeDynamicProperty(const char* name);
104  bool removeProperty(const Property *prop);
106  std::vector<std::string> getDynamicPropertyNames() const;
108  const char* getPropertyName(const Property* prop) const;
110 
113  short getPropertyType(const Property* prop) const;
116  short getPropertyType(const char *name) const;
118  const char* getPropertyGroup(const Property* prop) const;
120  const char* getPropertyGroup(const char *name) const;
122  const char* getPropertyDocumentation(const Property* prop) const;
124  const char* getPropertyDocumentation(const char *name) const;
126 
128  void clear();
129 
131  size_t size() const;
132 
133  void save(const Property *prop, Base::AbstractWriter& writer, Base::PersistenceVersion& version);
134 
135  Property *restore(PropertyContainer &pc,
136  const char *PropName, const char *TypeName, Base::AbstractXMLReader& reader, Base::PersistenceVersion& version);
137 
138 #ifndef SWIG
139  struct PropData {
141  std::string name;
142  const char *pName;
143  std::string group;
144  std::string doc;
145  short attr;
146  bool readonly;
147  bool hidden;
148 
149  PropData(Property *prop=0, std::string &&n=std::string(), const char *pn=0,
150  const char *g=0, const char *d=0, short a=0, bool ro=false, bool h=false)
151  :property(prop),name(std::move(n)),pName(pn)
152  ,group(g?g:""),doc(d?d:""),attr(a),readonly(ro),hidden(h)
153  {}
154 
155  const char *getName() const {
156  return pName?pName:name.c_str();
157  }
158  };
159 
160  PropData getDynamicPropertyData(const Property* prop) const;
161 #endif
162 private:
163  std::string getUniquePropertyName(PropertyContainer &pc, const char *Name) const;
164 
165 private:
166  std::unique_ptr<DynamicPropertyP> mPimpl;
167 };
168 
169 } // namespace Core
170 
171 
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:149
Definition: PropertyLink.h:19
Property * property
Definition: DynamicProperty.h:140
std::string group
Definition: DynamicProperty.h:143
Definition: Persistence.h:14
short attr
Definition: DynamicProperty.h:145
Definition: PropertyContainer.h:107
Definition: GlobalId.h:61
Core::PropertyText name
Definition: CoreDocument.h:167
std::size_t operator()(const char *s) const
Definition: DynamicProperty.h:43
LX_CORE_EXPORT Version & version
Definition: DynamicProperty.h:42
Definition: DynamicProperty.h:139
Definition: DynamicProperty.h:58
bool hidden
Definition: DynamicProperty.h:147
Definition: AbstractXMLReader.h:7
bool readonly
Definition: DynamicProperty.h:146
Definition: Base.h:12
std::string doc
Definition: DynamicProperty.h:144
std::string name
Definition: DynamicProperty.h:141
Definition: Writer.h:16
bool operator()(const char *a, const char *b) const
Definition: DynamicProperty.h:47
Definition: Property.h:77
const char * pName
Definition: DynamicProperty.h:142
Definition: AbstractXMLReader.h:5
basic_group< entity, Types... > group
Alias declaration for the most common use case.
Definition: entt.hpp:3822
const char * getName() const
Definition: DynamicProperty.h:155