00001 """
00002 Factory Classes to create Structure instances from actual data
00003
00004 """
00005
00006
00007 __copyright__ = """
00008 Copyright 2008 Sean Ross-Ross
00009 """
00010 __license__ = """
00011 This file is part of SLIMpy .
00012
00013 SLIMpy is free software: you can redistribute it and/or modify
00014 it under the terms of the GNU Lesser General Public License as published by
00015 the Free Software Foundation, either version 3 of the License, or
00016 (at your option) any later version.
00017
00018 SLIMpy is distributed in the hope that it will be useful,
00019 but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021 GNU Lesser General Public License for more details.
00022
00023 You should have received a copy of the GNU Lesser General Public License
00024 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00025 """
00026
00027 from slimpy_base.Core.Interface.AbstractDataInterface import ADI
00028 from slimpy_base.Core.Interface.ContainerBase import contain
00029 from slimpy_base.Core.User.Structures.serial_vector import Vector
00030 from slimpy_base.Environment.InstanceManager import InstanceManager
00031 from slimpy_base.utils.Profileable import Profileable,note
00032
00033
00034 class VectorFactory( object ):
00035 """
00036 factory class to contain data into a subclass of
00037 dataContainer and put that into a vector
00038 """
00039
00040 __metaclass__ = Profileable
00041 """
00042 Class used as a convinience method to contain various data formats and
00043 return a vector
00044 """
00045
00046 env = InstanceManager()
00047
00048 @note("class is initialized by user")
00049 def __init__( self ):
00050 """
00051 nothing done in the init
00052 """
00053 pass
00054
00055 def __call__( self, data ):
00056 """
00057 contain data into a subclass of dataContainer and put that into a vector
00058 """
00059 if isinstance(data, ADI):
00060 newdata = data.container
00061
00062 else:
00063 newdata = contain( data )
00064 self.env['graphmgr'].add_source( newdata )
00065
00066 return Vector( newdata )
00067
00068 def __str__(self):
00069 return "<SLIMpy function: vector>"
00070
00071 def __repr__(self):
00072 return "SLIMpy.VectorFactory( )"
00073
00074