module Pione::TupleSpace::TupleDefinition

Public Instance Methods

any() click to toggle source

Returns a respresentation for matching any tuples of same type. @return [TupleObject]

a query tuple that matches any tuples has the identifier
# File lib/pione/tuple-space/basic-tuple.rb, line 108
def any
  new
end
define_format(format) click to toggle source

Defines a tuple format and create a class representing it. @return [void]

# File lib/pione/tuple-space/basic-tuple.rb, line 54
def define_format(format)
  raise ScriptError if @format
  @format = format

  identifier = format.first
  set_attr_accessors

  # check arguments: format is a list of symbols
  format.each do |name, _|
    unless Symbol === name
      raise TupleFormatError.new(name, identifier)
    end
  end

  # forbid to define same identifier and different format
  if TUPLE.has_key?(identifier)
    if not(TUPLE[identifier].format == format)
      raise TupleFormatError.new(format, identifier)
    else
      return TUPLE[identifier]
    end
  end

  # make a class and set it in a table
  TUPLE[identifier] = self
end
delete_format(identifier) click to toggle source

Deletes a tuple format definition. @return [void]

# File lib/pione/tuple-space/basic-tuple.rb, line 83
def delete_format(identifier)
  if TUPLE.has_key?(identifier)
    name = TUPLE[identifier].name.split('::').last
    TUPLE.delete(identifier)
    remove_const(name)
  end
end
domain_position() click to toggle source

Returns domain position of the format. @return [Integer, nil]

position number of domain field, or nil

@api private

# File lib/pione/tuple-space/basic-tuple.rb, line 116
def domain_position
  position_of(:domain) || position_of(:domain_id)
end
format() click to toggle source

Returns tuple’s format. @return [Array]

tuple's format
# File lib/pione/tuple-space/basic-tuple.rb, line 94
def format
  @format
end
identifier() click to toggle source

Returns the identifier. @return [Symbol]

identifier of the tuple
# File lib/pione/tuple-space/basic-tuple.rb, line 101
def identifier
  @format.first
end
location_position() click to toggle source

Return location position of the format.

@return [Integer or nil]

position number of location field, or nil

@api private

# File lib/pione/tuple-space/basic-tuple.rb, line 125
def location_position
  position_of(:location)
end

Private Instance Methods

position_of(name) click to toggle source

@api private

# File lib/pione/tuple-space/basic-tuple.rb, line 143
def position_of(name)
  @format.each_with_index do |key, i|
    key = key.kind_of?(Array) ? key.first : key
    return i if key == name
  end
  return nil
end
set_attr_accessors() click to toggle source

Sets the tuple format and creates accessor methods. @param [Array] definition

tuple format

@return [void]

# File lib/pione/tuple-space/basic-tuple.rb, line 135
def set_attr_accessors
  @format.each do |key, _|
    define_method(key) {@data[key]}
    define_method("%s=" % key) {|val| @data[key] = val}
  end
end