Skip to content

Commit

Permalink
Added observer<void> as a specialisation for C++03 code
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wellbelove committed Aug 1, 2024
1 parent a1e1207 commit c61f493
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 4 deletions.
13 changes: 13 additions & 0 deletions include/etl/observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion include/etl/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions support/Release notes.txt
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
62 changes: 62 additions & 0 deletions test/test_observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -141,6 +146,22 @@ class ObservableVoidInt : public etl::observable<ObserverVoidIntType, 2>
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

//*****************************************************************************
Expand Down Expand Up @@ -260,6 +281,32 @@ class ObserverVoidInt : public ObserverVoidIntType
// 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;
}
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.39.0
20.39.1

0 comments on commit c61f493

Please sign in to comment.