Class: BOAST::Else

Inherits:
Object show all
Defined in:
lib/BOAST/Algorithm.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition = nil, &block) ⇒ Else

Returns a new instance of Else.



1422
1423
1424
1425
# File 'lib/BOAST/Algorithm.rb', line 1422

def initialize(condition=nil, &block)
  @condition = condition
  @block = block
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



1421
1422
1423
# File 'lib/BOAST/Algorithm.rb', line 1421

def condition
  @condition
end

Class Method Details

.parens(*args, &block) ⇒ Object



1417
1418
1419
# File 'lib/BOAST/Algorithm.rb', line 1417

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

Instance Method Details

#close(final = true) ⇒ Object



1465
1466
1467
1468
# File 'lib/BOAST/Algorithm.rb', line 1465

def close(final=true)
  return self.close_fortran(final) if BOAST::get_lang == FORTRAN
  return self.close_c(final) if [C, CL, CUDA].include?( BOAST::get_lang )
end

#close_c(final = true) ⇒ Object



1469
1470
1471
1472
1473
1474
1475
1476
# File 'lib/BOAST/Algorithm.rb', line 1469

def close_c(final=true)
  s = ""
  BOAST::decrement_indent_level      
  s += " "*BOAST::get_indent_level if final
  s += "}"
  BOAST::get_output.puts s if final
  return s
end

#close_fortran(final = true) ⇒ Object



1477
1478
1479
1480
1481
1482
1483
1484
# File 'lib/BOAST/Algorithm.rb', line 1477

def close_fortran(final=true)
  s = ""
  BOAST::decrement_indent_level      
  s += " "*BOAST::get_indent_level if final
  s += "end if"
  BOAST::get_output.puts s if final
  return s
end


1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
# File 'lib/BOAST/Algorithm.rb', line 1451

def print(*args)
  final = true
  s=""
  s += " "*BOAST::get_indent_level if final
  s += self.to_str
  BOAST::increment_indent_level      
  BOAST::get_output.puts s if final
  if @block then
    s += "\n"
    @block.call(*args)
    s += self.close
  end
  return s
end

#to_sObject



1426
1427
1428
# File 'lib/BOAST/Algorithm.rb', line 1426

def to_s
  self.to_str
end

#to_strObject



1429
1430
1431
1432
# File 'lib/BOAST/Algorithm.rb', line 1429

def to_str
  return self.to_str_fortran if BOAST::get_lang == FORTRAN
  return self.to_str_c if [C, CL, CUDA].include?( BOAST::get_lang )
end

#to_str_cObject



1442
1443
1444
1445
1446
1447
1448
1449
1450
# File 'lib/BOAST/Algorithm.rb', line 1442

def to_str_c
  s = ""
  if @condition then
    s += "else if(#{@condition}){"
  else
    s += "else {"
  end
  return s
end

#to_str_fortranObject



1433
1434
1435
1436
1437
1438
1439
1440
1441
# File 'lib/BOAST/Algorithm.rb', line 1433

def to_str_fortran
  s = ""
  if @condition then
    s += "else if #{@condition} then"
  else
    s += "else"
  end
  return s
end