Module: OroGen::TypekitMarshallers::Corba::ContainerType

Defined in:
lib/orogen/marshallers/corba.rb

Instance Method Summary collapse

Instance Method Details

#corba_arg_typeObject


247
# File 'lib/orogen/marshallers/corba.rb', line 247

def corba_arg_type; "#{corba_name} const&" end

#corba_nameObject


235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/orogen/marshallers/corba.rb', line 235

def corba_name
    container_kind = self.container_kind.gsub /.*\//, ''
    element_name   = deference.name.gsub(/[^\w]/, "_")
    typedef_name = container_kind + "_" + element_name

    if deference.corba_name !~ /^orogen::/
        # This type is mapped into the root namespace
        "orogen::Corba::#{typedef_name}_"
    else
        "#{corba_namespace}::#{typedef_name}_"
    end
end

#corba_namespaceObject


250
251
252
# File 'lib/orogen/marshallers/corba.rb', line 250

def corba_namespace
    deference.corba_namespace
end

#corba_ref_typeObject


248
# File 'lib/orogen/marshallers/corba.rb', line 248

def corba_ref_type; "#{corba_name}&" end

#from_corba(typekit, result, indent) ⇒ Object


288
289
290
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
# File 'lib/orogen/marshallers/corba.rb', line 288

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

    if container_kind != "/std/vector"
        raise NotImplementedError, "from_corba is not implemented for other containers than std::vector, got #{container_kind}"
    end

    allocate_index do |element_idx|
        result << "#{indent}size_t const size_#{element_idx} = corba.length();\n"
        result << "#{indent}value.resize(size_#{element_idx});\n"

        if collection_name == "/std/vector" && 
            element_type < NumericType

            result << "if (!value.empty()) #{indent}memcpy(&value[0], &corba[0], size_#{element_idx});"
        else
            result << "\#{indent}for(size_t \#{element_idx} = 0; \#{element_idx} < size_\#{element_idx}; ++\#{element_idx})\n\#{indent}{\n"

            if element_type.inlines_code?
                result << element_type.inline_fromCorba("value[#{element_idx}]", "corba[#{element_idx}]", indent)
            elsif element_type < ArrayType
                result << "#{indent}    fromCORBA(reinterpret_cast<#{element_type.deference.cxx_name}*>(value[#{element_idx}]), #{element_type.length}, corba[#{element_idx}]);\n";
            else
                result << "#{indent}    fromCORBA(value[#{element_idx}], corba[#{element_idx}]);\n";
            end

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

#to_corba(typekit, result, indent) ⇒ Object


254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/orogen/marshallers/corba.rb', line 254

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

    result << "#{indent}corba.length(value.size());\n"
    # Special case for array of bytes, we can do a simple memcpy
    # (maybe extend that later)
    if collection_name == "/std/vector" && 
        element_type < NumericType &&
        element_type.integer? &&
        element_type.size == 1

        result << "if (!value.empty()) #{indent}memcpy(&corba[0], &value[0], value.size());"
    else
        allocate_index do |element_idx|
            result << "\#{indent}size_t \#{element_idx} = 0;\n\#{indent}for(\#{cxx_name}::const_iterator it = value.begin(); it != value.end(); ++it, ++\#{element_idx})\n\#{indent}{\n"

            if element_type.inlines_code?
                result << element_type.inline_toCorba("corba[#{element_idx}]", "(*it)", indent)
            elsif element_type < ArrayType
                result << indent << "    toCORBA(corba[#{element_idx}], reinterpret_cast< #{element_type.deference.cxx_name} const*>(*it), #{element_type.length});\n";
            else
                result << indent << "    toCORBA(corba[#{element_idx}], *it);\n";
            end

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