mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Updated version and release notes
This commit is contained in:
parent
8c47217982
commit
86b147d2a4
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Embedded Template Library - Arduino",
|
||||
"version": "20.37.0",
|
||||
"version": "20.37.1",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library - Arduino
|
||||
version=20.37.0
|
||||
version=20.37.1
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
262
include/etl/delegate_observer.h
Normal file
262
include/etl/delegate_observer.h
Normal file
@ -0,0 +1,262 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2023 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_DELEGATE_OBSERVER_INCLUDED
|
||||
#define ETL_DELEGATE_OBSERVER_INCLUDED
|
||||
|
||||
#include "algorithm.h"
|
||||
|
||||
#include "platform.h"
|
||||
#include "delegate.h"
|
||||
#include "vector.h"
|
||||
#include "exception.h"
|
||||
#include "error_handler.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
///\ingroup observer
|
||||
/// The base class for delegate observer exceptions.
|
||||
//***************************************************************************
|
||||
class delegate_observer_exception : public exception
|
||||
{
|
||||
public:
|
||||
|
||||
delegate_observer_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
///\ingroup observer
|
||||
/// The exception thrown when the delegate observer list is full.
|
||||
//***************************************************************************
|
||||
class delegate_observer_list_full : public delegate_observer_exception
|
||||
{
|
||||
public:
|
||||
|
||||
delegate_observer_list_full(string_type file_name_, numeric_type line_number_)
|
||||
: delegate_observer_exception(ETL_ERROR_TEXT("delegate_observable:full", ETL_DELEGATE_OBSERVER_FILE_ID"A"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*********************************************************************
|
||||
/// The object that is being observed.
|
||||
///\tparam MAX_OBSERVERS The maximum number of observers that can be accommodated.
|
||||
///\ingroup observer
|
||||
//*********************************************************************
|
||||
template <typename TNotification, const size_t MAX_OBSERVERS>
|
||||
class delegate_observable
|
||||
{
|
||||
public:
|
||||
|
||||
typedef etl::delegate<void(TNotification)> observer_type;
|
||||
|
||||
private:
|
||||
|
||||
//***********************************
|
||||
// Item stored in the observer list.
|
||||
//***********************************
|
||||
struct observer_item
|
||||
{
|
||||
observer_item(observer_type observer_)
|
||||
: observer(observer_)
|
||||
, enabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
observer_type observer;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
//***********************************
|
||||
// How to compare an observer with an observer list item.
|
||||
//***********************************
|
||||
struct compare_observers
|
||||
{
|
||||
compare_observers(observer_type& observer_)
|
||||
: observer(&observer_)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator ()(const observer_item& item) const
|
||||
{
|
||||
return observer == item.observer;
|
||||
}
|
||||
|
||||
observer_type observer;
|
||||
};
|
||||
|
||||
typedef etl::vector<observer_item, MAX_OBSERVERS> Observer_List;
|
||||
|
||||
public:
|
||||
|
||||
typedef size_t size_type;
|
||||
typedef TNotification notification_type;
|
||||
|
||||
//*****************************************************************
|
||||
/// Add an observer to the list.
|
||||
/// If asserts or exceptions are enabled then an etl::observable_observer_list_full
|
||||
/// is emitted if the observer list is already full.
|
||||
///\param observer A reference to the observer.
|
||||
//*****************************************************************
|
||||
void add_observer(observer_type& observer)
|
||||
{
|
||||
// See if we already have it in our list.
|
||||
typename Observer_List::iterator i_observer_item = find_observer(observer);
|
||||
|
||||
// Not there?
|
||||
if (i_observer_item == observer_list.end())
|
||||
{
|
||||
// Is there enough room?
|
||||
ETL_ASSERT_OR_RETURN(!observer_list.full(), ETL_ERROR(etl::observer_list_full));
|
||||
|
||||
// Add it.
|
||||
observer_list.push_back(observer_item(observer));
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************
|
||||
/// Remove a particular observer from the list.
|
||||
///\param observer A reference to the observer.
|
||||
///\return <b>true</b> if the observer was removed, <b>false</b> if not.
|
||||
//*****************************************************************
|
||||
bool remove_observer(observer_type& observer)
|
||||
{
|
||||
// See if we have it in our list.
|
||||
typename Observer_List::iterator i_observer_item = find_observer(observer);
|
||||
|
||||
// Found it?
|
||||
if (i_observer_item != observer_list.end())
|
||||
{
|
||||
// Erase it.
|
||||
observer_list.erase(i_observer_item);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************
|
||||
/// Enable an observer
|
||||
///\param observer A reference to the observer.
|
||||
///\param state <b>true</b> to enable, <b>false</b> to disable. Default is enable.
|
||||
//*****************************************************************
|
||||
void enable_observer(observer_type& observer, bool state = true)
|
||||
{
|
||||
// See if we have it in our list.
|
||||
typename Observer_List::iterator i_observer_item = find_observer(observer);
|
||||
|
||||
// Found it?
|
||||
if (i_observer_item != observer_list.end())
|
||||
{
|
||||
i_observer_item->enabled = state;
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************
|
||||
/// Disable an observer
|
||||
//*****************************************************************
|
||||
void disable_observer(observer_type& observer)
|
||||
{
|
||||
// See if we have it in our list.
|
||||
typename Observer_List::iterator i_observer_item = find_observer(observer);
|
||||
|
||||
// Found it?
|
||||
if (i_observer_item != observer_list.end())
|
||||
{
|
||||
i_observer_item->enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************
|
||||
/// Clear all observers from the list.
|
||||
//*****************************************************************
|
||||
void clear_observers()
|
||||
{
|
||||
observer_list.clear();
|
||||
}
|
||||
|
||||
//*****************************************************************
|
||||
/// Returns the number of observers.
|
||||
//*****************************************************************
|
||||
size_type number_of_observers() const
|
||||
{
|
||||
return observer_list.size();
|
||||
}
|
||||
|
||||
//*****************************************************************
|
||||
/// Notify all of the observers, sending them the notification.
|
||||
///\tparam TNotification The notification type.
|
||||
///\param n The notification.
|
||||
//*****************************************************************
|
||||
void notify_observers(TNotification n)
|
||||
{
|
||||
typename Observer_List::iterator i_observer_item = observer_list.begin();
|
||||
|
||||
while (i_observer_item != observer_list.end())
|
||||
{
|
||||
if (i_observer_item->enabled)
|
||||
{
|
||||
i_observer_item->p_observer->notification(n);
|
||||
}
|
||||
|
||||
++i_observer_item;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
~observable()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//*****************************************************************
|
||||
/// Find an observer in the list.
|
||||
/// Returns the end of the list if not found.
|
||||
//*****************************************************************
|
||||
typename Observer_List::iterator find_observer(observer_type& observer_)
|
||||
{
|
||||
return etl::find_if(observer_list.begin(), observer_list.end(), compare_observers(observer_));
|
||||
}
|
||||
|
||||
/// The list of observers.
|
||||
Observer_List observer_list;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -40,7 +40,7 @@ SOFTWARE.
|
||||
|
||||
#define ETL_VERSION_MAJOR 20
|
||||
#define ETL_VERSION_MINOR 37
|
||||
#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.37.0",
|
||||
"version": "20.37.1",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library
|
||||
version=20.37.0
|
||||
version=20.37.1
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
===============================================================================
|
||||
20.37.1
|
||||
Fixed etl::optional arrow and dereference operators.
|
||||
|
||||
===============================================================================
|
||||
20.37.0
|
||||
#708 Fix missing class key with friend.
|
||||
|
||||
@ -539,10 +539,52 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_optional_pod_assign_bug_714)
|
||||
{
|
||||
etl::optional<int> o = 42;
|
||||
o = etl::nullopt;
|
||||
etl::optional<int> opt = 42;
|
||||
opt = etl::nullopt;
|
||||
|
||||
CHECK_EQUAL(false, o.has_value());
|
||||
CHECK_EQUAL(false, opt.has_value());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_dereference_operator_bug_730)
|
||||
{
|
||||
etl::optional<int> opt = 42;
|
||||
|
||||
CHECK_EQUAL(42, *opt);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_const_dereference_operator_bug_730)
|
||||
{
|
||||
const etl::optional<int> opt = 42;
|
||||
|
||||
CHECK_EQUAL(42, *opt);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_arrow_operator_bug_730)
|
||||
{
|
||||
struct Object
|
||||
{
|
||||
int value;
|
||||
};
|
||||
|
||||
etl::optional<Object> opt = Object{ 42 };
|
||||
|
||||
CHECK_EQUAL(42, opt->value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_const_arrow_operator_bug_730)
|
||||
{
|
||||
struct Object
|
||||
{
|
||||
int value;
|
||||
};
|
||||
|
||||
const etl::optional<Object> opt = Object{ 42 };
|
||||
|
||||
CHECK_EQUAL(42, opt->value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -3398,9 +3398,6 @@
|
||||
<ClCompile Include="..\test_result.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_expected.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\sanity-check\expected.h.t.cpp">
|
||||
<Filter>Tests\Syntax Checks\Source</Filter>
|
||||
</ClCompile>
|
||||
@ -3416,6 +3413,9 @@
|
||||
<ClCompile Include="..\test_intrusive_links.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_expected.cpp">
|
||||
<Filter>Tests\Misc</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
|
||||
@ -1 +1 @@
|
||||
20.37.0
|
||||
20.37.1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user