Class: BOAST::Case
Instance Attribute Summary collapse
-
#constants_list ⇒ Object
readonly
Returns the value of attribute constants_list.
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
Class Method Summary collapse
Instance Method Summary collapse
- #close(final = true) ⇒ Object
- #close_c(final = true) ⇒ Object
- #close_fortran(final = true) ⇒ Object
-
#initialize(expression, *control) ⇒ Case
constructor
A new instance of Case.
- #print(*args) ⇒ Object
- #to_s(*args) ⇒ Object
- #to_str(constants, first = true) ⇒ Object
- #to_str_c(constants, first) ⇒ Object
- #to_str_fortran(constants, first) ⇒ Object
Constructor Details
#initialize(expression, *control) ⇒ Case
Returns a new instance of Case.
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 |
# File 'lib/BOAST/Algorithm.rb', line 1496 def initialize(expression, *control) @expression = expression @constants_list = [] @blocks = [] if control.size < 1 then raise "No block given!" elsif control.size.even? then (0..control.size-1).step(2) { |i| @constants_list[i/2] = [control[i]].flatten @blocks[i/2] = control[i+1] } else (0..control.size-2).step(2) { |i| @constants_list[i/2] = [control[i]].flatten @blocks[i/2] = control[i+1] } @blocks.push(control.last) end end |
Instance Attribute Details
#constants_list ⇒ Object (readonly)
Returns the value of attribute constants_list.
1494 1495 1496 |
# File 'lib/BOAST/Algorithm.rb', line 1494 def constants_list @constants_list end |
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
1493 1494 1495 |
# File 'lib/BOAST/Algorithm.rb', line 1493 def expression @expression end |
Class Method Details
.parens(*args, &block) ⇒ Object
1489 1490 1491 |
# File 'lib/BOAST/Algorithm.rb', line 1489 def self.parens(*args,&block) return self::new(*args,&block) end |
Instance Method Details
#close(final = true) ⇒ Object
1574 1575 1576 1577 |
# File 'lib/BOAST/Algorithm.rb', line 1574 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
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 |
# File 'lib/BOAST/Algorithm.rb', line 1578 def close_c(final=true) s = "" s += " "*BOAST::get_indent_level if final s += "break;\n" BOAST::decrement_indent_level s += " "*BOAST::get_indent_level if final s += "}" BOAST::decrement_indent_level BOAST::get_output.puts s if final return s end |
#close_fortran(final = true) ⇒ Object
1589 1590 1591 1592 1593 1594 1595 1596 1597 |
# File 'lib/BOAST/Algorithm.rb', line 1589 def close_fortran(final=true) s = "" BOAST::decrement_indent_level s += " "*BOAST::get_indent_level if final s += "end select" BOAST::decrement_indent_level BOAST::get_output.puts s if final return s end |
#print(*args) ⇒ Object
1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 |
# File 'lib/BOAST/Algorithm.rb', line 1563 def print(*args) first = true @blocks.each_index { |indx| s = self.to_str(@constants_list[indx],first) BOAST::get_output.puts s @blocks[indx].call(*args) first = false } self.close return self end |
#to_s(*args) ⇒ Object
1516 1517 1518 |
# File 'lib/BOAST/Algorithm.rb', line 1516 def to_s(*args) self.to_str(*args) end |
#to_str(constants, first = true) ⇒ Object
1520 1521 1522 1523 |
# File 'lib/BOAST/Algorithm.rb', line 1520 def to_str(constants, first= true) return self.to_str_fortran(constants, first) if BOAST::get_lang == FORTRAN return self.to_str_c(constants, first) if [C, CL, CUDA].include?( BOAST::get_lang ) end |
#to_str_c(constants, first) ⇒ Object
1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 |
# File 'lib/BOAST/Algorithm.rb', line 1543 def to_str_c(constants, first) s = "" if first then s += " "*BOAST::get_indent_level s += "switch(#{@expression}){\n" BOAST::increment_indent_level else s += " "*BOAST::get_indent_level + "break;\n" BOAST::decrement_indent_level end s += " "*BOAST::get_indent_level if constants and constants.size>0 then s += "case #{constants.join(" : case")} :" else s += "default :" end BOAST::increment_indent_level return s end |
#to_str_fortran(constants, first) ⇒ Object
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 |
# File 'lib/BOAST/Algorithm.rb', line 1525 def to_str_fortran(constants, first) s = "" if first then s += "select case #{@expression}\n" BOAST::increment_indent_level else BOAST::decrement_indent_level end s += " "*BOAST::get_indent_level if constants and constants.size>0 then s += "case #{constants.join(" : ")}" else s += "case default" end BOAST::increment_indent_level return s end |