Class: Comet::HeaderGenerator
- Inherits:
-
Object
- Object
- Comet::HeaderGenerator
- Defined in:
- lib/comet-html/header-generator.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #bound_attributes_definition ⇒ Object
- #friends_def ⇒ Object
- #generate ⇒ Object
- #generate_anchors ⇒ Object
- #generate_getters_setters ⇒ Object
- #generate_properties ⇒ Object
- #indent ⇒ Object
-
#initialize(object) ⇒ HeaderGenerator
constructor
A new instance of HeaderGenerator.
- #signaler_definition ⇒ Object
Constructor Details
#initialize(object) ⇒ HeaderGenerator
Returns a new instance of HeaderGenerator.
5 6 7 |
# File 'lib/comet-html/header-generator.rb', line 5 def initialize object @object = object end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
3 4 5 |
# File 'lib/comet-html/header-generator.rb', line 3 def object @object end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
3 4 5 |
# File 'lib/comet-html/header-generator.rb', line 3 def source @source end |
Instance Method Details
#bound_attributes_definition ⇒ Object
21 22 23 24 |
# File 'lib/comet-html/header-generator.rb', line 21 def bound_attributes_definition return "" if object.implements_ibindable_view? "Comet::BoundAttributes bound_attributes;" end |
#friends_def ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/comet-html/header-generator.rb', line 61 def friends_def result = "" object.context.classes.each do |klass| result += indent + "friend class #{klass.typename};\n" unless klass == object end result end |
#generate ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/comet-html/header-generator.rb', line 114 def generate anchors_def = generate_anchors public_properties_def, protected_properties_def, private_properties_def = generate_properties <<HEADER class #{object.typename} : public #{object.superclass} { #{friends_def} protected: #{bound_attributes_definition} #{protected_properties_def} private: #{anchors_def} #{private_properties_def} public: #{signaler_definition} #{public_properties_def} #{object.constructor_decl} virtual ~#{object.typename}() {} void bind_attributes(); void trigger_binding_updates(); #{generate_getters_setters} #{object.inline_code} }; HEADER end |
#generate_anchors ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/comet-html/header-generator.rb', line 48 def generate_anchors result = "" anchor_count = 0 object.collect_children.each do |child| if child.is_anchorable? anchor_count += 1 child.anchor_name = "anchor_#{anchor_count}" result += indent + "Comet::CommentElement #{child.anchor_name};\n" end end result end |
#generate_getters_setters ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/comet-html/header-generator.rb', line 26 def generate_getters_setters result = "" object.refs.each do |ref| is_ptr = ref.type.end_with? '*' if ref.has_getter? if is_ptr result += indent + "#{ref.type} get_#{ref.name}() const { return #{ref.name}; }\n" else result += indent + "const #{ref.type}& get_#{ref.name}() const { return #{ref.name}; }\n" end end if ref.has_setter? if is_ptr result += indent + "virtual void set_#{ref.name}(#{ref.type} __v) { #{ref.name} = __v; }\n" else result += indent + "virtual void set_#{ref.name}(const #{ref.type}& __v) { #{ref.name} = __v; }\n" end end end result end |
#generate_properties ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/comet-html/header-generator.rb', line 69 def generate_properties protected_properties_def = "" public_properties_def = "" private_properties_def = "" if object.is_root? protected_properties_def += indent + "#{object.typename}* root;\n" else public_properties_def += indent + "#{object.parent.typename}* parent;\n" protected_properties_def += indent + "#{object.root.typename}* root;\n" end object.refs.each do |ref| suffix = " = #{ref.default_value}" if ref.has_default_value? if ref.is_explicit? protected_properties_def += indent + "#{ref.type} #{ref.name}#{suffix};\n" elsif ref.is_implicit? private_properties_def += indent + "#{ref.type} #{ref.name}#{suffix};\n" end end ## BEGIN Repeaters object.repeaters.each do |repeater| protected_properties_def += indent + "Comet::Repeater<#{repeater.list_type}, #{repeater.typename}> #{repeater.repeater_name};\n" end if object.class == Repeater public_properties_def += indent + "#{object.value_type} #{object.value_name};\n" end ## END Repeaters ## BEGIN SLOTS # Slots emanate from the root object. if object.is_root? all_slots = object.slots object.recursively_collect_children.each do |child| all_slots += child.slots end all_slots.each do |slot| public_properties_def += indent + "Comet::SlotElement #{slot.slot_ref};\n" end else object.slots.each do |slot| public_properties_def += indent + "Comet::SlotElement& #{slot.slot_ref};\n" end end ## END SLOTS [public_properties_def, protected_properties_def, private_properties_def] end |
#indent ⇒ Object
9 10 11 |
# File 'lib/comet-html/header-generator.rb', line 9 def indent " " end |
#signaler_definition ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/comet-html/header-generator.rb', line 13 def signaler_definition return "" if object.implements_ibindable_view? # Signaler def. Must be a reference if the object isn't the root object signaler_type = "Comet::Signal<std::string>" signaler_type += "&" unless object.parent.nil? "#{signaler_type} signaler;" end |