Class: BOAST::Ternary

Inherits:
Object show all
Includes:
Arithmetic
Defined in:
lib/BOAST/Operators.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Arithmetic

#!, #!=, #*, #+, #-, #-@, #/, #<, #<=, #==, #===, #>, #>=, #address, #dereference

Constructor Details

#initialize(x, y, z) ⇒ Ternary

Returns a new instance of Ternary.



413
414
415
416
417
# File 'lib/BOAST/Operators.rb', line 413

def initialize(x,y,z)
  @operand1 = x
  @operand2 = y
  @operand3 = z
end

Instance Attribute Details

#operand1Object (readonly)

Returns the value of attribute operand1.



409
410
411
# File 'lib/BOAST/Operators.rb', line 409

def operand1
  @operand1
end

#operand2Object (readonly)

Returns the value of attribute operand2.



410
411
412
# File 'lib/BOAST/Operators.rb', line 410

def operand2
  @operand2
end

#operand3Object (readonly)

Returns the value of attribute operand3.



411
412
413
# File 'lib/BOAST/Operators.rb', line 411

def operand3
  @operand3
end

Class Method Details

.parens(*args, &block) ⇒ Object



405
406
407
# File 'lib/BOAST/Operators.rb', line 405

def self.parens(*args,&block)
  return self::new(*args,&block)
end

Instance Method Details



431
432
433
434
435
436
437
438
# File 'lib/BOAST/Operators.rb', line 431

def print(final=true)
  s=""
  s += " "*BOAST::get_indent_level if final
  s += self.to_str
  s += ";" if final and [BOAST::C, BOAST::CL, BOAST::CUDA].include?( BOAST::get_lang )
  BOAST::get_output.puts s if final
  return s
end

#to_sObject



419
420
421
# File 'lib/BOAST/Operators.rb', line 419

def to_s
  self.to_str
end

#to_strObject



423
424
425
426
# File 'lib/BOAST/Operators.rb', line 423

def to_str
  raise "Ternary operator unsupported in FORTRAN!" if BOAST::get_lang == BOAST::FORTRAN
  return self.to_str_c if [BOAST::C, BOAST::CL, BOAST::CUDA].include?( BOAST::get_lang )
end

#to_str_cObject



427
428
429
430
# File 'lib/BOAST/Operators.rb', line 427

def to_str_c
  s = ""
  s += "(#{@operand1} ? #{@operand2} : #{@operand3})"
end