00001 __copyright__ = """
00002 Copyright 2008 Sean Ross-Ross
00003 """
00004 __license__ = """
00005 This file is part of SLIMpy .
00006
00007 SLIMpy is free software: you can redistribute it and/or modify
00008 it under the terms of the GNU Lesser General Public License as published by
00009 the Free Software Foundation, either version 3 of the License, or
00010 (at your option) any later version.
00011
00012 SLIMpy is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015 GNU Lesser General Public License for more details.
00016
00017 You should have received a copy of the GNU Lesser General Public License
00018 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00019 """
00020
00021 from slimpy_base.Core.Interface.Structure import Structure as __Structure
00022
00023 class ADI( __Structure ):
00024 """
00025 Same as Structure except that this class has a dataContainer instance within
00026 """
00027 name = "Abstract_data_interface"
00028
00029 def __init__( self, data_container ):
00030 self.__data_container = data_container
00031 self._scalar_lookup = {}
00032
00033
00034 def accept_command( self, command ):
00035
00036 return super( ADI, self ).apply_command( self, command )
00037
00038 def generateNew( self, cmd, *args, **kargs ):
00039
00040 return super( ADI, self ).generateNew( self, cmd, *args, **kargs )
00041
00042 def genData( self, cmd, *args, **kargs ):
00043
00044 return super( ADI, self ).genData( self, cmd, *args, **kargs )
00045
00046 def testCommand( self, cmd, *args, **kargs ):
00047 """
00048 returns the resulting space from applying the command but does not add the command to the tree
00049 """
00050 return super( ADI, self ).testCommand( self.getParameters(), cmd, *args, **kargs )
00051
00052
00053
00054 def __str__( self ):
00055 """
00056 wrapper method to data_container.__str__
00057 """
00058 return "<SLIMpy.%s '%s'>" %( self.name, self.container )
00059
00060
00061 def __repr__( self ):
00062 return self.__str__()
00063
00064
00065 def getContainer( self ):
00066 return self.__data_container
00067
00068 def getParameters( self ):
00069
00070 return self.container.params
00071
00072 container = property( getContainer )
00073 params = property( getParameters )
00074
00075 def switchto( self, newSubclass, *p, **k ):
00076 """
00077 pass a class as the newSubclass arg and returns a new
00078 instance of the newSubclass with this structure's
00079 """
00080 return newSubclass( self.container, *p, **k )
00081
00082 def scalar_reduction( self, cmd, *args, **kargs ):
00083 """
00084 generate a Scalar from a command
00085 """
00086 scal_key = ( cmd, args, tuple( kargs.items() ) )
00087 if self._scalar_lookup.has_key( scal_key ):
00088 scal = self._scalar_lookup[ scal_key ]
00089 return scal
00090 else:
00091 scal = super( ADI, self ).scalar_reduction( self.container, cmd, *args, **kargs )
00092 self._scalar_lookup[ scal_key ] = scal
00093 return scal
00094
00095 def flush( self ):
00096 """
00097 force the commands in the graph to be run only to build this target.
00098 """
00099
00100 super( ADI, self ).flush( self.getContainer() )
00101
00102 return self
00103
00104 def dependant( self ):
00105 return super( ADI, self ).dependant( self.getContainer() )
00106
00107 def addBreakPoint( self ):
00108 """
00109 set the data from the interface as a needed
00110 resource without setting it as a target.
00111 """
00112 super( ADI, self ).addBreakPoint( self.getContainer() )
00113
00114 return self