23 #ifndef LELY_CO_VAL_HPP_ 24 #define LELY_CO_VAL_HPP_ 27 #error "include <lely/co/val.h> for the C interface" 41 template <co_
unsigned16_t N>
46 static const co_unsigned16_t index = traits::index;
48 typedef typename traits::type type;
50 operator const type&()
const noexcept {
return m_val; }
51 operator type&() noexcept {
return m_val; }
57 COVal(
const type& val) : m_val(val) {}
58 COVal(type&& val) : m_val(::std::move(val)) {}
60 COVal(
const void* ptr, ::std::size_t n) {
68 operator=(
const type& val) {
74 operator=(type&& val) {
75 m_val = ::std::move(val);
80 address()
const noexcept {
81 return static_cast<const void*
>(&m_val);
85 size()
const noexcept {
99 static const co_unsigned16_t index = traits::index;
101 typedef typename traits::type type;
103 operator type()
const noexcept {
return m_val; }
105 operator ::std::string()
const {
106 return m_val ? ::std::string(m_val) : ::std::string();
110 COVal(
const COVal& val) : m_val() { *
this = val; }
111 COVal(
COVal&& val) : m_val() { *
this = ::std::move(val); }
113 COVal(
const void* ptr, ::std::size_t n) {
117 COVal(
const char* vs) { init(vs); }
118 COVal(const ::std::string& vs) { init(vs); }
123 operator=(
const COVal& val) {
130 operator=(
COVal&& val) {
137 operator=(
const char* vs) {
144 operator=(const ::std::string& vs) {
151 address()
const noexcept {
156 size()
const noexcept {
162 init(
const char* vs) {
167 init(const ::std::string& vs) {
180 static const co_unsigned16_t index = traits::index;
182 typedef typename traits::type type;
184 operator type()
const noexcept {
return m_val; }
186 operator ::std::vector<uint8_t>()
const {
187 return m_val ? ::std::vector<uint8_t>(m_val, m_val + size())
188 : ::std::vector<uint8_t>();
192 COVal(
const COVal& val) : m_val() { *
this = val; }
193 COVal(
COVal&& val) : m_val() { *
this = ::std::move(val); }
195 COVal(
const void* ptr, ::std::size_t n) {
199 COVal(
const uint8_t* os, ::std::size_t n) { init(os, n); }
200 COVal(const ::std::vector<uint8_t>& os) { init(os); }
205 operator=(
const COVal& val) {
212 operator=(
COVal&& val) {
219 operator=(const ::std::vector<uint8_t>& os) {
226 address()
const noexcept {
231 size()
const noexcept {
237 init(
const uint8_t* os, ::std::size_t n) {
242 init(const ::std::vector<uint8_t>& os) {
243 init(os.data(), os.size());
255 static const co_unsigned16_t index = traits::index;
257 typedef typename traits::type type;
259 operator type()
const noexcept {
return m_val; }
261 operator ::std::basic_string<char16_t>()
const {
262 return m_val ? ::std::basic_string<char16_t>(m_val)
263 : ::std::basic_string<char16_t>();
267 COVal(
const COVal& val) : m_val() { *
this = val; }
268 COVal(
COVal&& val) : m_val() { *
this = ::std::move(val); }
270 COVal(
const void* ptr, ::std::size_t n) {
274 COVal(
const char16_t* us) { init(us); }
275 COVal(const ::std::basic_string<char16_t>& us) { init(us); }
280 operator=(
const COVal& val) {
287 operator=(
COVal&& val) {
294 operator=(
const char16_t* us) {
301 operator=(const ::std::basic_string<char16_t>& us) {
308 address()
const noexcept {
313 size()
const noexcept {
319 init(
const char16_t* us) {
324 init(const ::std::basic_string<char16_t>& us) {
337 static const co_unsigned16_t index = traits::index;
339 typedef typename traits::type type;
341 operator type()
const noexcept {
return m_val; }
344 COVal(
const COVal& val) : m_val() { *
this = val; }
345 COVal(
COVal&& val) : m_val() { *
this = ::std::move(val); }
347 COVal(
const void* dom, ::std::size_t n) {
354 operator=(
const COVal& val) {
361 operator=(
COVal&& val) {
368 address()
const noexcept {
373 size()
const noexcept {
383 #endif // !LELY_CO_VAL_HPP_ This header file is part of the CANopen library; it contains the C++ interface of the CANopen type de...
#define CO_DEFTYPE_VISIBLE_STRING
The data type (and object index) of an array of visible characters.
#define CO_DEFTYPE_DOMAIN
The data type (and object index) of an arbitrary large block of data.
int co_val_init_dom(void **val, const void *dom, size_t n)
Initializes an arbitrary large block of data (CO_DEFTYPE_DOMAIN).
This header file is part of the CANopen library; it contains the CANopen value declarations.
int co_val_init_os(uint8_t **val, const uint8_t *os, size_t n)
Initializes an array of octets (CO_DEFTYPE_OCTET_STRING).
The type of objects thrown as exceptions to report a failure to copy an instantiation of a C type...
int co_val_init_vs(char **val, const char *vs)
Initializes an array of visible characters (CO_DEFTYPE_VISIBLE_STRING).
This header file is part of the utilities library; it contains the C to C++ interface declarations...
int co_val_init_us(char16_t **val, const char16_t *us)
Initializes an array of (16-bit) Unicode characters (CO_DEFTYPE_UNICODE_STRING).
#define CO_DEFTYPE_UNICODE_STRING
The data type (and object index) of an array of (16-bit) Unicode characters.
size_t co_val_sizeof(co_unsigned16_t type, const void *val)
Returns the size (in bytes) of a value of the specified data type.
size_t co_val_copy(co_unsigned16_t type, void *dst, const void *src)
Copies one value to another.
A class template mapping CANopen types to C++ types.
The type of objects thrown as exceptions to report a failure to initialize an instantiation of a C ty...
size_t co_val_make(co_unsigned16_t type, void *val, const void *ptr, size_t n)
Constructs a value of the specified data type.
const void * co_val_addressof(co_unsigned16_t type, const void *val)
Returns the address of the first byte in a value of the specified data type.
#define CO_DEFTYPE_OCTET_STRING
The data type (and object index) of an array of octets.
void co_val_fini(co_unsigned16_t type, void *val)
Finalizes a value of the specified data type.
The type of objects thrown as exceptions to report a failure to move an instantiation of a C type...
size_t co_val_move(co_unsigned16_t type, void *dst, void *src)
Moves one value to another.
Global namespace for the Lely Industries N.V. libraries.
#define throw_or_abort(e)
If exceptions are disabled, aborts the process instead of throwing an exception.