Class: DefaultFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/default_files.rb

Overview

class DefaultFiles

A singleton class to generate header and souce files.
TODO: consider using class source_file.rb in Pareater

Class Method Summary collapse

Class Method Details

.create_config(path, compiler = 'clang++', src_sfx = 'cpp', hdr_sfx = 'hpp') ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/default_files.rb', line 13

def create_config(path, compiler = 'clang++', src_sfx = 'cpp', hdr_sfx = 'hpp')
  open_file_and_write(
    "#{path}/config.json",
    "      {\n          \"compiler\": \"\#{compiler}\",\n          \"header-suffix\": \"\#{hdr_sfx}\",\n          \"source-suffix\": \"\#{src_sfx}\",\n          \"flags\": {\n              \"compile\": {\n                  \"opt\": \"-O2\",\n                  \"debug\": \"-g\"\n              },\n              \"link\": {\n\n              }\n          }\n      }\n    CONFIG\n  )\nend\n"

.create_cpp(filename, src_sfx = 'cpp', hdr_sfx = 'hpp') ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/default_files.rb', line 60

def create_cpp(filename, src_sfx = 'cpp', hdr_sfx = 'hpp')
  open_file_and_write(
    "#{filename}.#{src_sfx}",
    "      #include \"\#{filename}.\#{hdr_sfx}\"\n    DOC\n  )\nend\n"

.create_hpp(workspace, prefix, filename, hdr_sfx = 'hpp') ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/default_files.rb', line 69

def create_hpp(workspace, prefix, filename, hdr_sfx = 'hpp')
  open_file_and_write(
    "#{filename}.#{hdr_sfx}",
    "      #ifndef __\#{workspace.upcase}__\#{prefix.upcase}__\#{filename.upcase}__\n      #define __\#{workspace.upcase}__\#{prefix.upcase}__\#{filename.upcase}__\n\n      #endif\n    DOC\n  )\nend\n"

.create_lib_header(path, lib_name, suffix = 'hpp') ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/default_files.rb', line 48

def create_lib_header(path, lib_name, suffix = 'hpp')
  open_file_and_write(
    "#{path}/#{lib_name}.#{suffix}",
    "      #ifndef __\#{lib_name.upcase}__\n      #define __\#{lib_name.upcase}__\n\n      #endif\n    DOC\n  )\nend\n"

.create_main(path, suffix = 'cpp') ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/default_files.rb', line 35

def create_main(path, suffix = 'cpp')
  header = suffix == 'c' ? 'stdio.h' : 'iostream'
  open_file_and_write(
    "#{path}/main.#{suffix}",
    "      #include <\#{header}>\n      int main(int argc, char *argv[]) {\n\n      }\n    DOC\n  )\nend\n"

.open_file_and_write(filename, content) ⇒ Object



7
8
9
10
11
# File 'lib/default_files.rb', line 7

def open_file_and_write(filename, content)
  File.open(filename, 'w') do |f|
    f.write(content)
  end
end