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.
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 |
# File 'lib/BOAST/Algorithm.rb', line 1427 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.
1425 1426 1427 |
# File 'lib/BOAST/Algorithm.rb', line 1425 def constants_list @constants_list end |
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
1424 1425 1426 |
# File 'lib/BOAST/Algorithm.rb', line 1424 def expression @expression end |
Class Method Details
.parens(*args, &block) ⇒ Object
1420 1421 1422 |
# File 'lib/BOAST/Algorithm.rb', line 1420 def self.parens(*args,&block) return self::new(*args,&block) end |
Instance Method Details
#close(final = true) ⇒ Object
1506 1507 1508 1509 |
# File 'lib/BOAST/Algorithm.rb', line 1506 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
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 |
# File 'lib/BOAST/Algorithm.rb', line 1510 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
1521 1522 1523 1524 1525 1526 1527 1528 1529 |
# File 'lib/BOAST/Algorithm.rb', line 1521 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
1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 |
# File 'lib/BOAST/Algorithm.rb', line 1495 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
1447 1448 1449 |
# File 'lib/BOAST/Algorithm.rb', line 1447 def to_s(*args) self.to_str(*args) end |
#to_str(constants, first = true) ⇒ Object
1451 1452 1453 1454 |
# File 'lib/BOAST/Algorithm.rb', line 1451 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
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 |
# File 'lib/BOAST/Algorithm.rb', line 1475 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
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 |
# File 'lib/BOAST/Algorithm.rb', line 1456 def to_str_fortran(constants, first) s = "" if first then s += " "*BOAST::get_indent_level 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 |