Packing control for generated types

This commit is contained in:
Pavel Kirienko
2014-03-03 16:27:06 +04:00
parent 02963500ec
commit 89f8925a76
2 changed files with 21 additions and 0 deletions
@@ -46,6 +46,10 @@ namespace ${nsc}
{
% endfor
#if UAVCAN_PACK_STRUCTS
UAVCAN_PACKED_BEGIN
#endif
struct ${t.short_name}
{
<%def name="generate_primary_body(type_name, max_bitlen, fields, constants)" buffered="True">
@@ -174,6 +178,10 @@ ${'::uavcan::TailArrayOptDisabled' if (idx + 1) < len(fields) else 'tao_mode'});
}
};
#if UAVCAN_PACK_STRUCTS
UAVCAN_PACKED_END
#endif
// TODO Stream operator
% if t.has_default_dtid:
@@ -181,6 +189,8 @@ namespace
{
::uavcan::DefaultDataTypeRegistrator<${t.short_name}> _uavcan_gdtr_registrator_${t.short_name};
}
% else:
// No default registration
% endif
% for nsc in t.cpp_namespace_components:
@@ -18,6 +18,17 @@ namespace uavcan
# endif
#endif
/**
* Struct layout control.
* Define UAVCAN_PACK_STRUCTS = 1 to reduce memory usage.
*/
#ifndef UAVCAN_PACKED_BEGIN
# define UAVCAN_PACKED_BEGIN _Pragma("pack(push, 1)")
#endif
#ifndef UAVCAN_PACKED_END
# define UAVCAN_PACKED_END _Pragma("pack(pop)")
#endif
/**
* Should be OK for any target arch up to AMD64 and any compiler.
* The library leverages compile-time checks to ensure that all types that are subject to dynamic allocation