Back to index

salome-kernel  6.5.0
Public Member Functions | Private Member Functions | Private Attributes
KERNEL_PY.kernel.datamodeler.DataModeler Class Reference

List of all members.

Public Member Functions

def __init__
def addAttribute
def __setattr__
def __getattribute__
def log

Private Member Functions

def __isNotValidType
def __isNotValidRange
def __isVoidAllowed

Private Attributes

 _typemap
 _rangemap
 _defaultmap
 _voidmap

Detailed Description

This class is a placeholder for modeling data. An object based on this class
(particular instance or specialized derived class) can defined attributes with
the following properties:

- a type : the class or the type of the attribute. Setting an attribute to
  a value whose type is not the specified type raises an exception.
- a range : a list of the possible values for the attribute. Setting an
  attribute to a value not in the range raises an exception
- a default: the default value of an attribute when an instance is created
- a void flag: the attribute can be authorized to be None or not using this
  flag. Setting an attribute to a None value while the flag is not set to
  True raises an exception. By default, a None value is not allowed.

These properties are dictionnaries mapping the attribute name to its
associated value for the property.

A typical usage is to derived this class in a specialized form where the
attributes names and there properties are defined in the constructor. See
use cases at the end of this file.

Definition at line 46 of file datamodeler.py.


Constructor & Destructor Documentation

def KERNEL_PY.kernel.datamodeler.DataModeler.__init__ (   self,
  typemap = None,
  rangemap = None,
  defaultmap = None,
  voidmap = None 
)

Definition at line 69 of file datamodeler.py.

00069 
00070     def __init__(self, typemap=None, rangemap=None, defaultmap=None, voidmap=None):
00071         self._typemap = {}
00072         self._rangemap   = {} # possible values
00073         self._defaultmap = {} # defaults values
00074         self._voidmap    = {}    # None values are allowed
00075         
00076         if typemap is not None:
00077             self._typemap.update(typemap)
00078         if rangemap is not None:
00079             self._rangemap.update(rangemap)
00080         if voidmap is not None:
00081             self._voidmap.update(voidmap)
00082 
00083         # Default initialization (if any)
00084         if defaultmap is not None:
00085             self._defaultmap.update(defaultmap)
00086             for name in self._defaultmap.keys():
00087                 self.__setattr__(name,self._defaultmap[name])


Member Function Documentation

Definition at line 133 of file datamodeler.py.

00133 
00134     def __getattribute__(self, name):
00135         if name in UNCHECKED_ATTRIBUTES:
00136             return self.__dict__[name]
00137 
00138         if name not in self._typemap.keys():
00139             raise DevelException("The class "+str(self.__class__)+" has no attribute "+str(name))
00140         # The attribute coulb be requested while it has not been created yet (for
00141         # example if we did't call the setter before).
00142         if not self.__dict__.has_key(name):
00143             return None
00144         
00145         return self.__dict__[name]

Here is the call graph for this function:

def KERNEL_PY.kernel.datamodeler.DataModeler.__isNotValidRange (   self,
  name,
  val 
) [private]

Definition at line 153 of file datamodeler.py.

00153 
00154     def __isNotValidRange(self, name, val):
00155         isNotValid = (
00156             ( self._rangemap is not None) and
00157             ( self._rangemap.has_key(name) ) and
00158             ( self._rangemap[name] is not None ) and
00159             ( val not in self._rangemap[name] ) )
00160 
00161         return isNotValid

Here is the caller graph for this function:

def KERNEL_PY.kernel.datamodeler.DataModeler.__isNotValidType (   self,
  name,
  val 
) [private]

Definition at line 146 of file datamodeler.py.

00146 
00147     def __isNotValidType(self, name, val):
00148         isNotValid = (
00149             ( self._typemap[name] is not None) and
00150             ( not isinstance(val,self._typemap[name]) ) )
00151 
00152         return isNotValid

Here is the caller graph for this function:

def KERNEL_PY.kernel.datamodeler.DataModeler.__isVoidAllowed (   self,
  name 
) [private]

Definition at line 162 of file datamodeler.py.

00162 
00163     def __isVoidAllowed(self,name):
00164         isVoidAllowed = (
00165             ( self._voidmap is not None) and
00166             ( self._voidmap.has_key(name) ) and
00167             ( self._voidmap[name] is True ) )
00168             
00169         return isVoidAllowed

Here is the caller graph for this function:

def KERNEL_PY.kernel.datamodeler.DataModeler.__setattr__ (   self,
  name,
  val 
)

Definition at line 105 of file datamodeler.py.

00105 
00106     def __setattr__(self, name, val):
00107         if name in UNCHECKED_ATTRIBUTES:
00108             self.__dict__[name] = val
00109             return
00110 
00111         #__GBO_DEBUG_
00112         if name == "_typemap":
00113             print "WARNING WARNING WARNING : changing value of _typemap by ",val
00114 
00115         if name not in self._typemap.keys():
00116             raise DevelException("The class "+str(self.__class__)+" has no attribute "+str(name))
00117 
00118         if val is None:
00119             if not self.__isVoidAllowed(name):
00120                 raise DevelException("The attribute "+str(name)+" can't be None")
00121             else:
00122                 # We can stop here and set the value to None
00123                 self.__dict__[name] = None
00124                 return
00125 
00126         if self.__isNotValidType(name,val):
00127             raise DevelException("The attribute "+str(name)+" must be an instance of "+str(self._typemap[name]))
00128 
00129         if self.__isNotValidRange(name,val):
00130             raise DevelException("The attribute "+str(name)+" must be a value in :"+str(self._rangemap[name]))
00131 
00132         self.__dict__[name] = val
    

Here is the call graph for this function:

Here is the caller graph for this function:

def KERNEL_PY.kernel.datamodeler.DataModeler.addAttribute (   self,
  name,
  type = None,
  range = None,
  default = None,
  void = None 
)
A None argument means that no entry is created in the associated maps.

Definition at line 88 of file datamodeler.py.

00088 
00089     def addAttribute(self, name, type=None, range=None, default=None, void=None):
00090         """
00091         A None argument means that no entry is created in the associated maps.
00092         """
00093         self._typemap[name] = type
00094 
00095         if range is not None:
00096             self._rangemap[name] = range
00097 
00098         if void is not None:
00099             self._voidmap[name] = void
00100 
00101         if (not void) and (default is None):
00102             return
00103         
00104         self.__setattr__(name,default)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 170 of file datamodeler.py.

00170 
00171     def log(self):
00172         print "DATAMODELER ["+str(self.__class__)+"]: self._typemap.keys() = "+str(self._typemap.keys())
00173 
00174 
00175 
00176 
00177 #
00178 # ==============================================================================
00179 # Basic use cases and unit tests
00180 # ==============================================================================
#

Member Data Documentation

Definition at line 72 of file datamodeler.py.

Definition at line 71 of file datamodeler.py.

Definition at line 70 of file datamodeler.py.

Definition at line 73 of file datamodeler.py.


The documentation for this class was generated from the following file: