module OroGen::Gen::RTT_CPP

Constants

AUTOMATIC_AREA_NAME
Attribute
ConfigError
ConfigurationObject
DynamicInputPort
DynamicOutputPort
InputPort
OROGEN_LIB_DIR
Operation
OutputPort
Port
Property
TaskContext

Attributes

command_line_options[RW]
default_type_export_policy[R]
generated_files[R]

The set of files generated so far, as a set of absolute paths

generation_directory[RW]
relative_generation_directory[RW]
templates[R]

The set of templates already loaded as a path => ERB object hash

typekit_slice[RW]

Multiple type info objects can be grouped in a single file to reduce the overhead, at compilation time, of reading the preprocessed file

This controls the size of the grouping

typekit_slice_minimum[RW]

Public Class Methods

adapt_namespace(old, new, indent_size = 4) click to toggle source

Returns the C++ code which changes the current namespace from old to new. indent_size is the count of indent spaces between namespaces.

# File lib/orogen/gen/base.rb, line 23
def self.adapt_namespace(old, new, indent_size = 4)
    old = old.split('/').delete_if { |v| v.empty? }
    new = new.split('/').delete_if { |v| v.empty? }
    indent = old.size * indent_size

    result = ""

    while !old.empty? && old.first == new.first
        old.shift
        new.shift
    end
    while !old.empty?
        indent -= indent_size
        result << " " * indent + "}\n"
        old.shift
    end
    while !new.empty?
        result << "#{" " * indent}namespace #{new.first} {\n"
        indent += indent_size
        new.shift
    end

    result
end
base_dir() click to toggle source

Returns the directory where Orogen's lib part sits (i.e. where autobuild.rb and autobuild/ are)

# File lib/orogen/gen/base.rb, line 6
def self.base_dir
    File.expand_path(File.join('..', '..'), File.dirname(__FILE__))
end
clean() click to toggle source
# File lib/orogen/gen/templates.rb, line 187
def self.clean
    FileUtils.rm_rf Generation::AUTOMATIC_AREA_NAME
    FileUtils.rm_rf "build"
    FileUtils.rm_rf "templates"
end
cleanup_dir(*path) click to toggle source

Removes from the given path all files that have not been generated

# File lib/orogen/gen/templates.rb, line 149
def self.cleanup_dir(*path)
    dir_path = File.expand_path(File.join(*path))

    Find.find(dir_path) do |file|
        if File.directory?(file) && File.directory?(File.join(file, "CMakeFiles"))
            # This looks like a build directory. Ignore
            Find.prune
        
        elsif File.file?(file) && !File.symlink?(file) && !generated_files.include?(file)
            info "   removing #{file}"
            FileUtils.rm_f file
        end
    end
end
cmake_pkgconfig_require(depspec, context = 'core') click to toggle source
# File lib/orogen/gen/base.rb, line 82
def self.cmake_pkgconfig_require(depspec, context = 'core')
    depspec.inject([]) do |result, s|
        result << "orogen_pkg_check_modules(#{s.var_name} REQUIRED #{s.pkg_name})"
        if s.in_context?(context, 'include')
            result << "include_directories(${#{s.var_name}_INCLUDE_DIRS})"
            result << "add_definitions(${#{s.var_name}_CFLAGS_OTHER})"
        end
        if s.in_context?(context, 'link')
            result << "link_directories(${#{s.var_name}_LIBRARY_DIRS})"
        end
        result
    end.join("\n") + "\n"
end
default_deployment_name(task_model_name) click to toggle source
# File lib/orogen/gen/project.rb, line 17
def self.default_deployment_name(task_model_name)
    "orogen_default_#{task_model_name.gsub(/[^\w]/, '_')}"
end
default_type_export_policy=(value) click to toggle source
# File lib/orogen/gen/project.rb, line 23
def default_type_export_policy=(value)
    if ![:all, :used].include?(value)
        raise ArgumentError, "the default type export policy must be either 'all' or 'used', got '#{value}'"
    end
    @default_type_export_policy = value
end
define_default_deployments=(value) click to toggle source
# File lib/orogen/gen/project.rb, line 13
def self.define_default_deployments=(value);  @define_default_deployments = value end
define_default_deployments_enabled?() click to toggle source
# File lib/orogen/gen/project.rb, line 14
def self.define_default_deployments_enabled?; @define_default_deployments end
enable() click to toggle source
# File lib/orogen/gen/enable.rb, line 4
def self.enable
    Attribute.include AttributeGeneration
    Property.include PropertyGeneration
    Operation.include OperationGeneration
    Port.include PortGeneration
    OutputPort.include OutputPortGeneration
    InputPort.include InputPortGeneration
    TaskContext.include TaskContextGeneration
