Module: EasySwig::Util
- Included in:
- ApiNode, GenerateTask, Generator, GeneratorUtil
- Defined in:
- lib/util/utilities.rb
Instance Method Summary collapse
-
#del_prefix_class(n) ⇒ Object
Previuously escaped for const.
- #escape_all(typename) ⇒ Object
- #escape_const_ref_ptr(typename) ⇒ Object
- #escape_template(typename) ⇒ Object
- #gen_dir ⇒ Object
- #home_dir ⇒ Object
- #is_primitive?(typename) ⇒ Boolean
-
#is_std?(typename) ⇒ Boolean
TODO depends on language.
- #lib_dir ⇒ Object
- #logs_dir ⇒ Object
- #output_dir ⇒ Object
- #read_file(file_name) ⇒ Object
- #rename_files(dir, find, ext = '*', &block) ⇒ Object
- #swig_dir ⇒ Object
- #write_file(file_name, data) ⇒ Object
Instance Method Details
#del_prefix_class(n) ⇒ Object
Previuously escaped for const
38 39 40 |
# File 'lib/util/utilities.rb', line 38 def del_prefix_class(n) # Previuously escaped for const n.gsub(%r{^[^<]*[:]}, "") end |
#escape_all(typename) ⇒ Object
30 31 32 |
# 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) ⇒ Object
34 35 36 |
# File 'lib/util/utilities.rb', line 34 def escape_const_ref_ptr(typename) typename.gsub(/^ *const /,'').gsub(/ +(const)* *[&*]* *(const)* *$/,'').strip end |
#escape_template(typename) ⇒ Object
55 56 57 |
# File 'lib/util/utilities.rb', line 55 def escape_template(typename) typename.gsub(/<.+$/,'').strip end |
#gen_dir ⇒ Object
63 64 65 |
# File 'lib/util/utilities.rb', line 63 def gen_dir File.(output_dir+"/gen") end |
#home_dir ⇒ Object
22 23 24 |
# File 'lib/util/utilities.rb', line 22 def home_dir File.(lib_dir+"/..") end |
#is_primitive?(typename) ⇒ Boolean
42 43 44 45 46 47 48 |
# 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) ⇒ Boolean
TODO depends on language. What happens with templates?
50 51 52 53 |
# 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 ⇒ Object
18 19 20 |
# File 'lib/util/utilities.rb', line 18 def lib_dir File.(File.dirname(__FILE__)+'/..') end |
#logs_dir ⇒ Object
59 60 61 |
# File 'lib/util/utilities.rb', line 59 def logs_dir @output_dir+"/logs" end |
#output_dir ⇒ Object
26 27 28 |
# File 'lib/util/utilities.rb', line 26 def output_dir @output_dir end |
#read_file(file_name) ⇒ Object
71 72 73 74 75 76 |
# 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) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# 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 ⇒ Object
67 68 69 |
# File 'lib/util/utilities.rb', line 67 def swig_dir File.(output_dir+"/swig") end |
#write_file(file_name, data) ⇒ Object
78 79 80 81 82 83 84 |
# 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 |