pyffi :: object_models :: simple_type :: SimpleType :: Class SimpleType
[hide private]
[frames] | no frames]

Class SimpleType

source code

            object --+        
                     |        
utils.graph.DetailNode --+    
                         |    
          any_type.AnyType --+
                             |
                            SimpleType
Known Subclasses:

Base class from which all simple types are derived. Simple types contain data which is not divided further into smaller pieces, and that can represented efficiently by a (usually native) Python type, typically int, float, or str.

A brief example of usage:

>>> class Short(SimpleType):
...     def __init__(self):
...         # for fun, let default value be 3
...         self._value = 3
...     def set_value(self, value):
...         # check type
...         if not isinstance(value, int):
...             raise TypeError("Expected int but got %s."
...                             % value.__class__.__name__)
...         # check range
...         if value < -0x8000 or value > 0x7fff:
...             raise ValueError("Value %i out of range." % value)
...         self._value = value
>>> test = Short()
>>> print(test)
3
>>> test.value = 255
>>> print(test)
255
>>> test.value = 100000 # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
ValueError: ...
>>> test.value = "hello world" # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
TypeError: ...

Also override read and write if you wish to read and write data of this type, and is_interchangeable if you wish to declare data as equivalent.

Nested Classes [hide private]
  __metaclass__
This metaclass binds the get_value and set_value methods to the value property.
Instance Methods [hide private]
str
__str__(self)
String representation.
source code
Whatever is appropriate.
get_value(self)
Return the stored value.
source code
 
set_value(self, value)
Set stored value.
source code
bool
is_interchangeable(self, other)
This checks for object identity of the value.
source code
str
get_detail_display(self)
Display string for the detail tree.
source code

Inherited from any_type.AnyType: __hash__, read, write

Inherited from utils.graph.DetailNode: get_detail_child_edge_types, get_detail_child_names, get_detail_child_nodes, get_detail_iterator, replace_global_node

Inherited from object: __delattr__, __format__, __getattribute__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Variables [hide private]
  _value = None
The data.
Properties [hide private]
  value
A property which wraps the actual data.

Inherited from object: __class__

Method Details [hide private]

__str__(self)
(Informal representation operator)

source code 
String representation. This implementation is simply a wrapper around str on _value.
Returns: str
String representation.
Overrides: object.__str__

get_value(self)

source code 
Return the stored value.
Returns: Whatever is appropriate.
The stored value.

set_value(self, value)

source code 
Set stored value. Override this method to enable validation (type checking, range checking, and so on).
Parameters:
  • value (Whatever is appropriate.) - The value to store.

is_interchangeable(self, other)

source code 
This checks for object identity of the value.
Returns: bool
True if objects are close, False otherwise.
Overrides: any_type.AnyType.is_interchangeable

get_detail_display(self)

source code 
Display string for the detail tree. This implementation is simply a wrapper around C{self.:attr:_value.__str__()}.
Returns: str
String representation.
Overrides: utils.graph.DetailNode.get_detail_display

Property Details [hide private]

value

A property which wraps the actual data. This property always calls set_value to assign the value, and ensures that the value is valid (type, range, ...). Unless you know what you are doing, always use the value property to change the data.
Get Method:
unreachable.get_value(self) - Return the stored value.
Set Method:
unreachable.set_value(self, value) - Set stored value.