Class: Typelib::ContainerType

Inherits:
Object
  • Object
show all
Defined in:
lib/orogen/gen/typekit.rb,
lib/orogen/marshallers/iostream.rb,
lib/orogen/typenames.rb

Class Method Summary collapse

Class Method Details

.code_copy(typekit, result, indent, dest, src, method, src_type, dest_type) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/orogen/gen/typekit.rb', line 144

def self.code_copy(typekit, result, indent, dest, src, method, src_type, dest_type)
    collection_name, element_type = container_kind, deference.name
    element_type = registry.build(element_type)

    result << "#{indent}#{dest}.clear();\n"
    if (container_kind == "vector")
        result << "#{indent}#{dest}.reserve(#{src}.size());\n"
    end

    result << <<-EOT
#{indent}for(#{src_type.cxx_name}::const_iterator it = #{src}.begin(); it != #{src}.end(); ++it)
#{indent}{
    EOT

    if yield(element_type)
        result << "#{indent}    #{dest}.push_back(*it);\n"
    else
        result << "#{indent}    #{dest}.push_back(#{dest_type.deference.cxx_name}());\n"
        result << "#{indent}    #{method}(*#{dest}.rbegin(), *it);\n";
    end

    result << "#{indent}}\n";
end

.container_cxx_kindObject



139
140
141
# File 'lib/orogen/gen/typekit.rb', line 139

def self.container_cxx_kind
    normalize_cxxname(container_kind)
end

.cxx_nameObject



110
111
112
113
114
115
116
# File 'lib/orogen/typenames.rb', line 110

def self.cxx_name
    if name =~ /</
        normalize_cxxname(container_kind) + "< " + deference.cxx_name + " >"
    else
        normalize_cxxname(container_kind)
    end
end

.from_intermediate(typekit, result, indent) ⇒ Object



173
174
175
176
177
# File 'lib/orogen/gen/typekit.rb', line 173

def self.from_intermediate(typekit, result, indent)
    code_copy(typekit, result, indent, "value", "intermediate", "fromIntermediate", typekit.intermediate_type_for(self), self) do |type|
        !type.contains_opaques?
    end
end

.to_intermediate(typekit, result, indent) ⇒ Object



168
169
170
171
172
# File 'lib/orogen/gen/typekit.rb', line 168

def self.to_intermediate(typekit, result, indent)
    code_copy(typekit, result, indent, "intermediate", "value", "toIntermediate", self, typekit.intermediate_type_for(self)) do |type|
        !type.contains_opaques?
    end
end

.to_m_type(target_basename, typekit) ⇒ Object



133
134
135
136
137
# File 'lib/orogen/gen/typekit.rb', line 133

def self.to_m_type(target_basename, typekit)
    target_cxxname = typekit.intermediate_cxxname_for(deference)
    "struct __gccxml_workaround_#{method_name(true)} {\n  #{container_cxx_kind}< #{target_cxxname[0]}#{target_cxxname[1]} > instanciate;\n};\n"  +
    "typedef #{container_cxx_kind}< #{target_cxxname[0]}#{target_cxxname[1]} > orogen_typekits_mtype_#{method_name(true)};"
end

.to_stream(typekit, result, indent) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/orogen/marshallers/iostream.rb', line 10

def self.to_stream(typekit, result, indent)
    collection_name, element_type = container_kind, deference.name
    element_type = registry.build(element_type)

    result << indent << "io << \"[ \";\n"

    first_field = true
    allocate_index do |element_idx|
        result << <<-EOT
#{indent}bool first_field = true;
#{indent}for(#{cxx_name}::const_iterator it = value.begin(); it != value.end(); ++it)
#{indent}{
#{indent}    if (!first_field)
#{indent}         io << ", ";
#{indent}    first_field = false;
        EOT

        if element_type.inlines_code?
            result << "#{indent}    io << *it;\n"
        elsif element_type < ArrayType
            result << "#{indent}    toStream(\"\", reinterpret_cast<#{element_type.deference.cxx_name} const*>(*it), #{element_size.length}, io);\n"
        else
            result << "#{indent}    toStream(\"\", *it, io);\n"
        end
        result << "#{indent}}\n"
    end
    result << indent << "io << \" ]\";\n"
end