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.
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 |
# File 'lib/BOAST/Algorithm.rb', line 1461 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.
1460 1461 1462 |
# File 'lib/BOAST/Algorithm.rb', line 1460 def conditions @conditions end |
Class Method Details
.parens(*args, &block) ⇒ Object
1456 1457 1458 |
# File 'lib/BOAST/Algorithm.rb', line 1456 def self.parens(*args,&block) return self::new(*args,&block) end |
Instance Method Details
#close(final = true) ⇒ Object
1538 1539 1540 1541 |
# File 'lib/BOAST/Algorithm.rb', line 1538 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
1542 1543 1544 1545 1546 1547 1548 1549 |
# File 'lib/BOAST/Algorithm.rb', line 1542 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
1550 1551 1552 1553 1554 1555 1556 1557 |
# File 'lib/BOAST/Algorithm.rb', line 1550 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
1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 |
# File 'lib/BOAST/Algorithm.rb', line 1515 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
1482 1483 1484 |
# File 'lib/BOAST/Algorithm.rb', line 1482 def to_s(*args) self.to_str(*args) end |
#to_str(condition, first = true) ⇒ Object
1485 1486 1487 1488 |
# File 'lib/BOAST/Algorithm.rb', line 1485 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
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 |
# File 'lib/BOAST/Algorithm.rb', line 1502 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
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 |
# File 'lib/BOAST/Algorithm.rb', line 1489 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 |