codeable_models.CObject¶
-
class
codeable_models.
CObject
(cl, name=None, **kwargs)¶ CObject
is used to define objects. Objects in Codeable Models are instances of classes (defined usingCClass
).Superclasses:
CBundlable
- Parameters
Examples:
An example object definition is:
basic_pen = CObject(product, values={"id": "P001", "name": "Basic Pen", "price": 1.50})
Here an unnamed object is derived from class
product
with two string valuesid
andname
, as well as a float valueprice
. The following defines the same object, except that it uses an object name instead of defining a name as an attribute value:basic_pen = CObject(product, "Basic Pen", values={"id": "P001", "price": 1.50})
Main Relations:
The main relations of
CObject
are shown in the figure below.Each
CObject
can be used in bundles through its superclassCBundlable
. Objects are instances of typeCClass
.Each
CClass
has oneclass object
, a special object to manage the instance relation of a class to its meta-class. For instance, the values of meta-class attributes and links for meta-class associations are stored and managed via wrapper methods onCClass
that call the respective methods of theclass object
.Each object can be source or target of a link. Links are only valid, if there is an association between the classes of the objects to be linked (and multiplicities are correctly set on these associations). The association is the classifier of the link (thus it inherits from
CClassifier
), and the link is interpreted as an instance of the association (thus it inherits fromCObject
).-
add_links
(links, **kwargs)¶ Add links on this object (which are based on associations defined on the object’s class). Uses the function
add_links()
. That is, it is possible to use the following equivalently:add_links({<this_object>: <links>}, <**kwargs>)
- Parameters
links – The new links to be defined.
**kwargs – Any keyword arg acceptable to
add_links()
.
- Returns
List of created link objects.
- Return type
list[CLink]
-
property
class_object_class
¶ Getter for the class that has this object as a class object. Returns
None
if this object is not a class object.- Type
-
property
classifier
¶ Get/set the classifier of this object. For the setter, changes to the classifier (i.e., the association) of a link should not be performed with
CObject
methods.- Type
-
delete
()¶ Delete the object and delete it from its classifier. Delete all links of the object. Calls
delete()
on superclass.- Returns
None
-
delete_links
(links, **kwargs)¶ Delete links on this object (which are based on associations defined on the object’s class). Uses the function
delete_links()
. That is, it is possible to use the following equivalently:delete_links({<this_object>: <links>}, <**kwargs>)
- Parameters
links – The links to be deleted.
**kwargs – Any keyword arg acceptable to
delete_links()
.
- Returns
List of deleted link objects.
- Return type
list[CLink]
-
delete_value
(attribute_name, classifier=None)¶ Delete the value of an attribute with the given
attribute_name
. Optionally the classifier to consider can be specified. This is needed, if one or more attributes of the same name are defined on the inheritance hierarchy. Then a shadowed attribute can be accessed by specifying its classifier.- Parameters
attribute_name – The name of the attribute.
classifier – The optional classifier on which the attribute is defined.
- Returns
Value of the attribute.
- Return type
Supported Attribute Types
-
get_linked
(**kwargs)¶ Method to get the linked objects defined for this object filtered using criteria specified in kwargs.
- Parameters
**kwargs –
Defines filter criteria.
association
:Include links only if they are based on the specified association.
role_name
:Include links only if they are based on an associations having the specified role name either as a target or source role name.
- Returns
List of linked objects
- Return type
list[CObject]
-
get_links_for_association
(association)¶ Method to get all link objects which are defined based on the given association.
- Parameters
association – Association used to filter the links.
- Returns
The list of link objects.
- Return type
list[CLink]
-
get_value
(attribute_name, classifier=None)¶ Get the value of an attribute with the given
attribute_name
. Optionally the classifier to consider can be specified. This is needed, if one or more attributes of the same name are defined on the inheritance hierarchy. Then a shadowed attribute can be accessed by specifying its classifier.- Parameters
attribute_name – The name of the attribute.
classifier – The optional classifier on which the attribute is defined.
- Returns
Value of the attribute.
- Return type
Supported Attribute Types
-
instance_of
(classifier)¶ Tests whether this object is an instance of
classifier
or not.- Parameters
classifier (CClassifier) – The classifier to test against.
- Returns
The result of the test.
- Return type
bool
-
property
links
¶ Getter for getting the links defined for this object. Object links are based on the associations defined for the object’s class.
- Type
list[CLink]
-
set_value
(attribute_name, value, classifier=None)¶ Set the value of an attribute with the given
attribute_name
tovalue
. Optionally the classifier to consider can be specified. This is needed, if one or more attributes of the same name are defined on the inheritance hierarchy. Then a shadowed attribute can be accessed by specifying its classifier.- Parameters
attribute_name – The name of the attribute.
value – The new value.
classifier – The optional classifier on which the attribute is defined.
- Returns
None
-
property
values
¶ Getter for getting all values of the object using a dict, and setter of setting all values of the object based on a dict. The dict uses key/value pairs. The value types must conform to the types defined for the attributes.
- Type
dict[str, value]