Class: RbPlusPlus::Writers::MultipleFilesWriter::FileWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/rbplusplus/writers/multiple_files_writer.rb

Overview

For every file to write out, we build an instance of a FileWriter here. This class needs to be given all the nodes it will be writing out to a file

To handle parents calling register_#name() on their children, it's up to the children writers to inform the parents of their existence

Direct Known Subclasses

RbppCustomFileWriter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, parent) ⇒ FileWriter

Returns a new instance of FileWriter.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/rbplusplus/writers/multiple_files_writer.rb', line 127

def initialize(node, parent)
  @node = node
  @base_name = node.qualified_name.as_variable

  @register_method = nil
  @register_methods = []
  @register_includes = []


  @header = parent ? "_#{@base_name}.rb.hpp" : nil
  @source = parent ? "_#{@base_name}.rb.cpp" : "#{@base_name}.rb.cpp"
  @parent = parent

  @require_custom = false

  @needs_closing = true

  register_with_parent if @parent

  @nodes = [@node]
end

Instance Attribute Details

#base_nameObject (readonly)

Returns the value of attribute base_name.



125
126
127
# File 'lib/rbplusplus/writers/multiple_files_writer.rb', line 125

def base_name
  @base_name
end

#nodeObject (readonly)

Returns the value of attribute node.



125
126
127
# File 'lib/rbplusplus/writers/multiple_files_writer.rb', line 125

def node
  @node
end

Instance Method Details

#<<(node) ⇒ Object

Add a node to this file writer



150
151
152
# File 'lib/rbplusplus/writers/multiple_files_writer.rb', line 150

def <<(node)
  @nodes << node
end

#add_register_method(node_name, header) ⇒ Object



175
176
177
178
# File 'lib/rbplusplus/writers/multiple_files_writer.rb', line 175

def add_register_method(node_name, header)
  @register_includes << "#include \"#{header}\""
  @register_methods << "register_#{node_name}(#{has_rice_variable? ? self.rice_variable : ""});"
end

#has_rice_variable?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/rbplusplus/writers/multiple_files_writer.rb', line 171

def has_rice_variable?
  !@node.rice_variable.nil?
end

#rice_typeObject



163
164
165
# File 'lib/rbplusplus/writers/multiple_files_writer.rb', line 163

def rice_type
  @node.rice_variable_type
end

#rice_variableObject



167
168
169
# File 'lib/rbplusplus/writers/multiple_files_writer.rb', line 167

def rice_variable
  @node.rice_variable
end

#write(build_dir, custom_includes = []) ⇒ Object



154
155
156
157
158
159
160
161
# File 'lib/rbplusplus/writers/multiple_files_writer.rb', line 154

def write(build_dir, custom_includes = [])
  @build_dir = build_dir
  @custom_includes = custom_includes.flatten

  build_source
  write_header if @header
  write_source
end