end
extended_states=(value) click to toggle source
# File lib/orogen/gen/project.rb, line 9
def self.extended_states=(value);  @extended_states = value end
extended_states_enabled?() click to toggle source
# File lib/orogen/gen/project.rb, line 10
def self.extended_states_enabled?; @extended_states end
load_template path1, path2, ..., file_name → erb object click to toggle source

Loads the template file located at template_dir/path1/path2/…/file_name and return the ERB object generated from it. template_dir is the templates/ directory located in Orocos.rb sources.

A template is only loaded once. See Generation.templates.

# File lib/orogen/gen/templates.rb, line 44
def self.load_template(*path)
    if template = templates[path]
        template
    else
        template_file   = template_path(*path)

        templates[path] = begin
                              ERB.new(File.read(template_file), nil, "<>", path.join('_').downcase.gsub(/[\/\.-]/, '_'))
                          rescue Errno::ENOENT
                              raise ArgumentError, "template #{File.join(*path)} does not exist"
                          end
        templates[path].filename = template_file
        templates[path]
    end
end
multiline_string_to_cxx(str) click to toggle source
# File lib/orogen/gen/tasks.rb, line 4
def self.multiline_string_to_cxx(str)
    if str
        "\"#{str.split("\n").join("\\n").gsub('"', '\\"')}\""
    else "\"\""
    end
end
orocos_target() click to toggle source
# File lib/orogen/gen/project.rb, line 57
def self.orocos_target
    user_target = ENV['OROCOS_TARGET']
    if @orocos_target
        @orocos_target.dup
    elsif user_target && !user_target.empty?
        user_target
    else
        'gnulinux'
    end
end
orocos_target=(target) click to toggle source
# File lib/orogen/gen/project.rb, line 52
def self.orocos_target=(target)
    @orocos_target = target.to_s
end
really_clean() click to toggle source
# File lib/orogen/gen/templates.rb, line 164
def self.really_clean
    # List all files in templates and compare them w.r.t.  the ones in
    # the user-side of the project. Remove those that are identical
    base_dir     = Pathname.new('.')
    template_dir = Pathname.new('templates')
    template_dir.find do |path|
        next unless path.file?
        template_data = File.read(path.to_s)
        relative = path.relative_path_from(template_dir)

        if relative.file?
            user_data = File.read(relative.to_s)
            if user_data == template_data
                logger.info "removing #{relative} as it is the same than in template"
                FileUtils.rm_f relative.to_s
            end
        end
    end
    
    # Call #clean afterwards, since #clean removes the templates/ directory
    clean
end
render_template path1, path2, file_name, binding click to toggle source

Render the template found at path1/path2/file_name and render it using the provided binding

# File lib/orogen/gen/templates.rb, line 65
def self.render_template(*args)
    binding = args.pop
    template = load_template(*args)
    debug "rendering #{File.join(*args)}"
    template.result(binding)
rescue Exception => e
    raise e, "while rendering #{File.join(*args)}: #{e.message}", e.backtrace
end
save_automatic path1, path2, ..., file_name, data click to toggle source

Save the provided data in the path1/path2/…/file_name file of the automatically-generated part of the project (i.e. under .orogen)

# File lib/orogen/gen/templates.rb, line 118
def self.save_automatic(*args)
    save_generated true, AUTOMATIC_AREA_NAME, *args
end
save_public_automatic path1, path2, ..., file_name, data click to toggle source

Save the provided data in the path1/path2/file_name file of the user-written part of the project. It differs from ::save_user because it will happily overwrite an existing file.

# File lib/orogen/gen/templates.rb, line 128
def self.save_public_automatic(*args)
    save_generated true, *args
end
save_user path1, path2, ..., file_name, data click to toggle source

Save the provided data in the path1/path2/file_name file of the user-written part of the project, if the said file does not exist yet

# File lib/orogen/gen/templates.rb, line 138
def self.save_user(*args)
    result = save_generated false, *args

    # Save the template in path1/path2/.../orogen/file_name
    args = args.dup
    args.unshift "templates"
    save_generated true, *args
    result
end
template_path(path1, path2, ..., file_name) click to toggle source

Returns the full path for the template path1/path2/…/file_name. Templates names are the path relative to the template base directory, which is the orocos/templates directory directly in orogen sources.

Alternative, if an absolute path it passed, it will be directly returned

# File lib/orogen/gen/templates.rb, line 26
def self.template_path(*path)
    if Pathname.new(File.join(*path)).absolute?
        File.join(*path)
    else
        reldir = File.join('orogen', 'templates', *path)
        File.expand_path(reldir, base_dir)
    end
end
touch path1, path2, ..., file_name click to toggle source

Creates an empty file path1/path2/…/file_name

# File lib/orogen/gen/base.rb, line 14
def self.touch(*args)
    path = File.expand_path(File.join(*args))
    FileUtils.touch path
    generated_files << path
end