Program Listing for File any.h#
↰ Return to documentation for file (support\any.h)
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Erik Verhoeven - initial API and implementation
********************************************************************************/
#ifndef SDV_ANY_H
#define SDV_ANY_H
#include <string>
#include <algorithm>
#include <ostream>
#include <istream>
#include <filesystem>
#include "string.h"
#include "interface.h"
#include "except.h"
namespace sdv
{
class any_t
{
public:
enum class EValType : uint32_t
{
val_type_empty = 0,
val_type_bool = 1,
val_type_int8 = 8,
val_type_uint8 = 9,
val_type_int16 = 16,
val_type_uint16 = 17,
val_type_int32 = 32,
val_type_uint32 = 33,
val_type_int64 = 64,
val_type_uint64 = 65,
val_type_char = 100,
val_type_char16 = 116,
val_type_char32 = 132,
val_type_wchar = 101,
val_type_float = 232,
val_type_double = 264,
val_type_long_double = 265,
val_type_fixed = 300,
val_type_string = 1000,
val_type_u8string = 1008,
val_type_u16string = 1016,
val_type_u32string = 1032,
val_type_wstring = 1001,
val_type_interface = 2000,
val_type_interface_id = 2001,
val_type_exception_id = 3000,
} eValType = EValType::val_type_empty;
union
{
bool bVal;
int8_t i8Val;
uint8_t ui8Val;
int16_t i16Val;
uint16_t ui16Val;
int32_t i32Val;
uint32_t ui32Val;
int64_t i64Val;
uint64_t ui64Val;
char cVal;
char16_t c16Val;
char32_t c32Val;
wchar_t cwVal;
float fVal;
double dVal;
long double ldVal;
//fixed fixValue; ///< Fixed point value
string ssVal;
u8string ss8Val;
u16string ss16Val;
u32string ss32Val;
wstring sswVal;
interface_t ifcVal;
interface_id idIfcVal;
exception_id idExceptVal;
};
any_t();
~any_t();
any_t(bool bVal);
any_t(int8_t iVal);
any_t(int16_t iVal);
any_t(int32_t iVal);
#ifdef _WIN32
any_t(long iVal);
#endif
any_t(int64_t iVal);
#ifdef __linux__
any_t(long long int iVal);
#endif
any_t(uint8_t uiVal);
any_t(uint16_t uiVal);
any_t(uint32_t uiVal);
#ifdef _WIN32
any_t(unsigned long uiVal);
#endif
any_t(uint64_t uiVal);
#ifdef __linux__
any_t(unsigned long long int uiVal);
#endif
any_t(char cVal);
any_t(char16_t cVal);
any_t(char32_t cVal);
any_t(wchar_t cVal);
any_t(float fVal);
any_t(double fVal);
any_t(long double fVal);
any_t(const string& rssVal);
any_t(const u8string& rssVal);
any_t(const u16string& rssVal);
any_t(const u32string& rssVal);
any_t(const wstring& rssVal);
any_t(const char* szVal);
any_t(const char16_t* szVal);
any_t(const char32_t* szVal);
any_t(const wchar_t* szVal);
any_t(const std::string& rssVal);
any_t(const std::u16string& rssVal);
any_t(const std::u32string& rssVal);
any_t(const std::wstring& rssVal);
any_t(const std::filesystem::path& rpathVal);
any_t(interface_t ifcVal);
// Assignment already covered by any_t(uint64)
// * brief Interface ID constructor.
// * param[in] idIfcVal Interface ID.
// */
//any_t(interface_id idIfcVal);
// Assignment already covered by any_t(uint64)
// * brief Exception ID constructor.
// * param[in] idExceptVal Exception ID.
// */
//any_t(exception_id idExceptVal);
template <typename TEnum, typename TEnable = std::enable_if_t<std::is_enum_v<TEnum>>>
explicit any_t(TEnum eVal);
template <typename TType>
any_t(TType tVal, EValType eValTypeParam);
any_t(const any_t& rany);
any_t(any_t&& rany) noexcept;
any_t& operator=(bool bVal);
any_t& operator=(int8_t iVal);
any_t& operator=(int16_t iVal);
any_t& operator=(int32_t iVal);
#ifdef _WIN32
any_t& operator=(long iVal);
#endif
any_t& operator=(int64_t iVal);
#ifdef __linux__
any_t& operator=(long long int iVal);
#endif
any_t& operator=(uint8_t uiVal);
any_t& operator=(uint16_t uiVal);
any_t& operator=(uint32_t uiVal);
#ifdef _WIN32
any_t& operator=(unsigned long uiVal);
#endif
any_t& operator=(uint64_t uiVal);
#ifdef __linux__
any_t& operator=(unsigned long long int uiVal);
#endif
any_t& operator=(char cVal);
any_t& operator=(char16_t cVal);
any_t& operator=(char32_t cVal);
any_t& operator=(wchar_t cVal);
any_t& operator=(float fVal);
any_t& operator=(double fVal);
any_t& operator=(long double fVal);
any_t& operator=(const string& rssVal);
any_t& operator=(const u8string& rssVal);
any_t& operator=(const u16string& rssVal);
any_t& operator=(const u32string& rssVal);
any_t& operator=(const wstring& rssVal);
any_t& operator=(const char* szVal);
any_t& operator=(const char16_t* szVal);
any_t& operator=(const char32_t* szVal);
any_t& operator=(const wchar_t* szVal);
any_t& operator=(const std::string& rssVal);
any_t& operator=(const std::u16string& rssVal);
any_t& operator=(const std::u32string& rssVal);
any_t& operator=(const std::wstring& rssVal);
any_t& operator=(const std::filesystem::path& rpathVal);
any_t& operator=(interface_t ifcVal);
// Assignment already covered by operator=(uint64)
// * brief Interface ID operator.
// * param[in] idIfcVal Interface ID.
// */
//any_t& operator=(interface_id idIfcVal);
// Assignment already covered by operator=(uint64)
// * brief Exception ID operator.
// * param[in] idExceptVal Exception ID.
// */
//any_t& operator=(exception_id idExceptVal);
template <typename TEnum, typename TEnable = std::enable_if_t<std::is_enum_v<TEnum>>>
any_t& operator=(TEnum eVal);
any_t& operator=(const any_t& rany);
any_t& operator=(any_t&& rany) noexcept;
operator bool() const;
operator int8_t() const;
operator uint8_t() const;
operator int16_t() const;
operator uint16_t() const;
operator int32_t() const;
operator uint32_t() const;
operator int64_t() const;
operator uint64_t() const;
#ifdef __linux__
operator long long int() const { return static_cast<long long int>(operator int64_t()); }
operator unsigned long long int() const { return static_cast<long long int>(operator uint64_t()); }
#endif
operator char() const;
operator char16_t() const;
operator char32_t() const;
operator wchar_t() const;
operator float() const;
operator double() const;
operator long double() const;
//operator fixed() const;
operator string() const;
operator u8string() const;
operator u16string() const;
operator u32string() const;
operator wstring() const;
operator interface_t() const;
//operator interface_id() const;
//operator exception_id() const;
operator std::string() const;
operator std::u16string() const;
operator std::u32string() const;
operator std::wstring() const;
operator std::filesystem::path() const;
bool empty() const;
void clear();
void set(bool bVal);
void set(int8_t iVal);
void set(int16_t iVal);
void set(int32_t iVal);
#ifdef _WIN32
void set(long iVal);
#endif
void set(int64_t iVal);
#ifdef __linux__
void set(long long int iVal);
#endif
void set(uint8_t uiVal);
void set(uint16_t uiVal);
void set(uint32_t uiVal);
#ifdef _WIN32
void set(unsigned long uiVal);
#endif
void set(uint64_t uiVal);
#ifdef __linux__
void set(unsigned long long int uiVal);
#endif
void set(char cVal);
void set(char16_t cVal);
void set(char32_t cVal);
void set(wchar_t cVal);
void set(float fVal);
void set(double fVal);
void set(long double fVal);
void set(const string& rssVal);
void set(const u8string& rssVal);
void set(const u16string& rssVal);
void set(const u32string& rssVal);
void set(const wstring& rssVal);
void set(const char* szVal);
void set(const char16_t* szVal);
void set(const char32_t* szVal);
void set(const wchar_t* szVal);
void set(const std::string& rssVal);
void set(const std::u16string& rssVal);
void set(const std::u32string& rssVal);
void set(const std::wstring& rssVal);
void set(const std::filesystem::path& rpathVal);
void set(interface_t ifcVal);
// Assignment already covered by set(uint64)
// * brief Interface ID assignment function.
// * param[in] idIfcVal Interface ID.
// */
//void set(interface_id idIfcVal);
// Assignment already covered by set(uint64)
// * brief Exception ID assignment function.
// * param[in] idExceptVal Exception ID.
// */
//void set(exception_id idExceptVal);
template <typename TEnum, typename TEnable = std::enable_if_t<std::is_enum_v<TEnum>>>
void set(TEnum eVal);
template <typename TType>
void set(TType tVal, EValType eValTypeParam);
template <typename TType>
TType get() const;
enum class ECompareType
{
compare_equal,
compare_inequal,
compare_smaller,
compare_smaller_equal,
compare_larger,
compare_larger_equal,
};
template <typename TType, ECompareType eType>
bool Compare(const TType& rtVal) const;
template <ECompareType eType>
bool Compare(const any_t& ranyVal) const;
private:
template <typename TSourceType, typename TDestType>
static void convert(const TSourceType& rtSrcVal, TDestType& rtDstVal);
};
template <typename TType>
bool operator==(const sdv::any_t& ranyVal1, TType tVal2);
template <typename TType>
bool operator==(TType tVal1, const sdv::any_t& ranyVal2);
bool operator==(const sdv::any_t& ranyVal1, const sdv::any_t& ranyVal2);
template <typename TType>
bool operator!=(const sdv::any_t& ranyVal1, TType tVal2);
template <typename TType>
bool operator!=(TType tVal1, const sdv::any_t& ranyVal2);
bool operator!=(const sdv::any_t& ranyVal1, const sdv::any_t& ranyVal2);
template <typename TType>
bool operator<(const sdv::any_t& ranyVal1, TType tVal2);
template <typename TType>
bool operator<(TType tVal1, const sdv::any_t& ranyVal2);
bool operator<(const sdv::any_t& ranyVal1, const sdv::any_t& ranyVal2);
template <typename TType>
bool operator<=(const sdv::any_t& ranyVal1, TType tVal2);
template <typename TType>
bool operator<=(TType tVal1, const sdv::any_t& ranyVal2);
bool operator<=(const sdv::any_t& ranyVal1, const sdv::any_t& ranyVal2);
template <typename TType>
bool operator>(const sdv::any_t& ranyVal1, TType tVal2);
template <typename TType>
bool operator>(TType tVal1, const sdv::any_t& ranyVal2);
bool operator>(const sdv::any_t& ranyVal1, const sdv::any_t& ranyVal2);
template <typename TType>
bool operator>=(const sdv::any_t& ranyVal1, TType tVal2);
template <typename TType>
bool operator>=(TType tVal1, const sdv::any_t& ranyVal2);
bool operator>=(const sdv::any_t& ranyVal1, const sdv::any_t& ranyVal2);
}
#include "any.inl"
#endif // !defined SDV_ANY_H