mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added observer<void> as a specialisation for C++03 code
This commit is contained in:
parent
a1e1207c0c
commit
c61f493a01
@ -498,6 +498,19 @@ namespace etl
|
||||
virtual void notification(T1) = 0;
|
||||
};
|
||||
|
||||
//*********************************************************************
|
||||
/// The observer interface for void argument notification type.
|
||||
///\ingroup observer
|
||||
//*********************************************************************
|
||||
template <>
|
||||
class observer<void>
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~observer() {}
|
||||
virtual void notification() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ SOFTWARE.
|
||||
|
||||
#define ETL_VERSION_MAJOR 20
|
||||
#define ETL_VERSION_MINOR 39
|
||||
#define ETL_VERSION_PATCH 0
|
||||
#define ETL_VERSION_PATCH 1
|
||||
|
||||
#define ETL_VERSION ETL_STRING(ETL_VERSION_MAJOR) "." ETL_STRING(ETL_VERSION_MINOR) "." ETL_STRING(ETL_VERSION_PATCH)
|
||||
#define ETL_VERSION_W ETL_WIDE_STRING(ETL_VERSION_MAJOR) L"." ETL_WIDE_STRING(ETL_VERSION_MINOR) L"." ETL_WIDE_STRING(ETL_VERSION_PATCH)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Embedded Template Library",
|
||||
"version": "20.39.0",
|
||||
"version": "20.39.1",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library
|
||||
version=20.39.0
|
||||
version=20.39.1
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
@ -1,4 +1,10 @@
|
||||
===============================================================================
|
||||
20.39.1
|
||||
|
||||
#940 Allow etl::observer notification without argument
|
||||
Added a void specialisation to the < C++11 code.
|
||||
|
||||
===============================================================================
|
||||
20.39.0
|
||||
|
||||
Refactored:
|
||||
|
||||
@ -75,6 +75,11 @@ namespace
|
||||
// The observer base type that does not take a notification type.
|
||||
//*****************************************************************************
|
||||
typedef etl::observer<void, int> ObserverVoidIntType;
|
||||
#else
|
||||
//*****************************************************************************
|
||||
// The observer base type that does not take a notification type.
|
||||
//*****************************************************************************
|
||||
typedef etl::observer<void> ObserverVoidType;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -141,6 +146,22 @@ public:
|
||||
notify_observers(n);
|
||||
}
|
||||
};
|
||||
#else
|
||||
//*****************************************************************************
|
||||
// The concrete observable 3 class.
|
||||
//*****************************************************************************
|
||||
class ObservableVoid : public etl::observable<ObserverVoidType, 2>
|
||||
{
|
||||
public:
|
||||
|
||||
//*********************************
|
||||
// Notify all of the observers.
|
||||
//*********************************
|
||||
void send_notifications()
|
||||
{
|
||||
notify_observers();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
@ -260,6 +281,32 @@ public:
|
||||
// Notification2
|
||||
//*******************************************
|
||||
void notification(int) override
|
||||
{
|
||||
++data2_count;
|
||||
}
|
||||
|
||||
int data1_count;
|
||||
int data2_count;
|
||||
};
|
||||
#else
|
||||
//*****************************************************************************
|
||||
// The third observer type.
|
||||
// If any one of the overloads is missing or a parameter declaration is incorrect
|
||||
// then the class will be 'abstract' and will not compile.
|
||||
//*****************************************************************************
|
||||
class ObserverVoid : public ObserverVoidType
|
||||
{
|
||||
public:
|
||||
|
||||
ObserverVoid()
|
||||
: data1_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
// Notification1
|
||||
//*******************************************
|
||||
void notification() override
|
||||
{
|
||||
++data1_count;
|
||||
}
|
||||
@ -572,6 +619,21 @@ namespace
|
||||
observable.send_notifications();
|
||||
observable.send_notifications(1);
|
||||
}
|
||||
#else
|
||||
//*************************************************************************
|
||||
TEST(test_void_observable)
|
||||
{
|
||||
// The observable objects.
|
||||
ObservableVoid observable;
|
||||
|
||||
// The observer objects.
|
||||
ObserverVoid observer;
|
||||
|
||||
observable.add_observer(observer);
|
||||
|
||||
// Send the notifications.
|
||||
observable.send_notifications();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +1 @@
|
||||
20.39.0
|
||||
20.39.1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user