00001 """
00002 Node classes for use in the graph and HashTable
00003 """
00004
00005 __copyright__ = """
00006 Copyright 2008 Sean Ross-Ross
00007 """
00008 __license__ = """
00009 This file is part of SLIMpy .
00010
00011 SLIMpy is free software: you can redistribute it and/or modify
00012 it under the terms of the GNU Lesser General Public License as published by
00013 the Free Software Foundation, either version 3 of the License, or
00014 (at your option) any later version.
00015
00016 SLIMpy is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 GNU Lesser General Public License for more details.
00020
00021 You should have received a copy of the GNU Lesser General Public License
00022 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00023 """
00024
00025
00026
00027 from slimpy_base.Environment.InstanceManager import InstanceManager
00028
00029 class Node( object ):
00030 """
00031 Node class to represent data and commands in the hash table
00032
00033 """
00034
00035 env = InstanceManager()
00036
00037 _objID = None
00038 __setstate__= None
00039 name = "Node"
00040
00041 def __init__( self, obj ):
00042 """
00043 take any object and store it to the hashtable
00044 while tracking it with this node instance
00045 """
00046 table = self.env['table']
00047 self._objID = table.append( obj )
00048
00049 def get( self ):
00050 """
00051 get object associated with this node from the hash Table
00052 """
00053 table = self.env['table']
00054 return table[self._objID]
00055
00056 def getID( self ):
00057 """
00058 return int id of node object
00059 """
00060 return self._objID
00061
00062 id = property( getID )
00063
00064 def __str__( self ):
00065 return "(%s:%s)"%( self.name, self._objID )
00066
00067 def __repr__( self ):
00068 return self.__str__()
00069
00070 def __getattr__( self, attr ):
00071
00072 return getattr( self.get(), attr )
00073
00074 def __eq__(self, other):
00075 if isinstance(other, Node) and self.id == other.id:
00076 return True
00077 else:
00078 return False
00079
00080
00081 class Target( Node ):
00082 """
00083 Target class is just to differentiate between different nodes in the command object
00084 """
00085 name = "Target"
00086
00087 class Source( Node ):
00088 """
00089 Source class is just to differentiate between different nodes in the command object
00090 """
00091 name = "Source"