Class: Typelib::CompoundType

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

Class Method Summary collapse

Class Method Details

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



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/orogen/gen/typekit.rb', line 225

def self.code_copy(typekit, result, indent, dest, src, method, error_handling)
    each_field do |field_name, field_type|
        if string = yield(field_name, field_type)
            if !string.respond_to?(:to_str)
                result << "#{indent}#{dest}.#{field_name} = #{src}.#{field_name};\n"
            else
                result << string
            end
        else
            s_src  = "#{src}.#{field_name}"
            s_dest = "#{dest}.#{field_name}"
            if field_type < ArrayType
                if src == "value"
                    s_src = "reinterpret_cast< #{field_type.deference.cxx_name} const*>(#{s_src}), #{field_type.length}"
                else
                    s_dest = "reinterpret_cast< #{field_type.deference.cxx_name}*>(#{s_dest}), #{field_type.length}"
                end
            end

            if error_handling
                result << "#{indent}if (!#{method}(#{s_dest}, #{s_src})) return false;\n";
            else
                result << "#{indent}#{method}(#{s_dest}, #{s_src});\n"
            end
        end
    end
    result
end

.from_intermediate(typekit, result, indent) ⇒ Object



261
262
263
264
265
266
267
# File 'lib/orogen/gen/typekit.rb', line 261

def self.from_intermediate(typekit, result, indent)
    code_copy(typekit, result, indent, "value", "intermediate", "fromIntermediate", false) do |field_name, field_type|
        if !field_type.contains_opaques?
            field_type.code_assign([], indent + "    ", "value.#{field_name}", "intermediate.#{field_name}").join
        end
    end
end

.to_intermediate(typekit, result, indent) ⇒ Object



254
255
256
257
258
259
260
# File 'lib/orogen/gen/typekit.rb', line 254

def self.to_intermediate(typekit, result, indent)
    code_copy(typekit, result, indent, "intermediate", "value", "toIntermediate", false) do |field_name, field_type|
        if !field_type.contains_opaques?
            field_type.code_assign([], indent + "    ", "intermediate.#{field_name}", "value.#{field_name}").join
        end
    end
end

.to_m_type(target_basename, typekit) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/orogen/gen/typekit.rb', line 206

def self.to_m_type(target_basename, typekit)
    result = <<-EOCODE
struct #{target_basename}
{
    EOCODE
    each_field do |field_name, field_type|
        field_cxxname =
            if field_type.contains_opaques?
                typekit.intermediate_cxxname_for(field_type.name)
            elsif field_type <= ArrayType
                [field_type.deference.cxx_name, "[#{field_type.length}]"]
            else
                [field_type.cxx_name]
            end
        result << "   #{field_cxxname[0]} #{field_name} #{field_cxxname[1]};\n"
    end
    result << "};"
end

.to_stream(typekit, result, indent) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/orogen/marshallers/iostream.rb', line 50

def self.to_stream(typekit, result, indent)
    result << indent << "io << \"{ \";\n"

    first_field = true
    each_field do |field_name, field_type|
        unless first_field
            result << "#{indent}  io << \", \";\n";
        end

        first_field = false
        result << "#{indent}  io << basename << \".#{field_name} = \";\n";
        if field_type.inlines_code?
            result << "#{indent}  io << value.#{field_name};\n"
        elsif field_type < ArrayType
            result << "#{indent}  toStream(basename + \".#{field_name}\", reinterpret_cast<#{field_type.deference.cxx_name} const*>(value.#{field_name}), #{field_type.length}, io);\n"
        else
            result << "#{indent}  toStream(basename + \".#{field_name}\", value.#{field_name}, io);\n"
        end
    end
    result << indent << "io << \" }\";\n"
end