Class: OroGen::Gen::RTT_CPP::TaskContextGeneration::GeneratedObject

Inherits:
Object
  • Object
show all
Defined in:
lib/orogen/gen/tasks.rb

Overview

Base class for code generation in tasks

Direct Known Subclasses

GeneratedMember, GeneratedMethod

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ GeneratedObject


745
746
747
748
# File 'lib/orogen/gen/tasks.rb', line 745

def initialize(task)
    @task = task
    @doc = nil
end

Instance Attribute Details

#taskObject (readonly)

Returns the value of attribute task


697
698
699
# File 'lib/orogen/gen/tasks.rb', line 697

def task
  @task
end

Class Method Details

.code_snippet(name, with_generation = true) ⇒ Object


699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
# File 'lib/orogen/gen/tasks.rb', line 699

def self.code_snippet(name, with_generation = true)
    class_eval "def \#{name}(code = nil, &block)\nif !code && !block\nreturn @\#{name}\nend\ncode = TaskContextGeneration.validate_code_object(code, block)\[email protected]\#{name} = code\nself\nend\ndef add_to_\#{name}_before(code, &block)\nif [email protected]\#{name}\n\#{name}(code,&block)\nelse\ncode = TaskContextGeneration.validate_code_object(code, block)\nold_code = @\#{name}\[email protected]\#{name} = lambda { |*args| code.call(*args) + old_code.call(*args) }\nend\nself\nend\ndef add_to_\#{name}_after(code, &block)\nif [email protected]\#{name}\n\#{name}(code,&block)\nelse\ncode = TaskContextGeneration.validate_code_object(code, block)\nold_code = @\#{name}\[email protected]\#{name} = lambda { |*args| old_code.call(*args) + code.call(*args) }\nend\nself\nend\n"
    
    if with_generation
        class_eval "def generate_\#{name}\nif @\#{name}\nif result = @\#{name}.call\nresult\nelse \"\"\nend\nend\nend\n"
    end
end

Instance Method Details

#doc(*lines) ⇒ Object


750
751
752
753
754
755
756
757
758
759
760
761
762
# File 'lib/orogen/gen/tasks.rb', line 750

def doc(*lines)
    if lines.empty?
        return @doc
    end

    comment = lines.join("\n * ") + "\n"
    if !@doc
        @doc = "/* #{comment}"
    else
        @doc = " * #{comment}"
    end
    self
end

#with_indent(number, method) ⇒ Object


764
765
766
767
768
769
770
# File 'lib/orogen/gen/tasks.rb', line 764

def with_indent(number, method)
    text = send("generate_#{method}")
    if text
        indent = " " * number
        indent + text.split("\n").join("\n#{indent}")
    end
end