Class: BOAST::If
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
Class Method Summary collapse
Instance Method Summary collapse
- #close(final = true) ⇒ Object
- #close_c(final = true) ⇒ Object
- #close_fortran(final = true) ⇒ Object
-
#initialize(*conditions, &block) ⇒ If
constructor
A new instance of If.
- #print(*args) ⇒ Object
- #to_s(*args) ⇒ Object
- #to_str(condition, first = true) ⇒ Object
- #to_str_c(condition, first) ⇒ Object
- #to_str_fortran(condition, first) ⇒ Object
Constructor Details
#initialize(*conditions, &block) ⇒ If
Returns a new instance of If.
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 |
# File 'lib/BOAST/Algorithm.rb', line 1452 def initialize(*conditions, &block) @conditions = [] @blocks = [] if conditions.size == 0 then raise "Illegal if construct!" elsif conditions.size == 1 then @conditions.push(conditions[0]) @blocks.push(block) elsif conditions.size.even? then (0..conditions.size-1).step(2) { |i| @conditions[i/2] = conditions[i] @blocks[i/2] = conditions[i+1] } else (0..conditions.size-2).step(2) { |i| @conditions[i/2] = conditions[i] @blocks[i/2] = conditions[i+1] } @blocks.push(conditions.last) end end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
1451 1452 1453 |
# File 'lib/BOAST/Algorithm.rb', line 1451 def conditions @conditions end |
Class Method Details
.parens(*args, &block) ⇒ Object
1447 1448 1449 |
# File 'lib/BOAST/Algorithm.rb', line 1447 def self.parens(*args,&block) return self::new(*args,&block) end |
Instance Method Details
#close(final = true) ⇒ Object
1529 1530 1531 1532 |
# File 'lib/BOAST/Algorithm.rb', line 1529 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
1533 1534 1535 1536 1537 1538 1539 1540 |
# File 'lib/BOAST/Algorithm.rb', line 1533 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
1541 1542 1543 1544 1545 1546 1547 1548 |
# File 'lib/BOAST/Algorithm.rb', line 1541 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 |
#print(*args) ⇒ Object
1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 |
# File 'lib/BOAST/Algorithm.rb', line 1506 def print(*args) s="" s += " "*BOAST::get_indent_level s += self.to_str(@conditions.first) BOAST::increment_indent_level BOAST::get_output.puts s if @blocks.size > 0 then if @blocks[0] then @blocks[0].call(*args) end @blocks[1..-1].each_index { |indx| BOAST::decrement_indent_level s="" s += " "*BOAST::get_indent_level s += self.to_str(@conditions[1..-1][indx],false) BOAST::increment_indent_level BOAST::get_output.puts s @blocks[1..-1][indx].call(*args) } self.close end return self end |
#to_s(*args) ⇒ Object
1473 1474 1475 |
# File 'lib/BOAST/Algorithm.rb', line 1473 def to_s(*args) self.to_str(*args) end |
#to_str(condition, first = true) ⇒ Object
1476 1477 1478 1479 |
# File 'lib/BOAST/Algorithm.rb', line 1476 def to_str(condition, first= true) return self.to_str_fortran(condition, first) if BOAST::get_lang == FORTRAN return self.to_str_c(condition, first) if [C, CL, CUDA].include?( BOAST::get_lang ) end |
#to_str_c(condition, first) ⇒ Object
1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 |
# File 'lib/BOAST/Algorithm.rb', line 1493 def to_str_c(condition, first) s = "" if first then s += "if(#{condition}){" else if condition then s += "} else if(#{condition}){" else s += "} else {" end end return s end |
#to_str_fortran(condition, first) ⇒ Object
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 |
# File 'lib/BOAST/Algorithm.rb', line 1480 def to_str_fortran(condition, first) s = "" if first then s += "if #{condition} then" else if condition then s += "else if #{condition} then" else s += "else" end end return s end |