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.
1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 |
# File 'lib/BOAST/Algorithm.rb', line 1606 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.
1605 1606 1607 |
# File 'lib/BOAST/Algorithm.rb', line 1605 def conditions @conditions end |
Class Method Details
.parens(*args, &block) ⇒ Object
1601 1602 1603 |
# File 'lib/BOAST/Algorithm.rb', line 1601 def self.parens(*args,&block) return self::new(*args,&block) end |
Instance Method Details
#close(final = true) ⇒ Object
1683 1684 1685 1686 |
# File 'lib/BOAST/Algorithm.rb', line 1683 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
1687 1688 1689 1690 1691 1692 1693 1694 |
# File 'lib/BOAST/Algorithm.rb', line 1687 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
1695 1696 1697 1698 1699 1700 1701 1702 |
# File 'lib/BOAST/Algorithm.rb', line 1695 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
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 |
# File 'lib/BOAST/Algorithm.rb', line 1660 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
1627 1628 1629 |
# File 'lib/BOAST/Algorithm.rb', line 1627 def to_s(*args) self.to_str(*args) end |
#to_str(condition, first = true) ⇒ Object
1630 1631 1632 1633 |
# File 'lib/BOAST/Algorithm.rb', line 1630 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
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 |
# File 'lib/BOAST/Algorithm.rb', line 1647 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
1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 |
# File 'lib/BOAST/Algorithm.rb', line 1634 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 |