xc
EntityWithProperties.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. PĂ©rez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //EntityWithProperties.h
22 
23 #ifndef ENTPROP_H
24 #define ENTPROP_H
25 
26 #include "EntityWithOwner.h"
27 #include <map>
28 
30 //
33  {
34  public:
35  typedef std::map<std::string, boost::python::object> PythonDict;
36  protected:
37  bool isEqual(const EntityWithProperties &) const;
38  private:
39  static inline const std::string py_prop_prefix= "py_prop";
40 
41  PythonDict python_dict;
42  public:
44 
45  void clearPyProps(void);
46  bool hasPyProp(const std::string &);
47  boost::python::object getPyProp(const std::string &str);
48  void setPyProp(std::string str, boost::python::object val);
49  void copyPropsFrom(const EntityWithProperties &);
50  boost::python::list getPropNames(void) const;
51 
52  const PythonDict &getPropertiesDict(void) const;
53  boost::python::dict getPyDict(void) const;
54  void setPyDict(const boost::python::dict &);
55  };
56 
57 #endif
void setPyProp(std::string str, boost::python::object val)
Sets/appends a value tho the Python object&#39;s dictionary.
Definition: EntityWithProperties.cc:67
boost::python::dict getPyDict(void) const
Return a Python dictionary containing the object members values.
Definition: EntityWithProperties.cc:126
boost::python::object getPyProp(const std::string &str)
Return the Python object with the name being passed as parameter.
Definition: EntityWithProperties.cc:41
Object that can return properties as Python objects.
Definition: EntityWithProperties.h:32
Entity with a pointer to its owner.
Definition: EntityWithOwner.h:34
bool isEqual(const EntityWithProperties &) const
Return true if both objects are equal.
Definition: EntityWithProperties.cc:94
EntityWithProperties(EntityWithProperties *owr=nullptr)
Default constructor.
Definition: EntityWithProperties.cc:28
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: EntityWithProperties.cc:153
void copyPropsFrom(const EntityWithProperties &)
Copy the properties from the argument.
Definition: EntityWithProperties.cc:82
bool hasPyProp(const std::string &)
Returns true if property exists.
Definition: EntityWithProperties.cc:37
const PythonDict & getPropertiesDict(void) const
Return a std::map container with the properties of the object.
Definition: EntityWithProperties.cc:90
boost::python::list getPropNames(void) const
Return the names of the object properties weightings.
Definition: EntityWithProperties.cc:73
void clearPyProps(void)
Clear python properties map.
Definition: EntityWithProperties.cc:33