Coerce.h

// Coerce.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2022

@import "cxObject.h"
#include "Ceda/cxUtils/BasicTypes.h"

namespace ceda
{
struct ReflectedType;
struct ReflectedClass;
struct ReflectedVariant;

// The CoerceFromRV functions don't throw UnsupportedExceptions 

// If the variable of type rtype at addr can be interpreted as a boolean variable then assign the
// value to v and return true. otherwise return false
// If allowExplicitConversions is true then enable coercions to bool

@api bool CoerceFromRV(bool& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);

@api bool CoerceFromRV(int8& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);
@api bool CoerceFromRV(int16& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);
@api bool CoerceFromRV(int32& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);
@api bool CoerceFromRV(int64& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);

@api bool CoerceFromRV(uint8& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);
@api bool CoerceFromRV(uint16& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);
@api bool CoerceFromRV(uint32& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);
@api bool CoerceFromRV(uint64& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);

@api bool CoerceFromRV(float32& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);
@api bool CoerceFromRV(float64& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);

@api bool CoerceFromRV(char8& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);
@api bool CoerceFromRV(char16& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);

@api bool CoerceFromRV(string8& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);
@api bool CoerceFromRV(string16& v, const ReflectedType& rtype, const void* addr, bool allowExplicitConversions = false);

@api bool AssignReflectedVariable(
    const ReflectedType& lhs_type, void* lhs, 
    const ReflectedType& rhs_type, const void* rhs,
    bool allowExplicitConversions);

@api bool AssignReflectedClassVariable(
    const ReflectedClass& lhs_rc, void* lhs, 
    const ReflectedClass& rhs_rc, const void* rhs,
    bool allowExplicitConversions);

@api bool AssignReflectedVariantVariable(
    const ReflectedVariant& lhs_rv, void* lhs, 
    const ReflectedVariant& rhs_rv, const void* rhs,
    bool allowExplicitConversions);

} // namespace ceda