class DataManager

Public Class Methods

new(template, manager) click to toggle source
# File template.rb, line 986
def initialize(template, manager)
  @template = template
  @manager = manager

  @builder = nil
  @ref_count = 0
end

Public Instance Methods

align(value) click to toggle source
# File template.rb, line 1019
def align(value)
  value_in_bytes = @template.alignment_in_bytes(value)
  @builder.align value, value_in_bytes
end
beginConfig(target, addressableSize, baseVirtAddr) click to toggle source
# File template.rb, line 994
def beginConfig(target, addressableSize, baseVirtAddr)
  @configurer = @manager.beginConfig target, addressableSize, baseVirtAddr
end
beginData(global, separate_file) click to toggle source
# File template.rb, line 1003
def beginData(global, separate_file)
  if @ref_count == 0
    @builder = @template.template.beginData global, separate_file
  end
  @ref_count = @ref_count + 1
  @builder
end
comment(value) click to toggle source
# File template.rb, line 1108
def comment(value)
  @builder.addComment value
end
data(attrs = {}, &contents) click to toggle source
# File template.rb, line 1116
def data(attrs = {}, &contents)
  self.instance_eval &contents
end
define_ascii_string(attrs) click to toggle source
# File template.rb, line 1090
def define_ascii_string(attrs)
  id       = get_attribute attrs, :id
  text     = get_attribute attrs, :text
  zeroTerm = get_attribute attrs, :zero_term

  @configurer.defineAsciiString id, text, zeroTerm

  p = lambda do |*strings|
    @builder.addAsciiStrings zeroTerm, strings
  end

  define_method_for DataManager, id, 'string', p
end
define_space(attrs) click to toggle source
# File template.rb, line 1076
def define_space(attrs)
  id       = get_attribute attrs, :id
  text     = get_attribute attrs, :text
  fillWith = get_attribute attrs, :fill_with

  @configurer.defineSpace id, text, fillWith

  p = lambda do |length|
    @builder.addSpace length
  end

  define_method_for DataManager, id, 'space', p
end
define_type(attrs) click to toggle source
# File template.rb, line 1058
def define_type(attrs)
  id   = get_attribute attrs, :id
  text = get_attribute attrs, :text
  type = get_attribute attrs, :type

  @configurer.defineType id, text, type.name, type.args

  p = lambda do |*arguments|
    dataBuilder = @builder.addDataValues id
    arguments.each do |value|
      dataBuilder.add value
    end
    dataBuilder.build
  end

  define_method_for DataManager, id, 'type', p
end
dist(*ranges) click to toggle source
# File template.rb, line 1050
def dist(*ranges)
  @template.dist *ranges
end
endConfig() click to toggle source
# File template.rb, line 998
def endConfig
  @manager.endConfig
  @configurer = nil
end
endData() click to toggle source
# File template.rb, line 1011
def endData
  @ref_count = @ref_count - 1
  if @ref_count == 0
    @template.template.endData
    @builder = nil
  end
end
label(id) click to toggle source
# File template.rb, line 1042
def label(id)
  @builder.addLabel id
end
method_missing(meth, *args, &block) click to toggle source
# File template.rb, line 1120
def method_missing(meth, *args, &block)
  # Redirecting call to the template. Note: methods of Template are not accepted.
  if @template.respond_to?(meth) and not Template.instance_methods.include?(meth)
    @template.send meth, *args, &block
  else
    raise MTRubyError, "Method '#{meth}' is not available in data sections."
  end
end
org(origin) click to toggle source
# File template.rb, line 1024
def org(origin)
  if origin.is_a?(Integer)
    @builder.setOrigin origin
  elsif origin.is_a?(Hash)
    delta = get_attribute origin, :delta
    if !delta.is_a?(Integer)
      raise MTRubyError, "delta (#{delta}) must be an Integer."
    end
    @builder.setRelativeOrigin delta
  else
    raise MTRubyError, "origin (#{origin}) must be an Integer or a Hash."
  end
end
rand(from, to) click to toggle source
# File template.rb, line 1046
def rand(from, to)
  @template.rand from, to
end
range(attrs = {}) click to toggle source
# File template.rb, line 1054
def range(attrs = {})
  @template.range attrs
end
text(value) click to toggle source
# File template.rb, line 1104
def text(value)
  @builder.addText value
end
type(*args) click to toggle source
# File template.rb, line 1038
def type(*args)
  Type.new *args
end
value(*args) click to toggle source
# File template.rb, line 1112
def value(*args)
  @template.value *args 
end