Class: OroGen::Gen::RTT_CPP::TaskContextGeneration::GeneratedObject
- Inherits:
-
Object
- Object
- OroGen::Gen::RTT_CPP::TaskContextGeneration::GeneratedObject
- Defined in:
- lib/orogen/gen/tasks.rb
Overview
Base class for code generation in tasks
Direct Known Subclasses
Instance Attribute Summary collapse
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Class Method Summary collapse
Instance Method Summary collapse
- #doc(*lines) ⇒ Object
-
#initialize(task) ⇒ GeneratedObject
constructor
A new instance of GeneratedObject.
- #with_indent(number, method) ⇒ Object
Constructor Details
#initialize(task) ⇒ GeneratedObject
Returns a new instance of GeneratedObject
745 746 747 748 |
# File 'lib/orogen/gen/tasks.rb', line 745 def initialize(task) @task = task @doc = nil end |
Instance Attribute Details
#task ⇒ Object (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 <<-EOD def #{name}(code = nil, &block) if !code && !block return @#{name} end code = TaskContextGeneration.validate_code_object(code, block) @#{name} = code self end def add_to_#{name}_before(code, &block) if !@#{name} #{name}(code,&block) else code = TaskContextGeneration.validate_code_object(code, block) old_code = @#{name} @#{name} = lambda { |*args| code.call(*args) + old_code.call(*args) } end self end def add_to_#{name}_after(code, &block) if !@#{name} #{name}(code,&block) else code = TaskContextGeneration.validate_code_object(code, block) old_code = @#{name} @#{name} = lambda { |*args| old_code.call(*args) + code.call(*args) } end self end EOD if with_generation class_eval <<-EOD def generate_#{name} if @#{name} if result = @#{name}.call result else "" end end end EOD 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 |