23#ifndef LELY_CO_VAL_HPP_
24#define LELY_CO_VAL_HPP_
26#if !defined(__cplusplus) || LELY_NO_CXX
27#error "include <lely/co/val.h> for the C interface"
41template <co_
unsigned16_t N>
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) {
69 operator=(
const type& val) {
75 operator=(type&& val) {
76 m_val = ::std::move(val);
81 address()
const noexcept {
82 return static_cast<const void*
>(&m_val);
86 size()
const noexcept {
102 typedef typename traits::type type;
104 operator type()
const noexcept {
return m_val; }
106 operator ::std::string()
const {
107 return m_val ? ::std::string(m_val) : ::std::string();
111 COVal(
const COVal& val) : m_val() { *
this = val; }
112 COVal(
COVal&& val) : m_val() { *
this = ::std::move(val); }
114 COVal(
const void* ptr, ::std::size_t n) {
120 COVal(const ::std::string&
vs) { init(
vs); }
125 operator=(
const COVal& val) {
134 operator=(
COVal&& val) {
141 operator=(
const char*
vs) {
148 operator=(const ::std::string&
vs) {
155 address()
const noexcept {
160 size()
const noexcept {
166 init(
const char*
vs) {
171 init(const ::std::string&
vs) {
186 typedef typename traits::type type;
188 operator type()
const noexcept {
return m_val; }
190 operator ::std::vector<uint_least8_t>()
const {
191 return m_val ? ::std::vector<uint_least8_t>(m_val, m_val + size())
192 : ::std::vector<uint_least8_t>();
196 COVal(
const COVal& val) : m_val() { *
this = val; }
197 COVal(
COVal&& val) : m_val() { *
this = ::std::move(val); }
199 COVal(
const void* ptr, ::std::size_t n) {
205 COVal(const ::std::vector<uint_least8_t>&
os) { init(
os); }
210 operator=(
const COVal& val) {
219 operator=(
COVal&& val) {
226 operator=(const ::std::vector<uint_least8_t>&
os) {
233 address()
const noexcept {
238 size()
const noexcept {
249 init(const ::std::vector<uint_least8_t>&
os) {
250 init(
os.data(),
os.size());
264 typedef typename traits::type type;
266 operator type()
const noexcept {
return m_val; }
268 operator ::std::basic_string<char16_t>()
const {
269 return m_val ? ::std::basic_string<char16_t>(m_val)
270 : ::std::basic_string<char16_t>();
274 COVal(
const COVal& val) : m_val() { *
this = val; }
275 COVal(
COVal&& val) : m_val() { *
this = ::std::move(val); }
277 COVal(
const void* ptr, ::std::size_t n) {
282 COVal(
const char16_t* us) { init(us); }
283 COVal(const ::std::basic_string<char16_t>& us) { init(us); }
288 operator=(
const COVal& val) {
297 operator=(
COVal&& val) {
304 operator=(
const char16_t* us) {
311 operator=(const ::std::basic_string<char16_t>& us) {
318 address()
const noexcept {
323 size()
const noexcept {
329 init(
const char16_t* us) {
334 init(const ::std::basic_string<char16_t>& us) {
349 typedef typename traits::type type;
351 operator type()
const noexcept {
return m_val; }
354 COVal(
const COVal& val) : m_val() { *
this = val; }
355 COVal(
COVal&& val) : m_val() { *
this = ::std::move(val); }
357 COVal(
const void*
dom, ::std::size_t n) {
364 operator=(
const COVal& val) {
373 operator=(
COVal&& val) {
380 address()
const noexcept {
385 size()
const noexcept {
This header file is part of the utilities library; it contains the C to C++ interface declarations.
The type of objects thrown as exceptions to report a failure to copy an instantiation of a C type.
The type of objects thrown as exceptions to report a failure to initialize an instantiation of a C ty...
The type of objects thrown as exceptions to report a failure to move an instantiation of a C type.
#define throw_or_abort(e)
If exceptions are disabled, aborts the process instead of throwing an exception.
#define CO_DEFTYPE_UNICODE_STRING
The data type (and object index) of an array of (16-bit) Unicode characters.
#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.
#define CO_DEFTYPE_OCTET_STRING
The data type (and object index) of an array of octets.
This header file is part of the CANopen library; it contains the C++ interface of the CANopen type de...
This header file is part of the CANopen library; it contains the CANopen value declarations.
size_t co_val_move(co_unsigned16_t type, void *dst, void *src)
Moves one value to another.
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.
int co_val_init_os(uint_least8_t **val, const uint_least8_t *os, size_t n)
Initializes an array of octets (CO_DEFTYPE_OCTET_STRING).
int co_val_init_dom(void **val, const void *dom, size_t n)
Initializes an arbitrary large block of data (CO_DEFTYPE_DOMAIN).
size_t co_val_copy(co_unsigned16_t type, void *dst, const void *src)
Copies one value to another.
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.
int co_val_init_us(char16_t **val, const char16_t *us)
Initializes an array of (16-bit) Unicode characters (CO_DEFTYPE_UNICODE_STRING).
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.
void co_val_fini(co_unsigned16_t type, void *val)
Finalizes a value of the specified data type.
int co_val_init_vs(char **val, const char *vs)
Initializes an array of visible characters (CO_DEFTYPE_VISIBLE_STRING).