Chemical Data Processing Library Python API - Version 1.2.0
Public Member Functions | Properties | List of all members
CDPL.Base.PropertyContainer Class Reference

A class providing methods for the storage and lookup of object properties. More...

+ Inheritance diagram for CDPL.Base.PropertyContainer:

Public Member Functions

None __init__ ()
 Constructs an empty PropertyContainer instance.
 
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
int getNumProperties ()
 Returns the number of property entries. More...
 
Any getPropertyOrDefault (LookupKey key, Any def_value)
 
list getPropertyKeys ()
 
list getPropertyValues ()
 
list getProperties ()
 Returns a reference to itself. More...
 
None setProperty (LookupKey key, Any value)
 
bool removeProperty (LookupKey key)
 Clears the value of the property specified by key. More...
 
Any getProperty (LookupKey key, bool throw_=False)
 Returns the value of the property specified by key. More...
 
bool isPropertySet (LookupKey key)
 Tells whether or not a value has been assigned to the property specified by key. More...
 
None clearProperties ()
 Clears all property values.
 
None addProperties (PropertyContainer cntnr)
 Adds the property value entries in the PropertyContainer instance cntnr. More...
 
None copyProperties (PropertyContainer cntnr)
 Replaces the current set of properties by a copy of the entries in cntnr. More...
 
None swap (PropertyContainer cntnr)
 Exchanges the properties of this container with the properties of the container cntnr. More...
 
Any __getitem__ (LookupKey key)
 
bool __contains__ (LookupKey key)
 Returns the result of the membership test operation key in self. More...
 
None __setitem__ (LookupKey key, Any value)
 
bool __delitem__ (LookupKey key)
 
int __len__ ()
 

Properties

 objectID = property(getObjectID)
 
 propertyKeys = property(getPropertyKeys)
 
 propertyValues = property(getPropertyValues)
 
 properties = property(getProperties)
 
 numProperties = property(getNumProperties)
 

Detailed Description

A class providing methods for the storage and lookup of object properties.

The purpose of PropertyContainer is to provide a common facility for the storage and lookup of dynamic object properties to subclasses and their clients.

PropertyContainer stores the properties in a map that associates unique property keys of type Base.LookupKey with corresponding property values of type Base.Any. Iterators pointing to the beginning and end of the property key/value pairs (see PropertyContainer.PropertyEntry) can be retrieved by the methods getPropertiesBegin() and getPropertiesEnd(), respectively. The number of currently stored property value entries is accessible via the method getNumProperties().

For the explicit assignment of property values the method setProperty() is provided which expects the key of the property as its first and the value to assign as the second argument. Whether the value of a particular property has been set can be tested by the method isPropertySet(). For the erasure of property values the methods removeProperty() and clearProperties() are provided. The first method clears the value of a single property while the latter method removes all assigned property values.

To access the value of a property, two types of getProperty() methods are available that both expect the key of the property as the first argument. The templated versions return the stored property value (or the specified default if not available) as a reference to an object of the specified template argument type. The non-template method returns the requested property value indirectly as a reference to the Base.Any instance storing the actual value. If the requested property value does not exist, an additional argument decides whether to throw an exception or to return an empty Base.Any instance.

Member Function Documentation

◆ getObjectID()

int CDPL.Base.PropertyContainer.getObjectID ( )

Returns the numeric identifier (ID) of the wrapped C++ class instance.

Different Python PropertyContainer instances may reference the same underlying C++ class instance. The commonly used Python expression a is not b thus cannot tell reliably whether the two PropertyContainer instances a and b reference different C++ objects. The numeric identifier returned by this method allows to correctly implement such an identity test via the simple expression a.getObjectID() != b.getObjectID().

Returns
The numeric ID of the internally referenced C++ class instance.

Reimplemented in CDPL.ConfGen.CanonicalFragment.

◆ getNumProperties()

int CDPL.Base.PropertyContainer.getNumProperties ( )

Returns the number of property entries.

Returns
The number of property entries.

◆ getPropertyOrDefault()

Any CDPL.Base.PropertyContainer.getPropertyOrDefault ( LookupKey  key,
Any  def_value 
)
Parameters
key
def_value
Returns

◆ getPropertyKeys()

list CDPL.Base.PropertyContainer.getPropertyKeys ( )
Returns

◆ getPropertyValues()

list CDPL.Base.PropertyContainer.getPropertyValues ( )
Returns

◆ getProperties()

list CDPL.Base.PropertyContainer.getProperties ( )

Returns a reference to itself.

Returns
self

◆ setProperty()

None CDPL.Base.PropertyContainer.setProperty ( LookupKey  key,
Any  value 
)
Parameters
key
value

◆ removeProperty()

bool CDPL.Base.PropertyContainer.removeProperty ( LookupKey  key)

Clears the value of the property specified by key.

Parameters
keyThe key of the property value to erase.
Returns
True if an entry for key could be found and was erased, and False otherwise.

◆ getProperty()

Any CDPL.Base.PropertyContainer.getProperty ( LookupKey  key,
bool   throw_ = False 
)

Returns the value of the property specified by key.

If an entry for the specified property exists, the stored value will be returned. Otherwise an empty Base.Any object gets returned if _throw is False, and a Base.ItemNotFound exception will be thrown if _throw is True.

Parameters
keyThe key of the property value to return.
throw_Specifies whether to throw a Base.ItemNotFound exception or to return an empty Base.Any object if the requested property value does not exist.
Returns
The stored property value or and empty Base.Any object.
Exceptions
Base.ItemNotFoundif an entry for the requested property value does not exist and throw_ is True.

◆ isPropertySet()

bool CDPL.Base.PropertyContainer.isPropertySet ( LookupKey  key)

Tells whether or not a value has been assigned to the property specified by key.

Parameters
keyThe key of the property.
Returns
True if a value has been assigned to the specified property, and False otherwise.

◆ addProperties()

None CDPL.Base.PropertyContainer.addProperties ( PropertyContainer  cntnr)

Adds the property value entries in the PropertyContainer instance cntnr.

Any property values which have no corresponding assigned value in cntnr are left unchanged. Otherwise the value of the local property gets overwritten by the value stored in cntnr.

Parameters
cntnrThe PropertyContainer instance containing the property value entries to add.

◆ copyProperties()

None CDPL.Base.PropertyContainer.copyProperties ( PropertyContainer  cntnr)

Replaces the current set of properties by a copy of the entries in cntnr.

Parameters
cntnrThe PropertyContainer instance containing the property value entries to add.

◆ swap()

None CDPL.Base.PropertyContainer.swap ( PropertyContainer  cntnr)

Exchanges the properties of this container with the properties of the container cntnr.

Parameters
cntnrThe container to exchange the properties with.

◆ __getitem__()

Any CDPL.Base.PropertyContainer.__getitem__ ( LookupKey  key)
Parameters
key
Returns

◆ __contains__()

bool CDPL.Base.PropertyContainer.__contains__ ( LookupKey  key)

Returns the result of the membership test operation key in self.

Parameters
keyThe value to test for membership.
Returns
The result of the membership test operation.

◆ __setitem__()

None CDPL.Base.PropertyContainer.__setitem__ ( LookupKey  key,
Any  value 
)
Parameters
key
value

◆ __delitem__()

bool CDPL.Base.PropertyContainer.__delitem__ ( LookupKey  key)
Parameters
key
Returns

◆ __len__()

int CDPL.Base.PropertyContainer.__len__ ( )