MIP_SDK
v3.0.0
MicroStrain Communications Library for embedded systems
src
cpp
mip
metadata
mip_meta_utils.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
mip_structures.hpp
"
4
5
6
namespace
mip::metadata::utils
7
{
8
9
//
10
// Gets the "Type" enum value given a C++ template type.
11
//
12
template
<
class
T,
class
=
void
>
struct
ParamType
{
static
inline
constexpr
auto
value
=
Type::NONE
; };
13
14
template
<>
struct
ParamType
<char, void> {
static
constexpr
inline
auto
value
=
Type::CHAR
; };
15
template
<>
struct
ParamType
<bool, void> {
static
constexpr
inline
auto
value
=
Type::BOOL
; };
16
template
<>
struct
ParamType
<uint8_t, void> {
static
constexpr
inline
auto
value
=
Type::U8
; };
17
template
<>
struct
ParamType
< int8_t, void> {
static
constexpr
inline
auto
value
=
Type::S8
; };
18
template
<>
struct
ParamType
<uint16_t, void> {
static
constexpr
inline
auto
value
=
Type::U16
; };
19
template
<>
struct
ParamType
< int16_t, void> {
static
constexpr
inline
auto
value
=
Type::S16
; };
20
template
<>
struct
ParamType
<uint32_t, void> {
static
constexpr
inline
auto
value
=
Type::U32
; };
21
template
<>
struct
ParamType
< int32_t, void> {
static
constexpr
inline
auto
value
=
Type::S32
; };
22
template
<>
struct
ParamType
<uint64_t, void> {
static
constexpr
inline
auto
value
=
Type::U64
; };
23
template
<>
struct
ParamType
< int64_t, void> {
static
constexpr
inline
auto
value
=
Type::S64
; };
24
template
<>
struct
ParamType
<float, void> {
static
constexpr
inline
auto
value
=
Type::FLOAT
; };
25
template
<>
struct
ParamType
<double, void> {
static
constexpr
inline
auto
value
=
Type::DOUBLE
; };
26
template
<
class
T>
struct
ParamType
<
Bitfield
<T>, void> {
static
constexpr
inline
auto
value
=
Type::BITS
; };
27
template
<
class
T>
struct
ParamType
<T, typename std::enable_if<std::is_enum<T>::value, T>::type> {
static
constexpr
inline
auto
value
=
Type::ENUM
; };
28
template
<
class
T>
struct
ParamType
<T, typename
EnableForFieldTypes
<T>::type> {
static
constexpr
inline
auto
value
=
Type::STRUCT
; };
29
template
<
class
T>
struct
ParamType
<T, typename std::enable_if<std::is_union<T>::value, T>::type> {
static
constexpr
inline
auto
value
=
Type::UNION
; };
30
31
32
//
33
// Gets the template type given a compile-time "Type" enum value.
34
// Note: this only works with basic/built-in/arithmetic types, not structs/enums/etc.
35
//
36
template
<Type Kind>
37
struct
ParamEnum
{
using
type
= void; };
38
39
template
<>
struct
ParamEnum
<
Type
::
CHAR
> {
using
type
= char; };
40
template
<>
struct
ParamEnum
<
Type
::
BOOL
> {
using
type
= bool; };
41
template
<>
struct
ParamEnum
<
Type
::
U8
> {
using
type
= uint8_t; };
42
template
<>
struct
ParamEnum
<
Type
::
S8
> {
using
type
= int8_t; };
43
template
<>
struct
ParamEnum
<
Type
::
U16
> {
using
type
= uint16_t; };
44
template
<>
struct
ParamEnum
<
Type
::
S16
> {
using
type
= int16_t; };
45
template
<>
struct
ParamEnum
<
Type
::
U32
> {
using
type
= uint32_t; };
46
template
<>
struct
ParamEnum
<
Type
::
S32
> {
using
type
= int32_t; };
47
template
<>
struct
ParamEnum
<
Type
::
U64
> {
using
type
= uint64_t; };
48
template
<>
struct
ParamEnum
<
Type
::
S64
> {
using
type
= int64_t; };
49
template
<>
struct
ParamEnum
<
Type
::
FLOAT
> {
using
type
= float; };
50
template
<>
struct
ParamEnum
<
Type
::
DOUBLE
> {
using
type
= double; };
51
52
53
// Gets a void pointer to the member identified by Ptr, given an
54
// instance of field passed by void pointer.
55
/*template<class Field, class T, T Field::*Ptr>
56
void* access(void* p)
57
{
58
return &(static_cast<Field*>(p)->*Ptr);
59
}
60
61
template<class Field, class T, auto Ptr>
62
void* access(void* p)
63
{
64
Field* f = static_cast<Field*>(p);
65
auto& param = f->*Ptr;
66
return ¶m;
67
}*/
68
69
template
<
class
Field,
class
T, auto Ptr>
70
void
*
access
(
void
* p);
71
72
}
// namespace mip::metadata
mip::metadata::utils::ParamEnum
Definition:
mip_meta_utils.hpp:37
mip::metadata::utils::ParamEnum< Type::CHAR >::type
char type
Definition:
mip_meta_utils.hpp:39
mip::metadata::Type::ENUM
@ ENUM
mip::metadata::Type::NONE
@ NONE
Invalid/unknown.
mip::metadata::utils::ParamType::value
static constexpr auto value
Definition:
mip_meta_utils.hpp:12
mip::EnableForFieldTypes
std::enable_if< isField< T >::value, T > EnableForFieldTypes
Definition:
mip_descriptors.hpp:57
mip::metadata::utils::ParamEnum< Type::S16 >::type
int16_t type
Definition:
mip_meta_utils.hpp:44
mip::metadata::Type::U16
@ U16
mip::metadata::Type::STRUCT
@ STRUCT
mip::metadata::Type::S32
@ S32
mip::metadata::utils::ParamEnum< Type::FLOAT >::type
float type
Definition:
mip_meta_utils.hpp:49
mip::metadata::Type::DOUBLE
@ DOUBLE
mip::metadata::Type
Type
Definition:
mip_structures.hpp:23
mip::metadata::Type::CHAR
@ CHAR
mip::metadata::utils::ParamEnum::type
void type
Definition:
mip_meta_utils.hpp:37
mip::metadata::utils::ParamEnum< Type::DOUBLE >::type
double type
Definition:
mip_meta_utils.hpp:50
mip::metadata::utils::ParamType
Definition:
mip_meta_utils.hpp:12
mip::metadata::Type::UNION
@ UNION
mip::metadata::Type::S8
@ S8
mip::metadata::Type::FLOAT
@ FLOAT
mip::metadata::Type::S16
@ S16
mip::metadata::Type::S64
@ S64
mip::metadata::utils::ParamEnum< Type::U8 >::type
uint8_t type
Definition:
mip_meta_utils.hpp:41
mip::metadata::Type::U64
@ U64
mip::metadata::Type::BOOL
@ BOOL
mip::metadata::utils::ParamEnum< Type::U64 >::type
uint64_t type
Definition:
mip_meta_utils.hpp:47
mip::metadata::Type::U8
@ U8
mip_structures.hpp
mip::metadata::utils::ParamEnum< Type::S32 >::type
int32_t type
Definition:
mip_meta_utils.hpp:46
mip::metadata::utils
Definition:
mip_meta_utils.hpp:6
mip::metadata::utils::ParamEnum< Type::U16 >::type
uint16_t type
Definition:
mip_meta_utils.hpp:43
mip::metadata::utils::ParamEnum< Type::S8 >::type
int8_t type
Definition:
mip_meta_utils.hpp:42
mip::metadata::utils::access
void * access(void *p)
mip::metadata::Type::BITS
@ BITS
mip::metadata::utils::ParamEnum< Type::U32 >::type
uint32_t type
Definition:
mip_meta_utils.hpp:45
mip::Bitfield
A dummy struct which is used to mark bitfield objects.
Definition:
mip_descriptors.hpp:62
mip::metadata::Type::U32
@ U32
mip::metadata::utils::ParamEnum< Type::S64 >::type
int64_t type
Definition:
mip_meta_utils.hpp:48
mip::metadata::utils::ParamEnum< Type::BOOL >::type
bool type
Definition:
mip_meta_utils.hpp:40
Generated by
1.8.17