class BOAST::Case

@!parse module Functors; functorize Case; end

Attributes

case_conditions[R]
expression[R]

Public Class Methods

new(expression, control = {}, &block) click to toggle source

Creates a new instance of the Caonstruct @param [#to_s] expression tested Expression/Variable @param [Hash{#to_s, :default => Proc}] control conditions and associated blocks. @param [Proc,nil] block if provided, and :default is not defined in control (or nil), will be used as the default block.

Calls superclass method
# File lib/BOAST/Language/Case.rb, line 88
def initialize(expression, control = {}, &block)
  super()
  @expression = expression
  @case_conditions = []
  default = control.delete(:default)
  default = block unless default or not block
  control.each { |key, value|
    @case_conditions.push CaseCondition::new( [key].flatten, &value )
  }
  @case_conditions.push CaseCondition::new( &default ) if default
end

Public Instance Methods

close() click to toggle source
# File lib/BOAST/Language/Case.rb, line 145
def close
  decrement_indent_level
  s = ""
  s << indent
  s << end_string
  output.puts s
  return self
end
get_cl_strings()
Alias for: get_c_strings
get_cuda_strings()
Alias for: get_c_strings
open() click to toggle source
# File lib/BOAST/Language/Case.rb, line 124
def open
  s = ""
  s << indent
  s << to_s
  output.puts s
  increment_indent_level
  return self
end
pr(*args) click to toggle source
# File lib/BOAST/Language/Case.rb, line 133
def pr(*args)
  args = @args if args.length == 0 and @args
  open
  if @case_conditions.size > 0 then
    @case_conditions.each { |cond|
      cond.pr(*args)
    }
    close
  end
  return self
end
to_s() click to toggle source
# File lib/BOAST/Language/Case.rb, line 118
def to_s
  s = ""
  s << switch_string(@expression)
  return s
end

Private Instance Methods

get_c_strings() click to toggle source
# File lib/BOAST/Language/Case.rb, line 100
def get_c_strings
  return { :switch => '"switch (#{expr}) {"',
           :end => '"}"' }
end
Also aliased as: get_cl_strings, get_cuda_strings
get_fortran_strings() click to toggle source
# File lib/BOAST/Language/Case.rb, line 105
def get_fortran_strings
  return { :switch => '"select case (#{expr})"',
           :end => '"end select"' }
end