Sha256: ef66cdcdaa062d3182b87d2e01da03dc080771e3954ec2f21f6d756dec13e13f

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8

# Workspace instance methods related to Petri net itsef (places, transitions,
# net instances).
# 
module YPetri::World::PetriNetRelated
  # Instance initialization.
  # 
  def initialize
    set_up_Top_net # Sets up :Top net encompassing all places and transitions.
    super
  end

  # Returns a place instance identified by the argument.
  # 
  def place id
    Place().instance( id )
  end

  # Returns a transition instance identified by the argument.
  # 
  def transition id
    Transition().instance( id )
  end

  # Returns a net instance identified by the argument.
  # 
  def net id
    Net().instance( id )
  end

  # Place instances.
  # 
  def places
    Place().instances
  end

  # Transition instances.
  # 
  def transitions
    Transition().instances
  end

  # Net instances.
  # 
  def nets
    Net().instances
  end

  private

  # Creates all-encompassing Net instance named :Top.
  # 
  def set_up_Top_net
    Net().new name: :Top # all-encompassing :Top net
    # Hook new places to add themselves magically to the :Top net.
    Place().new_instance_closure { |new_inst| net( :Top ) << new_inst }
    # Hook new transitions to add themselves magically to the :Top net.
    Transition().new_instance_closure { |new_inst| net( :Top ) << new_inst }    
  end
end # module YPetri::World::PetriNetRelated

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
y_petri-2.1.7 lib/y_petri/world/petri_net_related.rb
y_petri-2.1.6 lib/y_petri/world/petri_net_related.rb
y_petri-2.1.3 lib/y_petri/world/petri_net_related.rb