Class: BOAST::While

Inherits:
Object show all
Defined in:
lib/BOAST/Algorithm.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition, &block) ⇒ While

Returns a new instance of While.



1204
1205
1206
1207
# File 'lib/BOAST/Algorithm.rb', line 1204

def initialize(condition, &block)
  @condition = condition
  @block = block
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



1203
1204
1205
# File 'lib/BOAST/Algorithm.rb', line 1203

def condition
  @condition
end

Class Method Details

.parens(*args, &block) ⇒ Object



1199
1200
1201
# File 'lib/BOAST/Algorithm.rb', line 1199

def self.parens(*args,&block)
  return self::new(*args,&block)
end

Instance Method Details

#close(final = true) ⇒ Object



1239
1240
1241
1242
# File 'lib/BOAST/Algorithm.rb', line 1239

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



1243
1244
1245
1246
1247
1248
1249
1250
# File 'lib/BOAST/Algorithm.rb', line 1243

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



1251
1252
1253
1254
1255
1256
1257
1258
# File 'lib/BOAST/Algorithm.rb', line 1251

def close_fortran(final=true)
  s = ""
  BOAST::decrement_indent_level      
  s += " "*BOAST::get_indent_level if final
  s += "end do"
  BOAST::get_output.puts s if final
  return s
end


1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
# File 'lib/BOAST/Algorithm.rb', line 1225

def print(*args)
  final = true
  s=""
  s += " "*BOAST::get_indent_level if final
  s += self.to_str
  BOAST::increment_indent_level      
  BOAST::get_output.puts s if final
  if @block then
    s += "\n"
    @block.call(*args)
    s += self.close
  end
  return s
end

#to_sObject



1208
1209
1210
# File 'lib/BOAST/Algorithm.rb', line 1208

def to_s
  self.to_str
end

#to_strObject



1211
1212
1213
1214
# File 'lib/BOAST/Algorithm.rb', line 1211

def to_str
  return self.to_str_fortran if BOAST::get_lang == FORTRAN
  return self.to_str_c if [C, CL, CUDA].include?( BOAST::get_lang )
end

#to_str_cObject



1220
1221
1222
1223
1224
# File 'lib/BOAST/Algorithm.rb', line 1220

def to_str_c
  s = ""
  s += "while(#{@condition}){"
  return s
end

#to_str_fortranObject



1215
1216
1217
1218
1219
# File 'lib/BOAST/Algorithm.rb', line 1215

def to_str_fortran
  s = ""
  s += "do while( #{@condition} )"
  return s
end