SDS2 Parametric API
 All Classes Namespaces Functions Variables Pages
List of all members
ComponentState.ComponentState Class Reference

This is a helper to make Component.GetState easy to implement. More...

Methods defined here:

def __eq__
def __init__

Class methods defined here:

def Ignore
def Round

Data descriptors defined here:

def __dict__
 dictionary for instance variables (if defined)
def __weakref__
 list of weak references to the object (if defined)

Detailed Description

This is a helper to make Component.GetState easy to implement.

Simply return a new ComponentState with a key value list of tuples. You may also specify specific options for specific keys. For anything you may specific ComponentState.Ignore to have it not be included in the state. For floating point values you may give a rounding value:

def GetState( self ): return ComponentState( ( ( 'value1', self.value1 ), ( 'value2', self.value2 ) ), value2=ComponentState.Round(1.0/16.0) )

Or, if you use StateAccessor: def GetState( self ): return ComponentState( self, value2=ComponentState.Round(1.0/16.0), value3=ComponentState.Ignore )

Remember that State is all about whether or not process is needed. So don't include things in the state that don't affect process. That's what ComponentState.Ignore is there to help with.

Aside from ComponentState.Round and ComponentState.Ignore you may specify any callable (such as a function or lambda) which takes the value as an argument and returns a value. Examples include:

To ignore something, just always return None. def ignore( x ): return None

To round something: def round_sixteenths( x ): round( val*(1.0/(1.0/16.0)), 0 ) * (1.0/(1.0/16.0))

To make a copy of a class instance, just use python's copy module: import copy copy.copy

The purpose of these callables is to mutate the value such that if you ignore any differences that won't show differences in process.

Constructor & Destructor Documentation

def ComponentState.ComponentState.__init__ (   args)
 values - Either 'self' if you used StateAccessor.  Or a list of two-tuples.
          The two-tuples are ( "key", value ), where value can be any python
          type that can compare it's equality.
 **options - You can specify keyword arguments where the keyword is a key
             in your values list (or something you serialize if you used StateAccessor)
             and its value can be:
               - A floating point value to round to if it's a float
               - ComponentState.Ignore if you'd like this value to not be
                 used as a part of the state.  This one is especially useful
                 if you use StateAccessor and serialize some properties that
                 won't affect process.

Member Function Documentation

def ComponentState.ComponentState.__dict__ (   args)

dictionary for instance variables (if defined)

def ComponentState.ComponentState.__eq__ (   args)
 __eq__(args)
def ComponentState.ComponentState.__weakref__ (   args)

list of weak references to the object (if defined)

def ComponentState.ComponentState.Ignore (   args)
 Ignore(args)

builtin.type_cls_m Class Methods from builtin.type

def ComponentState.ComponentState.Round (   args)
 Round(args)

builtin.type_cls_m Class Methods from builtin.type