MakeString<> helper template

This commit is contained in:
Pavel Kirienko
2015-05-18 22:29:09 +03:00
parent 65c5d6efa8
commit 5e458e918d
4 changed files with 16 additions and 5 deletions
@@ -1087,6 +1087,19 @@ inline bool operator!=(const R& rhs, const Array<T, ArrayMode, MaxSize>& 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 <unsigned MaxSize>
class MakeString
{
MakeString(); // This class is not instantiatable.
public:
typedef Array<IntegerSpec<8, SignednessUnsigned, CastModeSaturate>, ArrayModeDynamic, MaxSize> Type;
};
/**
* YAML streamer specification for any Array<>
*/
@@ -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<IntegerSpec<8, SignednessUnsigned, CastModeTruncate>, ArrayModeDynamic, MaxStringLength> String;
typedef MakeString<MaxStringLength>::Type String;
/**
* Read one value from the storage.
@@ -34,8 +34,7 @@ class FileEventTracer : public uavcan::dynamic_node_id_server::IEventTracer
/**
* This type is used for the path
*/
typedef uavcan::Array<uavcan::IntegerSpec<8, uavcan::SignednessUnsigned, uavcan::CastModeTruncate>,
uavcan::ArrayModeDynamic, MaxPathLength> PathString;
typedef uavcan::MakeString<MaxPathLength>::Type PathString;
PathString path_;
@@ -39,8 +39,7 @@ class FileStorageBackend : public uavcan::dynamic_node_id_server::IStorageBacken
/**
* This type is used for the path
*/
typedef uavcan::Array<uavcan::IntegerSpec<8, uavcan::SignednessUnsigned, uavcan::CastModeTruncate>,
uavcan::ArrayModeDynamic, MaxPathLength> PathString;
typedef uavcan::MakeString<MaxPathLength>::Type PathString;
PathString base_path;