Class: BOAST::Else

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 = nil, &block) ⇒ Else

Returns a new instance of Else.



1268
1269
1270
1271
# File 'lib/BOAST/Algorithm.rb', line 1268

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

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



1267
1268
1269
# File 'lib/BOAST/Algorithm.rb', line 1267

def condition
  @condition
end

Class Method Details

.parens(*args, &block) ⇒ Object



1263
1264
1265
# File 'lib/BOAST/Algorithm.rb', line 1263

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

Instance Method Details

#close(final = true) ⇒ Object



1311
1312
1313
1314
# File 'lib/BOAST/Algorithm.rb', line 1311

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



1315
1316
1317
1318
1319
1320
1321
1322
# File 'lib/BOAST/Algorithm.rb', line 1315

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



1323
1324
1325
1326
1327
1328
1329
1330
# File 'lib/BOAST/Algorithm.rb', line 1323

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


1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
# File 'lib/BOAST/Algorithm.rb', line 1297

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



1272
1273
1274
# File 'lib/BOAST/Algorithm.rb', line 1272

def to_s
  self.to_str
end

#to_strObject



1275
1276
1277
1278
# File 'lib/BOAST/Algorithm.rb', line 1275

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



1288
1289
1290
1291
1292
1293
1294
1295
1296
# File 'lib/BOAST/Algorithm.rb', line 1288

def to_str_c
  s = ""
  if @condition then
    s += "else if(#{@condition}){"
  else
    s += "else {"
  end
  return s
end

#to_str_fortranObject



1279
1280
1281
1282
1283
1284
1285
1286
1287
# File 'lib/BOAST/Algorithm.rb', line 1279

def to_str_fortran
  s = ""
  if @condition then
    s += "else if #{@condition} then"
  else
    s += "else"
  end
  return s
end