Class: LazyPP::RenderState

Inherits:
Object show all
Defined in:
lib/readable-cpp/nodes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ RenderState

Returns a new instance of RenderState.



84
85
86
87
88
# File 'lib/readable-cpp/nodes.rb', line 84

def initialize opts={}
  @opts = { 
    indent: 0, parent: [], program: nil, namespace: []
  }.merge(opts.is_a?(RenderState) ? opts.opts : opts)
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



83
84
85
# File 'lib/readable-cpp/nodes.rb', line 83

def opts
  @opts
end

Instance Method Details

#add_parent(p) ⇒ Object



102
103
104
# File 'lib/readable-cpp/nodes.rb', line 102

def add_parent(p) 
  new(parent: parent+[p])
end

#gen_header!Object



93
# File 'lib/readable-cpp/nodes.rb', line 93

def gen_header!() new(gen_header: true) end

#gen_header?Boolean

Returns:

  • (Boolean)


92
# File 'lib/readable-cpp/nodes.rb', line 92

def gen_header?() !!@opts[:gen_header] end

#indent(by = 1) ⇒ Object



106
107
108
109
# File 'lib/readable-cpp/nodes.rb', line 106

def indent(by=1) 
  new(indent: @opts[:indent] + by)
  #RenderState.new(@opts.merge(indent: @opts[:indent]+by))
end

#indentationObject

RenderState.new(@opts.merge(indent: @opts+by))



110
# File 'lib/readable-cpp/nodes.rb', line 110

def indentation() '  '*@opts[:indent]  end

#last_parentObject



101
# File 'lib/readable-cpp/nodes.rb', line 101

def last_parent() parent.last.name.to_cpp RenderState.new end

#new(opts = {}) ⇒ Object



89
90
91
# File 'lib/readable-cpp/nodes.rb', line 89

def new opts={}
  RenderState.new(@opts.merge opts)
end

#no_headerObject



94
# File 'lib/readable-cpp/nodes.rb', line 94

def no_header() new(gen_header: false) end

#parent_namesObject



100
# File 'lib/readable-cpp/nodes.rb', line 100

def parent_names() parent.map{|p|p.name.to_cpp self}.join('::') end

#parentsObject Also known as: parent

def parent=(p)

@opts[:parent]=Array.wrap(p).compact

end



98
# File 'lib/readable-cpp/nodes.rb', line 98

def parents() @opts[:parent] end

#programObject



105
# File 'lib/readable-cpp/nodes.rb', line 105

def program() @opts[:program] end