Class: BOAST::CStruct
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#members_array ⇒ Object
readonly
Returns the value of attribute members_array.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #decl ⇒ Object
- #finalize ⇒ Object
- #header ⇒ Object
- #header_c(final = true) ⇒ Object
- #header_fortran(final = true) ⇒ Object
- #indent ⇒ Object
-
#initialize(hash = {}) ⇒ CStruct
constructor
A new instance of CStruct.
Constructor Details
#initialize(hash = {}) ⇒ CStruct
Returns a new instance of CStruct.
476 477 478 479 480 481 482 483 484 485 |
# File 'lib/BOAST/Algorithm.rb', line 476 def initialize(hash={}) @name = hash[:type_name] @members = {} @members_array = [] hash[:members].each { |m| mc = m.copy @members_array.push(mc) @members[mc.name] = mc } end |
Instance Attribute Details
#members ⇒ Object (readonly)
Returns the value of attribute members.
471 472 473 |
# File 'lib/BOAST/Algorithm.rb', line 471 def members @members end |
#members_array ⇒ Object (readonly)
Returns the value of attribute members_array.
471 472 473 |
# File 'lib/BOAST/Algorithm.rb', line 471 def members_array @members_array end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
471 472 473 |
# File 'lib/BOAST/Algorithm.rb', line 471 def name @name end |
Class Method Details
Instance Method Details
#decl ⇒ Object
487 488 489 490 |
# File 'lib/BOAST/Algorithm.rb', line 487 def decl return "struct #{@name}" if [C, CL, CUDA].include?( BOAST::get_lang ) return "TYPE(#{@name})" if BOAST::get_lang == FORTRAN end |
#finalize ⇒ Object
492 493 494 495 496 497 |
# File 'lib/BOAST/Algorithm.rb', line 492 def finalize s = "" s += ";" if [C, CL, CUDA].include?( BOAST::get_lang ) s+="\n" return s end |
#header ⇒ Object
503 504 505 506 507 |
# File 'lib/BOAST/Algorithm.rb', line 503 def header return header_c if [C, CL, CUDA].include?( BOAST::get_lang ) return header_fortran if BOAST::get_lang == FORTRAN raise "Unsupported language!" end |
#header_c(final = true) ⇒ Object
509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/BOAST/Algorithm.rb', line 509 def header_c(final = true) s = "" s += self.indent if final s += self.decl + " {\n" @members_array.each { |value| s+= self.indent if final s+= " "*BOAST::get_indent_increment + value.decl(false)+";\n" } s += self.indent if final s += "}" s += self.finalize if final BOAST::get_output.print s if final return s end |
#header_fortran(final = true) ⇒ Object
524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/BOAST/Algorithm.rb', line 524 def header_fortran(final = true) s = "" s += self.indent if final s += "TYPE :: #{@name}\n" members_array.each { |value| s+= self.indent if final s+= " "*BOAST::get_indent_increment + value.decl(false)+"\n" } s += self.indent if final s += "END TYPE #{@name}" s += self.finalize if final BOAST::get_output.print s if final return s end |
#indent ⇒ Object
499 500 501 |
# File 'lib/BOAST/Algorithm.rb', line 499 def indent return " "*BOAST::get_indent_level end |