Class: Typelib::ArrayType

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

Class Method Summary collapse

Class Method Details

.arg_typeObject



271
# File 'lib/orogen/gen/typekit.rb', line 271

def self.arg_type; "#{deference.cxx_name} const*" end

.code_assign(result, indent, dest, src) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
# File 'lib/orogen/gen/typekit.rb', line 279

def self.code_assign(result, indent, dest, src)
    element_type = deference
    allocate_index do |i|
        result << <<-EOT
#{indent}for(int #{i} = 0; #{i} < #{length}; ++#{i})
#{indent}{
        EOT
        deference.code_assign(result, "#{indent}  ", "#{dest}[#{i}]", "#{src}[#{i}]")
        result << "#{indent}}"
    end
end

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



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/orogen/gen/typekit.rb', line 291

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

    allocate_index do |i|
        result << <<-EOT
#{indent}for(int #{i} = 0; #{i} < length; ++#{i})
#{indent}{
        EOT

        if string = yield(element_type, indent, "#{dest}[#{i}]", "#{src}[#{i}]")
            if !string.respond_to?(:to_str)
                result << "#{indent}  #{dest}[#{i}] = #{src}[#{i}];\n"
            else
                result << string
            end
        else
            s_src  = "#{src}[#{i}]"
            s_dest = "#{dest}[#{i}]"
            if element_type < ArrayType
                if src == "value"
                    s_src = "reinterpret_cast< #{element_type.deference.cxx_name} const*>(#{s_src}), #{element_type.length}"
                else
                    s_dest = "reinterpret_cast< #{element_type.deference.cxx_name}*>(#{s_dest}), #{element_type.length}"
                end
            end

            result << "#{indent}    #{method}(#{s_dest}, #{s_src});\n";
        end

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

.from_intermediate(typekit, result, indent) ⇒ Object



333
334
335
336
337
338
339
# File 'lib/orogen/gen/typekit.rb', line 333

def self.from_intermediate(typekit, result, indent)
    code_copy(typekit, result, indent, "value", "intermediate", "fromIntermediate") do |type, indent, dest, src|
        if !type.contains_opaques?
            type.code_assign([], indent, dest, src).join
        end
    end
end

.ref_typeObject



272
# File 'lib/orogen/gen/typekit.rb', line 272

def self.ref_type; "#{deference.cxx_name}*" end

.to_intermediate(typekit, result, indent) ⇒ Object



325
326
327
328
329
330
331
# File 'lib/orogen/gen/typekit.rb', line 325

def self.to_intermediate(typekit, result, indent)
    code_copy(typekit, result, indent, "intermediate", "value", "toIntermediate") do |type, indent, dest, src|
        if !type.contains_opaques?
            type.code_assign([], indent, dest, src).join
        end
    end
end

.to_m_type(target_basename, typekit) ⇒ Object



274
275
276
277
# File 'lib/orogen/gen/typekit.rb', line 274

def self.to_m_type(target_basename, typekit)
    deference_name = typekit.intermediate_cxxname_for(deference)
    "typedef #{deference_name[0]} orogen_typekits_mtype_#{target_basename}#{deference_name[1]};"
end

.to_stream(typekit, result, indent) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/orogen/marshallers/iostream.rb', line 73

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

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

    first_field = true
    allocate_index do |i|
        result << <<-EOT
#{indent}bool first_field = true;
#{indent}for(int #{i} = 0; #{i} < length; ++#{i})
#{indent}{
#{indent}    if (!first_field)
#{indent}         io << ", ";
#{indent}    first_field = false;
        EOT

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