From 5e458e918d7606ffa89dc79ee357391799b501a9 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 18 May 2015 22:29:09 +0300 Subject: [PATCH] MakeString<> helper template --- libuavcan/include/uavcan/marshal/array.hpp | 13 +++++++++++++ .../dynamic_node_id_server/storage_backend.hpp | 2 +- .../dynamic_node_id_server/file_event_tracer.hpp | 3 +-- .../dynamic_node_id_server/file_storage_backend.hpp | 3 +-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libuavcan/include/uavcan/marshal/array.hpp b/libuavcan/include/uavcan/marshal/array.hpp index 73277f4c1b..c7263d106e 100644 --- a/libuavcan/include/uavcan/marshal/array.hpp +++ b/libuavcan/include/uavcan/marshal/array.hpp @@ -1087,6 +1087,19 @@ inline bool operator!=(const R& rhs, const Array& lhs) return lhs.operator!=(rhs); } +/** + * Shortcut for string-like array type instantiation. + * The proper way of doing this is actually "template<> using ... = ...", but this feature is not available in + * older C++ revisions which the library has to support. + */ +template +class MakeString +{ + MakeString(); // This class is not instantiatable. +public: + typedef Array, ArrayModeDynamic, MaxSize> Type; +}; + /** * YAML streamer specification for any Array<> */ diff --git a/libuavcan/include/uavcan/protocol/dynamic_node_id_server/storage_backend.hpp b/libuavcan/include/uavcan/protocol/dynamic_node_id_server/storage_backend.hpp index 9e970dd671..9e2395c92a 100644 --- a/libuavcan/include/uavcan/protocol/dynamic_node_id_server/storage_backend.hpp +++ b/libuavcan/include/uavcan/protocol/dynamic_node_id_server/storage_backend.hpp @@ -37,7 +37,7 @@ public: * This type is used to exchange data chunks with the backend. * It doesn't use any dynamic memory; please refer to the Array<> class for details. */ - typedef Array, ArrayModeDynamic, MaxStringLength> String; + typedef MakeString::Type String; /** * Read one value from the storage. diff --git a/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_event_tracer.hpp b/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_event_tracer.hpp index c8e97244dd..3398a54418 100644 --- a/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_event_tracer.hpp +++ b/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_event_tracer.hpp @@ -34,8 +34,7 @@ class FileEventTracer : public uavcan::dynamic_node_id_server::IEventTracer /** * This type is used for the path */ - typedef uavcan::Array, - uavcan::ArrayModeDynamic, MaxPathLength> PathString; + typedef uavcan::MakeString::Type PathString; PathString path_; diff --git a/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp b/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp index e4ce8c8e23..fdf173cc13 100644 --- a/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp +++ b/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp @@ -39,8 +39,7 @@ class FileStorageBackend : public uavcan::dynamic_node_id_server::IStorageBacken /** * This type is used for the path */ - typedef uavcan::Array, - uavcan::ArrayModeDynamic, MaxPathLength> PathString; + typedef uavcan::MakeString::Type PathString; PathString base_path;