/[freeride]/freeride/freebase/databus.rb
ViewVC logotype

Diff of /freeride/freebase/databus.rb

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by richkilmer, Sat Aug 3 15:00:04 2002 UTC revision 1.9 by richkilmer, Fri Aug 9 13:09:37 2002 UTC
# Line 90  module FreeBASE Line 90  module FreeBASE
90        QUEUE = "queue_slot"        QUEUE = "queue_slot"
91        STACK = "stack_slot"        STACK = "stack_slot"
92        PROC  = "proc_slot"        PROC  = "proc_slot"
93        HASH  = "hash_slot"        MAP  = "map_slot"
94                
95        # True if notify method propagates to parent.notify, default=true        # True if notify method propagates to parent.notify, default=true
96        attr_accessor :propagate_notifications        attr_accessor :propagate_notifications
# Line 283  module FreeBASE Line 283  module FreeBASE
283        end        end
284                
285        ##        ##
286        # calls hash.put if this is a hash slot        # calls map.put if this is a map slot
287        #        #
288        def put(key, value)        def put(key, value)
289          return self.hash.put(key,value)          return self.map.put(key,value)
290        end        end
291                
292        ##        ##
293        # calls hash.get if this is a hash slot        # calls map.get if this is a map slot
294        #        #
295        def get(key)        def get(key)
296          return self.hash.get(key)          return self.map.get(key)
297        end        end
298                
299        ##        ##
300        # removes a key if this is a hash slot        # removes a key if this is a map slot
301        #        #
302        def remove(key)        def remove(key)
303          return self.hash.remove          return self.map.remove
304        end        end
305                
306        ##        ##
307        # Clears the stack or queue or hash depending on the slot type        # Clears the stack or queue or map depending on the slot type
308        #        #
309        def clear        def clear
310          return self.queue.clear if is_queue_slot?          return self.queue.clear if is_queue_slot?
311          return self.stack.clear if is_stack_slot?          return self.stack.clear if is_stack_slot?
312          return self.hash.clear if is_hash_slot?          return self.map.clear if is_map_slot?
313        end        end
314                
315        ##        ##
# Line 320  module FreeBASE Line 320  module FreeBASE
320        def count        def count
321          return self.queue.count if is_queue_slot?          return self.queue.count if is_queue_slot?
322          return self.stack.count if is_stack_slot?          return self.stack.count if is_stack_slot?
323          return self.hash.count if is_hash_slot?          return self.map.count if is_map_slot?
324        end        end
325                
326        ##        ##
# Line 401  module FreeBASE Line 401  module FreeBASE
401        end        end
402                
403        ##        ##
404        # Retrieves the HashWrapper object if this is a hash slot        # Retrieves the Map object if this is a hash slot
405        #        #
406        # return:: [FreeBASE::DataBus::HashWrapper] The HashWrapper object of this Hash slot        # return:: [FreeBASE::DataBus::Map] The HashWrapper object of this Hash slot
407        # raise:: [RuntimeException] If this slot is not a Hash slot        # raise:: [RuntimeException] If this slot is not a Hash slot
408        #        #
409        def hash        def map
410          check_type(HASH)          check_type(MAP)
411          @hash = HashWrapper.new(self) unless @hash          @map = Map.new(self) unless @map
412          return @hash          return @map
413        end        end
414                
415        ##        ##
416        # Checks if this is a Hash slot        # Checks if this is a map slot
417        #        #
418        # return:: [Boolean] true if this is a Hash slot        # return:: [Boolean] true if this is a map slot
419        #        #
420        def is_hash_slot?        def is_map_slot?
421          return @type==HASH          return @type==MAP
422        end        end
423                
424        ##        ##
# Line 764  module FreeBASE Line 764  module FreeBASE
764      end      end
765    
766      ##      ##
767      # The HashWrapper holds the Hash object for the Hash slot      # The Map holds the Hash object for the Hash slot
768      #      #
769      # Usage::      # Usage::
770      #  p = HashWrapper.new(self)      #  p = HashWrapper.new(self)
771      #  p.put(key, value)      #  p.put(key, value)
772      #  p.get(key) #=> value      #  p.get(key) #=> value
773      #      #
774      class HashWrapper      class Map
775        ##        ##
776        # Create the ProcWrapper object        # Create the Map object
777        #        #
778        # slot:: [FreeBASE::DataBus::Slot] The slot this proc wrapper belongs to.        # slot:: [FreeBASE::DataBus::Slot] The slot this proc wrapper belongs to.
779        #        #
780        def initialize(slot)        def initialize(slot)
781          @slot = slot          @slot = slot
782          @hash = {}          @map = {}
783        end        end
784                
785        ##        ##
# Line 787  module FreeBASE Line 787  module FreeBASE
787        #        #
788        # hash:: [Hash] The Hash to store        # hash:: [Hash] The Hash to store
789        #        #
790        def set_hash(hash)        def map=(hash)
791          @hash=hash          @map=hash
792          @slot.notify(:notify_hash_set)          @slot.notify(:notify_map_set)
793        end        end
794                
795        ##        ##
796        # Clears the hash        # Clears the hash
797        #        #
798        def clear()        def clear()
799          @hash = {}          @map = {}
800          @slot.notify(:notify_hash_cleared)          @slot.notify(:notify_map_cleared)
801        end        end
802                
803        ##        ##
# Line 806  module FreeBASE Line 806  module FreeBASE
806        # key:: [key] The key to remove        # key:: [key] The key to remove
807        #        #
808        def remove(key)        def remove(key)
809          return @hash.remove[key]          return @map.remove[key]
810          @slot.notify(:notify_hash_remove)          @slot.notify(:notify_map_remove)
811        end        end
812                
813        ##        ##
# Line 817  module FreeBASE Line 817  module FreeBASE
817        # return:: [Object] The value of the specified key        # return:: [Object] The value of the specified key
818        #        #
819        def get(key)        def get(key)
820          return @hash[key]          return @map[key]
821        end        end
822                
823        ##        ##
# Line 827  module FreeBASE Line 827  module FreeBASE
827        # value:: [Object] The value        # value:: [Object] The value
828        #        #
829        def put(key, value)        def put(key, value)
830          @hash[key]=value          @map[key]=value
831          @slot.notify(:notify_hash_put)          @slot.notify(:notify_map_put)
832        end        end
833    
834        ##        ##
# Line 837  module FreeBASE Line 837  module FreeBASE
837        # return:: [Integer] The number of objects        # return:: [Integer] The number of objects
838        #        #
839        def count        def count
840          return @hash.size          return @map.size
841        end        end
842    
843      end      end

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26