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

Base 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_val)
 Returns the value of the property specified by key , or the default value def_val if an entry does not exist. More...
 
list getPropertyKeys ()
 Returns a list containing the keys of the current property entries. More...
 
list getPropertyValues ()
 Returns a list containing the values of the current property entries. More...
 
list getProperties ()
 Returns a reference to itself. More...
 
None setProperty (LookupKey key, Any val)
 Sets the value of the property specified by key to val. More...
 
bool removeProperty (LookupKey key)
 Removes the entry for 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 ()
 Erases all container entries.
 
None addProperties (PropertyContainer cntnr)
 Adds the property entries of the PropertyContainer instance cntnr. More...
 
None copyProperties (PropertyContainer cntnr)
 Replaces the current property entries by a copy of the entries in cntnr. More...
 
None swap (PropertyContainer cntnr)
 Exchanges the property entries of this container with the ones of cntnr. More...
 
Any __getitem__ (LookupKey key)
 Returns the value of the property specified by key. More...
 
bool __contains__ (LookupKey key)
 Tells whether or not a value has been assigned to the property specified by key. More...
 
None __setitem__ (LookupKey key, Any val)
 Sets the value of the property specified by key to val. More...
 
bool __delitem__ (LookupKey key)
 Removes the entry for the property specified by key. More...
 
int __len__ ()
 Returns the number of property entries. More...
 

Properties

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

Detailed Description

Base 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. The number of currently stored property 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 entries the methods removeProperty() and clearProperties() are provided. The first method removes the entry for a single property while the latter method removes all entries.

To access the value of a property the method getProperty() is available which expects the key of the property as the first argument. 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_val 
)

Returns the value of the property specified by key , or the default value def_val if an entry does not exist.

If a value has been assigned to the specified property, the stored value will be returned. Otherwise the default value specified by def_val gets returned.

Parameters
keyThe key of the property for which to return the stored (or specified default) value.
def_valThe default value that shall be returned if an entry for the specified property does not exist.
Returns
The stored property value or the default specified by def_val.

◆ getPropertyKeys()

list CDPL.Base.PropertyContainer.getPropertyKeys ( )

Returns a list containing the keys of the current property entries.

Returns
A list containing the requested property keys.

◆ getPropertyValues()

list CDPL.Base.PropertyContainer.getPropertyValues ( )

Returns a list containing the values of the current property entries.

Returns
A list containing the requested property values.

◆ getProperties()

list CDPL.Base.PropertyContainer.getProperties ( )

Returns a reference to itself.

Returns
self.

◆ setProperty()

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

Sets the value of the property specified by key to val.

If val is None, and a property entry for key exists, the entry gets erased (equivalent to removeProperty() with key as argument).

Parameters
keyThe key of the property value to assign or remove.
valThe value of the property.

◆ removeProperty()

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

Removes the entry for the property specified by key.

Parameters
keyThe key of the property entry to remove.
Returns
True if an entry for key could be found and was removed, 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 instance 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 instance if the requested property value does not exist.
Returns
The stored property value or and empty Base.Any instance.
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 entries of the PropertyContainer instance cntnr.

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

Parameters
cntnrThe PropertyContainer instance providing the property entries to add.

◆ copyProperties()

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

Replaces the current property entries by a copy of the entries in cntnr.

Parameters
cntnrThe PropertyContainer instance providing the property entries to copy.

◆ swap()

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

Exchanges the property entries of this container with the ones of cntnr.

Parameters
cntnrThe other PropertyContainer instance.

◆ __getitem__()

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

Returns the value of the property specified by key.

If an entry for the specified property exists, the stored value will be returned. Otherwise a Base.ItemNotFound exception will be thrown.

Parameters
keyThe key of the property value to return.
Returns
The stored property value.
Exceptions
Base.ItemNotFoundif an entry for the requested property value does not exist.

◆ __contains__()

bool CDPL.Base.PropertyContainer.__contains__ ( 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.

◆ __setitem__()

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

Sets the value of the property specified by key to val.

If val is of type Base.Any and empty, i.e. the method Base.Any.isEmpty() returns True, and a property entry for key exists, the entry gets erased (equivalent to removeProperty() with key as argument).

Parameters
keyThe key of the property value to assign or remove.
valThe value of the property.

◆ __delitem__()

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

Removes the entry for the property specified by key.

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

◆ __len__()

int CDPL.Base.PropertyContainer.__len__ ( )