class DataManager

Public Class Methods

new(template, manager) click to toggle source
# File template.rb, line 1202
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 1235
def align(value)

  value_in_bytes = @template.alignment_in_bytes(value)

  @builder.align value, value_in_bytes

end
beginConfig(target, addressableSize) click to toggle source
# File template.rb, line 1210
def beginConfig(target, addressableSize)

  @configurer = @manager.beginConfig target, addressableSize

end
beginData(global, separate_file) click to toggle source
# File template.rb, line 1219
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 1333
def comment(value)

  @builder.addComment value

end
data(attrs = {}, &contents) click to toggle source
# File template.rb, line 1341
def data(attrs = {}, &contents)

  self.instance_eval &contents

end
define_ascii_string(attrs) click to toggle source
# File template.rb, line 1315
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 1301
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 1278
def define_type(attrs)

  id   = get_attribute attrs, :id

  text = get_attribute attrs, :text

  type = get_attribute attrs, :type

  format = attrs.has_key?(:format) ? attrs[:format] : ''



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



  p = lambda do |*arguments|

    dataBuilder = @builder.addDataValues id

    arguments.each do |value|

      if value.is_a?(Float) then

        dataBuilder.addDouble value

      else

        dataBuilder.add value

      end

    end

    dataBuilder.build

  end



  define_method_for DataManager, id, 'type', p

end
dist(*ranges) click to toggle source
# File template.rb, line 1270
def dist(*ranges)

  @template.dist *ranges

end
endConfig() click to toggle source
# File template.rb, line 1214
def endConfig

  @manager.endConfig

  @configurer = nil

end
endData() click to toggle source
# File template.rb, line 1227
def endData

  @ref_count = @ref_count - 1

  if @ref_count == 0

    @template.template.endData

    @builder = nil

  end

end
global_label(id) click to toggle source
# File template.rb, line 1262
def global_label(id)

  @builder.addLabel id, true

end
label(id) click to toggle source
# File template.rb, line 1258
def label(id)

  @builder.addLabel id, false

end
method_missing(meth, *args, &block) click to toggle source
# File template.rb, line 1345
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 "Method '#{meth}' is not available in data sections."

  end

end
org(origin) click to toggle source
# File template.rb, line 1240
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 "delta (#{delta}) must be an Integer."

    end

    @builder.setRelativeOrigin delta

  else

    raise "origin (#{origin}) must be an Integer or a Hash."

  end

end
rand(from, to) click to toggle source
# File template.rb, line 1266
def rand(from, to)

  @template.rand from, to

end
range(attrs = {}) click to toggle source
# File template.rb, line 1274
def range(attrs = {})

  @template.range attrs

end
text(value) click to toggle source
# File template.rb, line 1329
def text(value)

  @builder.addText value

end
type(*args) click to toggle source
# File template.rb, line 1254
def type(*args)

  Type.new *args

end
value(*args) click to toggle source
# File template.rb, line 1337
def value(*args)

  @template.value *args

end