module EasySwig::Util

Public Instance Methods

del_prefix_class(n) click to toggle source
# File lib/util/utilities.rb, line 38
def del_prefix_class(n) # Previuously escaped for const
         n.gsub(%r{^[^<]*[:]}, "")
end
escape_all(typename) click to toggle source
# File lib/util/utilities.rb, line 30
def escape_all(typename)
    return del_prefix_class(escape_template(escape_const_ref_ptr(typename)))
end
escape_const_ref_ptr(typename) click to toggle source
# File lib/util/utilities.rb, line 34
def escape_const_ref_ptr(typename)
  typename.gsub(/^ *const /,'').gsub(/ +(const)* *[&*]* *(const)* *$/,'').strip
end
escape_template(typename) click to toggle source
# File lib/util/utilities.rb, line 55
def escape_template(typename)
  typename.gsub(/<.+$/,'').strip
end
gen_dir() click to toggle source
# File lib/util/utilities.rb, line 63
def gen_dir
  File.expand_path(output_dir+"/gen")
end
home_dir() click to toggle source
# File lib/util/utilities.rb, line 22
def home_dir
  File.expand_path(lib_dir+"/..")
end
is_primitive?(typename) click to toggle source
# File lib/util/utilities.rb, line 42
def is_primitive?(typename)
    ['void', 'bool', 'char', 'unsigned char', 
     'short', 'unsigned short', 'int', 'unsigned int',
     'long', 'unsigned long', 'long long', 'unsigned long long int', 
     'unsigned long long', 'float', 'double', 'long double',
     'size_t', 'uint32', 'uint8', 'uint16'].include?(typename)
end
is_std?(typename) click to toggle source
# File lib/util/utilities.rb, line 50
def is_std?(typename) # TODO depends on language. What happens with templates?
    ['vector', 'string', 'pair', 'list', 
     'map', 'deque', 'multimap', 'set'].include?(typename)
end
lib_dir() click to toggle source
# File lib/util/utilities.rb, line 18
def lib_dir
  File.expand_path(File.dirname(__FILE__)+'/..')
end
logs_dir() click to toggle source
# File lib/util/utilities.rb, line 59
def logs_dir
  @output_dir+"/logs"
end
output_dir() click to toggle source
# File lib/util/utilities.rb, line 26
def output_dir
  @output_dir
end
read_file(file_name) click to toggle source
# File lib/util/utilities.rb, line 71
def read_file file_name
  file = File.open(file_name, "r")
  data = file.read
  file.close
  return data
end
rename_files(dir, find, ext='*', &block) click to toggle source
# File lib/util/utilities.rb, line 86
def rename_files (dir, find, ext='*', &block)
  if ext
    Dir.glob(%Q{#{dir}/*.#{ext}}) { |file|
      # do work on files ending in .ext in the desired directory
      name = File.basename(file, "."+ext)
      newname = name.gsub(find) { |match|
        puts match
        a = block.call(match, $1)
        a
      }
      File.rename(file, file.gsub(name, newname))
    }
  end
end
swig_dir() click to toggle source
# File lib/util/utilities.rb, line 67
def swig_dir
  File.expand_path(output_dir+"/swig")
end
write_file(file_name, data) click to toggle source
# File lib/util/utilities.rb, line 78
def write_file file_name, data
    FileUtils::mkdir_p File.dirname(file_name)
  file = File.open(file_name, "w")
  count = file.write(data)
  file.close
  return count
end