mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-26 20:38:45 +08:00
Merge branch 'development'
This commit is contained in:
commit
56e76c4125
922
src/io_port.h
922
src/io_port.h
File diff suppressed because it is too large
Load Diff
@ -76,39 +76,15 @@ namespace etl
|
||||
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
|
||||
struct largest_type
|
||||
{
|
||||
private:
|
||||
|
||||
// Declaration.
|
||||
template <const bool Boolean, typename TrueType, typename FalseType>
|
||||
struct choose_type;
|
||||
|
||||
// Specialisation for 'true'.
|
||||
// Defines 'type' as 'TrueType'.
|
||||
template <typename TrueType, typename FalseType>
|
||||
struct choose_type<true, TrueType, FalseType>
|
||||
{
|
||||
typedef TrueType type;
|
||||
};
|
||||
|
||||
// Specialisation for 'false'.
|
||||
// Defines 'type' as 'FalseType'.
|
||||
template <typename TrueType, typename FalseType>
|
||||
struct choose_type<false, TrueType, FalseType>
|
||||
{
|
||||
typedef FalseType type;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
// Define 'largest_other' as 'largest_type' with all but the first parameter.
|
||||
typedef typename largest_type<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::type largest_other;
|
||||
|
||||
// Set 'type' to be the largest of the first parameter and any of the others.
|
||||
// This is recursive.
|
||||
typedef typename choose_type<(sizeof(T1) > sizeof(largest_other)), // Boolean
|
||||
T1, // TrueType
|
||||
largest_other> // FalseType
|
||||
::type type; // The largest type of the two.
|
||||
typedef typename etl::conditional<(sizeof(T1) > sizeof(largest_other)), // Boolean
|
||||
T1, // TrueType
|
||||
largest_other> // FalseType
|
||||
::type type; // The largest type of the two.
|
||||
|
||||
// The size of the largest type.
|
||||
enum
|
||||
@ -139,53 +115,40 @@ namespace etl
|
||||
///\ingroup largest
|
||||
//***************************************************************************
|
||||
template <typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
|
||||
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
|
||||
typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
|
||||
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
|
||||
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
|
||||
typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
|
||||
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
|
||||
struct largest_alignment
|
||||
{
|
||||
private:
|
||||
// Define 'largest_other' as 'largest_type' with all but the first parameter.
|
||||
typedef typename largest_alignment<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::type largest_other;
|
||||
|
||||
// Determine the largest size.
|
||||
template <const size_t size1, const size_t size2>
|
||||
struct max_size
|
||||
{
|
||||
enum
|
||||
{
|
||||
value = (size1 > size2) ? size1 : size2
|
||||
};
|
||||
};
|
||||
// Set 'type' to be the largest of the first parameter and any of the others.
|
||||
// This is recursive.
|
||||
typedef typename etl::conditional<(etl::alignment_of<T1>::value > etl::alignment_of<largest_other>::value), // Boolean
|
||||
T1, // TrueType
|
||||
largest_other> // FalseType
|
||||
::type type; // The largest type of the two.
|
||||
|
||||
// All of the alignments.
|
||||
// The largest alignment.
|
||||
enum
|
||||
{
|
||||
t1 = etl::alignment_of<T1>::value,
|
||||
t2 = etl::alignment_of<T2>::value,
|
||||
t3 = etl::alignment_of<T3>::value,
|
||||
t4 = etl::alignment_of<T4>::value,
|
||||
t5 = etl::alignment_of<T5>::value,
|
||||
t6 = etl::alignment_of<T6>::value,
|
||||
t7 = etl::alignment_of<T7>::value,
|
||||
t8 = etl::alignment_of<T8>::value,
|
||||
t9 = etl::alignment_of<T9>::value,
|
||||
t10 = etl::alignment_of<T10>::value,
|
||||
t11 = etl::alignment_of<T11>::value,
|
||||
t12 = etl::alignment_of<T12>::value,
|
||||
t13 = etl::alignment_of<T13>::value,
|
||||
t14 = etl::alignment_of<T14>::value,
|
||||
t15 = etl::alignment_of<T15>::value,
|
||||
t16 = etl::alignment_of<T16>::value
|
||||
value = etl::alignment_of<type>::value
|
||||
};
|
||||
};
|
||||
|
||||
public:
|
||||
//***************************************************************************
|
||||
// Specialisation for one template parameter.
|
||||
//***************************************************************************
|
||||
template <typename T1>
|
||||
struct largest_alignment<T1, void, void, void, void, void, void, void,
|
||||
void, void, void, void, void, void, void, void>
|
||||
{
|
||||
typedef T1 type;
|
||||
|
||||
// The largest of all of them.
|
||||
enum
|
||||
{
|
||||
value = max_size<t1, max_size<t2, max_size<t3, max_size<t4, max_size<t5, max_size<t6, max_size<t7, max_size<t8,
|
||||
max_size<t9, max_size<t10, max_size<t11, max_size<t12, max_size<t13, max_size<t14, max_size<t15, t16>
|
||||
::value>::value>::value>::value>::value>::value>::value>::value>
|
||||
::value>::value>::value>::value>::value>::value>::value
|
||||
value = etl::alignment_of<type>::value
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -93,30 +93,6 @@ namespace etl
|
||||
cog.outl("typename T%s = void>" % int(NTypes))
|
||||
cog.outl("struct largest_type")
|
||||
cog.outl("{")
|
||||
cog.outl("private:")
|
||||
cog.outl("")
|
||||
cog.outl(" // Declaration.")
|
||||
cog.outl(" template <const bool Boolean, typename TrueType, typename FalseType>")
|
||||
cog.outl(" struct choose_type;")
|
||||
cog.outl("")
|
||||
cog.outl(" // Specialisation for 'true'.")
|
||||
cog.outl(" // Defines 'type' as 'TrueType'.")
|
||||
cog.outl(" template <typename TrueType, typename FalseType>")
|
||||
cog.outl(" struct choose_type<true, TrueType, FalseType>")
|
||||
cog.outl(" {")
|
||||
cog.outl(" typedef TrueType type;")
|
||||
cog.outl(" };")
|
||||
cog.outl("")
|
||||
cog.outl(" // Specialisation for 'false'. ")
|
||||
cog.outl(" // Defines 'type' as 'FalseType'.")
|
||||
cog.outl(" template <typename TrueType, typename FalseType>")
|
||||
cog.outl(" struct choose_type<false, TrueType, FalseType>")
|
||||
cog.outl(" {")
|
||||
cog.outl(" typedef FalseType type;")
|
||||
cog.outl(" };")
|
||||
cog.outl("")
|
||||
cog.outl("public:")
|
||||
cog.outl("")
|
||||
cog.outl(" // Define 'largest_other' as 'largest_type' with all but the first parameter. ")
|
||||
cog.out(" typedef typename largest_type<")
|
||||
for n in range(2, int(NTypes)):
|
||||
@ -128,10 +104,10 @@ namespace etl
|
||||
cog.outl("")
|
||||
cog.outl(" // Set 'type' to be the largest of the first parameter and any of the others.")
|
||||
cog.outl(" // This is recursive.")
|
||||
cog.outl(" typedef typename choose_type<(sizeof(T1) > sizeof(largest_other)), // Boolean")
|
||||
cog.outl(" T1, // TrueType")
|
||||
cog.outl(" largest_other> // FalseType")
|
||||
cog.outl(" ::type type; // The largest type of the two.")
|
||||
cog.outl(" typedef typename etl::conditional<(sizeof(T1) > sizeof(largest_other)), // Boolean")
|
||||
cog.outl(" T1, // TrueType")
|
||||
cog.outl(" largest_other> // FalseType")
|
||||
cog.outl(" ::type type; // The largest type of the two.")
|
||||
cog.outl("")
|
||||
cog.outl(" // The size of the largest type.")
|
||||
cog.outl(" enum")
|
||||
@ -175,49 +151,50 @@ namespace etl
|
||||
cog.out("typename T%s = void, " % n)
|
||||
if n % 4 == 0:
|
||||
cog.outl("")
|
||||
cog.out(" ")
|
||||
cog.outl("typename T%s = void>" % NTypes)
|
||||
cog.out(" ")
|
||||
cog.outl("typename T%s = void>" % int(NTypes))
|
||||
cog.outl("struct largest_alignment")
|
||||
cog.outl("{")
|
||||
cog.outl("private:")
|
||||
cog.outl(" // Define 'largest_other' as 'largest_type' with all but the first parameter. ")
|
||||
cog.out(" typedef typename largest_alignment<")
|
||||
for n in range(2, int(NTypes)):
|
||||
cog.out("T%s, " % n)
|
||||
if n % 16 == 0:
|
||||
cog.outl("")
|
||||
cog.out(" ")
|
||||
cog.outl("T%s>::type largest_other;" % int(NTypes))
|
||||
cog.outl("")
|
||||
cog.outl(" // Determine the largest size.")
|
||||
cog.outl(" template <const size_t size1, const size_t size2>")
|
||||
cog.outl(" struct max_size")
|
||||
cog.outl(" {")
|
||||
cog.outl(" enum")
|
||||
cog.outl(" {")
|
||||
cog.outl(" value = (size1 > size2) ? size1 : size2")
|
||||
cog.outl(" };")
|
||||
cog.outl(" };")
|
||||
cog.outl(" // Set 'type' to be the largest of the first parameter and any of the others.")
|
||||
cog.outl(" // This is recursive.")
|
||||
cog.outl(" typedef typename etl::conditional<(etl::alignment_of<T1>::value > etl::alignment_of<largest_other>::value), // Boolean")
|
||||
cog.outl(" T1, // TrueType")
|
||||
cog.outl(" largest_other> // FalseType")
|
||||
cog.outl(" ::type type; // The largest type of the two.")
|
||||
cog.outl("")
|
||||
cog.outl(" // All of the alignments.")
|
||||
cog.outl(" // The largest alignment.")
|
||||
cog.outl(" enum")
|
||||
cog.outl(" {")
|
||||
for n in range(1, int(NTypes)):
|
||||
cog.outl(" t%s = etl::alignment_of<T%s>::value," %(n, n))
|
||||
cog.outl(" t%s = etl::alignment_of<T%s>::value" % (NTypes, NTypes))
|
||||
cog.outl(" value = etl::alignment_of<type>::value")
|
||||
cog.outl(" };")
|
||||
cog.outl("};")
|
||||
cog.outl("")
|
||||
cog.outl("public:")
|
||||
cog.outl("//***************************************************************************")
|
||||
cog.outl("// Specialisation for one template parameter.")
|
||||
cog.outl("//***************************************************************************")
|
||||
cog.outl("template <typename T1>")
|
||||
cog.out("struct largest_alignment<T1, ")
|
||||
for n in range(2, int(NTypes)):
|
||||
cog.out("void, ")
|
||||
if n % 8 == 0:
|
||||
cog.outl("")
|
||||
cog.out(" ")
|
||||
cog.outl("void>")
|
||||
cog.outl("{")
|
||||
cog.outl(" typedef T1 type;")
|
||||
cog.outl("")
|
||||
cog.outl(" // The largest of all of them.")
|
||||
cog.outl(" enum")
|
||||
cog.outl(" {")
|
||||
cog.out(" value = ")
|
||||
for n in range(1, int(NTypes)):
|
||||
cog.out("max_size<t%s, " %n)
|
||||
if n % 8 == 0:
|
||||
cog.outl("")
|
||||
cog.out(" ")
|
||||
cog.outl("t%s>" % int(NTypes))
|
||||
cog.out(" ")
|
||||
for n in range(1, int(NTypes) - 1):
|
||||
cog.out("::value>")
|
||||
if n % 8 == 0:
|
||||
cog.outl("")
|
||||
cog.out(" ")
|
||||
cog.outl("::value")
|
||||
cog.outl(" value = etl::alignment_of<type>::value")
|
||||
cog.outl(" };")
|
||||
cog.outl("};")
|
||||
]]]*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -72,6 +72,7 @@ cog.outl("//********************************************************************
|
||||
#include "error_handler.h"
|
||||
#include "exception.h"
|
||||
#include "largest.h"
|
||||
#include "nullptr.h"
|
||||
|
||||
#undef ETL_FILE
|
||||
#define ETL_FILE "35"
|
||||
@ -138,6 +139,12 @@ namespace etl
|
||||
return (message_router_id == MESSAGE_BUS);
|
||||
}
|
||||
|
||||
//********************************************
|
||||
void set_successor(imessage_router& successor_)
|
||||
{
|
||||
successor = &successor_;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
NULL_MESSAGE_ROUTER = 255,
|
||||
@ -148,11 +155,21 @@ namespace etl
|
||||
|
||||
protected:
|
||||
|
||||
imessage_router(etl::message_router_id_t id)
|
||||
: message_router_id(id)
|
||||
imessage_router(etl::message_router_id_t id_)
|
||||
: successor(nullptr),
|
||||
message_router_id(id_)
|
||||
{
|
||||
}
|
||||
|
||||
imessage_router(etl::message_router_id_t id_,
|
||||
imessage_router& successor_)
|
||||
: successor(&successor_),
|
||||
message_router_id(id_)
|
||||
{
|
||||
}
|
||||
|
||||
etl::imessage_router* successor;
|
||||
|
||||
private:
|
||||
|
||||
// Disabled.
|
||||
@ -313,10 +330,17 @@ namespace etl
|
||||
cog.outl(" };")
|
||||
cog.outl("")
|
||||
cog.outl(" //**********************************************")
|
||||
cog.outl(" message_router(etl::message_router_id_t id)")
|
||||
cog.outl(" : imessage_router(id)")
|
||||
cog.outl(" message_router(etl::message_router_id_t id_)")
|
||||
cog.outl(" : imessage_router(id_)")
|
||||
cog.outl(" {")
|
||||
cog.outl(" ETL_ASSERT(id <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
|
||||
cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //**********************************************")
|
||||
cog.outl(" message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)")
|
||||
cog.outl(" : imessage_router(id_, successor_)")
|
||||
cog.outl(" {")
|
||||
cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //**********************************************")
|
||||
@ -336,9 +360,18 @@ namespace etl
|
||||
cog.out(" case T%d::ID:" % n)
|
||||
cog.out(" static_cast<TDerived*>(this)->on_receive(source, static_cast<const T%d&>(msg));" % n)
|
||||
cog.outl(" break;")
|
||||
cog.out(" default:")
|
||||
cog.out(" static_cast<TDerived*>(this)->on_receive_unknown(source, msg);")
|
||||
cog.outl(" break;")
|
||||
cog.outl(" default:")
|
||||
cog.outl(" {")
|
||||
cog.outl(" if (successor != nullptr)")
|
||||
cog.outl(" {")
|
||||
cog.outl(" successor->receive(source, msg);")
|
||||
cog.outl(" }")
|
||||
cog.outl(" else")
|
||||
cog.outl(" {")
|
||||
cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(source, msg);")
|
||||
cog.outl(" }")
|
||||
cog.outl(" break;")
|
||||
cog.outl(" }")
|
||||
cog.outl(" }")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
@ -469,10 +502,17 @@ namespace etl
|
||||
cog.outl(" };")
|
||||
cog.outl("")
|
||||
cog.outl(" //**********************************************")
|
||||
cog.outl(" message_router(etl::message_router_id_t id)")
|
||||
cog.outl(" : imessage_router(id)")
|
||||
cog.outl(" message_router(etl::message_router_id_t id_)")
|
||||
cog.outl(" : imessage_router(id_)")
|
||||
cog.outl(" {")
|
||||
cog.outl(" ETL_ASSERT(id <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
|
||||
cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //**********************************************")
|
||||
cog.outl(" message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)")
|
||||
cog.outl(" : imessage_router(id_, successor_)")
|
||||
cog.outl(" {")
|
||||
cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //**********************************************")
|
||||
@ -492,9 +532,18 @@ namespace etl
|
||||
cog.out(" case T%d::ID:" % t)
|
||||
cog.out(" static_cast<TDerived*>(this)->on_receive(source, static_cast<const T%d&>(msg));" % t)
|
||||
cog.outl(" break;")
|
||||
cog.out(" default:")
|
||||
cog.out(" static_cast<TDerived*>(this)->on_receive_unknown(source, msg);")
|
||||
cog.outl(" break;")
|
||||
cog.outl(" default:")
|
||||
cog.outl(" {")
|
||||
cog.outl(" if (successor != nullptr)")
|
||||
cog.outl(" {")
|
||||
cog.outl(" successor->receive(source, msg);")
|
||||
cog.outl(" }")
|
||||
cog.outl(" else")
|
||||
cog.outl(" {")
|
||||
cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(source, msg);")
|
||||
cog.outl(" }")
|
||||
cog.outl(" break;")
|
||||
cog.outl(" }")
|
||||
cog.outl(" }")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
|
||||
@ -65,11 +65,6 @@ namespace etl
|
||||
static const uint64_t value = 1;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Declaration of static 'value' for power.
|
||||
//***************************************************************************
|
||||
template <const size_t NV, const size_t POWER> const uint64_t power<NV, POWER>::value;
|
||||
|
||||
//***************************************************************************
|
||||
///\ingroup power
|
||||
/// Calculates the rounded up power of 2.
|
||||
|
||||
@ -54,10 +54,10 @@ SOFTWARE.
|
||||
#define __ETL_TYPE_TRAITS__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "platform.h"
|
||||
#include "nullptr.h"
|
||||
#include "static_assert.h"
|
||||
|
||||
#if (ETL_CPP11_SUPPORTED)
|
||||
#include <type_traits>
|
||||
@ -318,6 +318,25 @@ namespace etl
|
||||
template <bool B, typename T, typename F> struct conditional { typedef T type; };
|
||||
template <typename T, typename F> struct conditional<false, T, F> { typedef F type; };
|
||||
|
||||
/// conditional_integral_constant
|
||||
///\ingroup type_traits
|
||||
template <bool B, typename T, T TRUE_VALUE, T FALSE_VALUE>
|
||||
struct conditional_integral_constant;
|
||||
|
||||
template <typename T, T TRUE_VALUE, T FALSE_VALUE>
|
||||
struct conditional_integral_constant<true, T, TRUE_VALUE, FALSE_VALUE>
|
||||
{
|
||||
STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type");
|
||||
static const T value = TRUE_VALUE;
|
||||
};
|
||||
|
||||
template <typename T, T TRUE_VALUE, T FALSE_VALUE>
|
||||
struct conditional_integral_constant<false, T, TRUE_VALUE, FALSE_VALUE>
|
||||
{
|
||||
STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type");
|
||||
static const T value = FALSE_VALUE;
|
||||
};
|
||||
|
||||
/// make_signed
|
||||
///\ingroup type_traits
|
||||
template <typename T> struct make_signed { typedef T type; };
|
||||
@ -417,10 +436,10 @@ namespace etl
|
||||
|
||||
/// is_base_of
|
||||
///\ingroup type_traits
|
||||
template<typename TBase,
|
||||
typename TDerived,
|
||||
const bool IsFundamental = (etl::is_fundamental<TBase>::value || etl::is_fundamental<TDerived>::value)>
|
||||
struct is_base_of
|
||||
template<typename TBase,
|
||||
typename TDerived,
|
||||
const bool IsFundamental = (etl::is_fundamental<TBase>::value || etl::is_fundamental<TDerived>::value)>
|
||||
struct is_base_of
|
||||
{
|
||||
private:
|
||||
|
||||
@ -441,7 +460,7 @@ namespace etl
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
|
||||
/// Alignment templates.
|
||||
/// These require compiler specific intrinsics.
|
||||
///\ingroup type_traits
|
||||
@ -465,14 +484,14 @@ namespace etl
|
||||
///\ingroup types
|
||||
//***************************************************************************
|
||||
template <typename T,
|
||||
typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
|
||||
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
|
||||
typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
|
||||
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void,
|
||||
typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
|
||||
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
|
||||
typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
|
||||
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void,
|
||||
typename T17 = void>
|
||||
struct is_one_of
|
||||
{
|
||||
static const bool value =
|
||||
static const bool value =
|
||||
etl::is_same<T, T1>::value ||
|
||||
etl::is_same<T, T2>::value ||
|
||||
etl::is_same<T, T3>::value ||
|
||||
|
||||
@ -69,6 +69,7 @@ cog.outl("//********************************************************************
|
||||
|
||||
#include "platform.h"
|
||||
#include "nullptr.h"
|
||||
#include "static_assert.h"
|
||||
|
||||
#if (ETL_CPP11_SUPPORTED)
|
||||
#include <type_traits>
|
||||
@ -329,6 +330,22 @@ namespace etl
|
||||
template <bool B, typename T, typename F> struct conditional { typedef T type; };
|
||||
template <typename T, typename F> struct conditional<false, T, F> { typedef F type; };
|
||||
|
||||
/// conditional_integral_constant
|
||||
///\ingroup type_traits
|
||||
template <bool B, typename T, T TRUE_VALUE, T FALSE_VALUE>
|
||||
struct conditional_integral_constant
|
||||
{
|
||||
STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type");
|
||||
static const T value = TRUE_VALUE;
|
||||
};
|
||||
|
||||
template <typename T, T TRUE_VALUE, T FALSE_VALUE>
|
||||
struct conditional_integral_constant<false, T, TRUE_VALUE, FALSE_VALUE>
|
||||
{
|
||||
STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type");
|
||||
static const T value = FALSE_VALUE;
|
||||
};
|
||||
|
||||
/// make_signed
|
||||
///\ingroup type_traits
|
||||
template <typename T> struct make_signed { typedef T type; };
|
||||
|
||||
@ -41,6 +41,11 @@ SOFTWARE.
|
||||
#pragma warning(disable:4101) // Unused variable.
|
||||
#endif
|
||||
|
||||
uint8_t rw = 0x12;
|
||||
uint8_t ro = 0x34;
|
||||
uint8_t wo = 0x56;
|
||||
uint8_t wos = 0x78;
|
||||
|
||||
namespace
|
||||
{
|
||||
template <uintptr_t ADDRESS>
|
||||
@ -123,8 +128,8 @@ namespace
|
||||
CHECK_EQUAL(0xDE, port.control2);
|
||||
|
||||
port.control2.set_address(0x1000);
|
||||
uint8_t* address = port.control2.get_address();
|
||||
CHECK_EQUAL(reinterpret_cast<uint8_t* const>(0x1000), address);
|
||||
volatile uint8_t* address = port.control2.get_address();
|
||||
CHECK_EQUAL(reinterpret_cast<volatile uint8_t*>(0x1000), address);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -144,9 +149,7 @@ namespace
|
||||
std::array<uint8_t, 10> result;
|
||||
|
||||
// Read from RW IOP.
|
||||
etl::io_port_rw<uint8_t>::iterator itr_rw = iop_rw.get_iterator();
|
||||
|
||||
std::copy_n(itr_rw, result.size(), result.begin());
|
||||
std::copy_n(iop_rw, result.size(), result.begin());
|
||||
compare.fill(0x12);
|
||||
|
||||
for (size_t i = 0; i < compare.size(); ++i)
|
||||
@ -156,14 +159,12 @@ namespace
|
||||
|
||||
// Write to RW IOP.
|
||||
compare.fill(0x34);
|
||||
std::copy_n(compare.begin(), compare.size(), itr_rw);
|
||||
std::copy_n(compare.begin(), compare.size(), iop_rw);
|
||||
|
||||
CHECK_EQUAL(compare[0], iop_rw);
|
||||
|
||||
// Read from RO IOP.
|
||||
etl::io_port_ro<uint8_t>::iterator itr_ro = iop_ro.get_iterator();
|
||||
|
||||
std::copy_n(itr_ro, result.size(), result.begin());
|
||||
std::copy_n(iop_ro, result.size(), result.begin());
|
||||
compare.fill(0x34);
|
||||
|
||||
for (size_t i = 0; i < compare.size(); ++i)
|
||||
@ -172,19 +173,15 @@ namespace
|
||||
}
|
||||
|
||||
// Write to WO IOP.
|
||||
etl::io_port_wo<uint8_t>::iterator itr_wo = iop_wo.get_iterator();
|
||||
|
||||
compare.fill(0x56);
|
||||
std::copy_n(compare.begin(), compare.size(), itr_wo);
|
||||
std::copy_n(compare.begin(), compare.size(), iop_wo);
|
||||
|
||||
CHECK_EQUAL(compare[0], memory_wo);
|
||||
|
||||
// Read from WOS IOP.
|
||||
etl::io_port_wos<uint8_t>::iterator itr_wos = iop_wos.get_iterator();
|
||||
iop_wos = 0x78;
|
||||
|
||||
*itr_wos = 0x78;
|
||||
|
||||
std::copy_n(itr_wos, result.size(), result.begin());
|
||||
std::copy_n(iop_wos, result.size(), result.begin());
|
||||
compare.fill(0x78);
|
||||
|
||||
for (size_t i = 0; i < compare.size(); ++i)
|
||||
@ -194,10 +191,32 @@ namespace
|
||||
|
||||
// Write to WOS IOP.
|
||||
compare.fill(0x90);
|
||||
std::copy_n(compare.begin(), compare.size(), itr_wos);
|
||||
std::copy_n(compare.begin(), compare.size(), iop_wos.get_iterator());
|
||||
|
||||
CHECK_EQUAL(compare[0], iop_wos);
|
||||
}
|
||||
|
||||
TEST(compile)
|
||||
{
|
||||
// etl::io_port_rw<uint8_t, uintptr_t(1)> p_rw;
|
||||
// etl::io_port_ro<uint8_t, uintptr_t(2)> p_ro;
|
||||
// etl::io_port_wo<uint8_t, uintptr_t(3)> p_wo;
|
||||
// etl::io_port_wos<uint8_t, uintptr_t(4)> p_wos;
|
||||
|
||||
// uint8_t c;
|
||||
|
||||
// *p_rw = 1;
|
||||
// c = *p_rw;
|
||||
|
||||
// *p_ro = 1;
|
||||
// c = *p_ro;
|
||||
|
||||
// *p_wo = 1;
|
||||
// c = *p_wo;
|
||||
|
||||
// *p_wos = 1;
|
||||
// c = *p_wos;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -417,5 +417,62 @@ namespace
|
||||
CHECK_EQUAL(4, r1.callback_count);
|
||||
queue.pop();
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
TEST(message_router_successor)
|
||||
{
|
||||
Router1 r1;
|
||||
Router2 r2;
|
||||
|
||||
r2.set_successor(r1);
|
||||
|
||||
etl::send_message(r2, message1);
|
||||
CHECK_EQUAL(1, r2.message1_count);
|
||||
CHECK_EQUAL(0, r2.message2_count);
|
||||
CHECK_EQUAL(0, r2.message4_count);
|
||||
CHECK_EQUAL(0, r2.message_unknown_count);
|
||||
|
||||
CHECK_EQUAL(0, r1.message1_count);
|
||||
CHECK_EQUAL(0, r1.message2_count);
|
||||
CHECK_EQUAL(0, r1.message3_count);
|
||||
CHECK_EQUAL(0, r1.message4_count);
|
||||
CHECK_EQUAL(0, r1.message_unknown_count);
|
||||
|
||||
etl::send_message(r2, message2);
|
||||
CHECK_EQUAL(1, r2.message1_count);
|
||||
CHECK_EQUAL(1, r2.message2_count);
|
||||
CHECK_EQUAL(0, r2.message4_count);
|
||||
CHECK_EQUAL(0, r2.message_unknown_count);
|
||||
|
||||
CHECK_EQUAL(0, r1.message1_count);
|
||||
CHECK_EQUAL(0, r1.message2_count);
|
||||
CHECK_EQUAL(0, r1.message3_count);
|
||||
CHECK_EQUAL(0, r1.message4_count);
|
||||
CHECK_EQUAL(0, r1.message_unknown_count);
|
||||
|
||||
etl::send_message(r2, message3);
|
||||
CHECK_EQUAL(1, r2.message1_count);
|
||||
CHECK_EQUAL(1, r2.message2_count);
|
||||
CHECK_EQUAL(0, r2.message4_count);
|
||||
CHECK_EQUAL(0, r2.message_unknown_count);
|
||||
|
||||
CHECK_EQUAL(0, r1.message1_count);
|
||||
CHECK_EQUAL(0, r1.message2_count);
|
||||
CHECK_EQUAL(1, r1.message3_count);
|
||||
CHECK_EQUAL(0, r1.message4_count);
|
||||
CHECK_EQUAL(0, r1.message_unknown_count);
|
||||
|
||||
etl::send_message(r2, message4);
|
||||
CHECK_EQUAL(1, r2.message1_count);
|
||||
CHECK_EQUAL(1, r2.message2_count);
|
||||
CHECK_EQUAL(1, r2.message4_count);
|
||||
CHECK_EQUAL(0, r2.message_unknown_count);
|
||||
|
||||
CHECK_EQUAL(0, r1.message1_count);
|
||||
CHECK_EQUAL(0, r1.message2_count);
|
||||
CHECK_EQUAL(1, r1.message3_count);
|
||||
CHECK_EQUAL(0, r1.message4_count);
|
||||
CHECK_EQUAL(0, r1.message_unknown_count);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -716,4 +716,14 @@ namespace
|
||||
CHECK((std::is_same<const int* const, etl::types<const volatile int&>::const_pointer_const>::value));
|
||||
}
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
TEST(conditional_integral_constant)
|
||||
{
|
||||
int v1 = etl::conditional_integral_constant<true, int, 1, 2>::value;
|
||||
int v2 = etl::conditional_integral_constant<false, int, 1, 2>::value;
|
||||
|
||||
CHECK_EQUAL(1, v1);
|
||||
CHECK_EQUAL(2, v2);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user