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.
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 |
# File 'lib/BOAST/Algorithm.rb', line 1335 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.
1333 1334 1335 |
# File 'lib/BOAST/Algorithm.rb', line 1333 def constants_list @constants_list end |
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
1332 1333 1334 |
# File 'lib/BOAST/Algorithm.rb', line 1332 def expression @expression end |
Class Method Details
.parens(*args, &block) ⇒ Object
1328 1329 1330 |
# File 'lib/BOAST/Algorithm.rb', line 1328 def self.parens(*args,&block) return self::new(*args,&block) end |
Instance Method Details
#close(final = true) ⇒ Object
1413 1414 1415 1416 |
# File 'lib/BOAST/Algorithm.rb', line 1413 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
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 |
# File 'lib/BOAST/Algorithm.rb', line 1417 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
1428 1429 1430 1431 1432 1433 1434 1435 1436 |
# File 'lib/BOAST/Algorithm.rb', line 1428 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
1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 |
# File 'lib/BOAST/Algorithm.rb', line 1402 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
1355 1356 1357 |
# File 'lib/BOAST/Algorithm.rb', line 1355 def to_s(*args) self.to_str(*args) end |
#to_str(constants, first = true) ⇒ Object
1359 1360 1361 1362 |
# File 'lib/BOAST/Algorithm.rb', line 1359 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
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 |
# File 'lib/BOAST/Algorithm.rb', line 1382 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
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 |
# File 'lib/BOAST/Algorithm.rb', line 1364 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 |