Initial code

This commit is contained in:
John Wellbelove 2022-03-26 20:09:08 +00:00 committed by John Wellbelove
parent e3dac1e33e
commit d5c8b7c9f8
9 changed files with 273 additions and 301 deletions

View File

@ -1,33 +0,0 @@
#pragma once
#include "platform.h"
template <typename TDestination, typename TSource>
typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) &&
etl::is_trivially_copyable<TSource>::value &&
etl::is_trivially_copyable<TDestination>::value, TDestination>::type
bit_cast(const TSource& source) ETL_NOEXCEPT
{
TDestination destination;
memcpy(&destination, &source, sizeof(TDestination));
return destination;
}
template <typename TDestination, typename TSource>
ETL_CONSTEXPR
typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) &&
etl::is_trivially_copyable<TSource>::value &&
etl::is_trivially_copyable<TDestination>::value, TDestination>::type
bit_cast(const TSource& source) ETL_NOEXCEPT
{
TDestination destination;
__builtin_memcpy(&destination, &source, sizeof(TDestination));
return destination;
}

View File

@ -1,181 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2021 jwellbelove
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_CLASS_TRAITS_INCLUDED
#define ETL_CLASS_TRAITS_INCLUDED
#include <stddef.h>
#include <stdint.h>
#include <utility>
#include "platform.h"
#if ETL_CPP11_SUPPORTED
namespace etl
{
#if ETL_CPP11_SUPPORTED
//***************************************************************************
/// has_member_function_begin
//***************************************************************************
template <typename T>
class has_begin
{
typedef char one;
struct two { char x[2]; };
template <typename C> static constexpr one test(decltype(&C::begin)*);
template <typename C> static constexpr two test(...);
public:
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
};
#if ETL_CPP17_SUPPORTED
template <typename T>
static constexpr bool has_begin_v = has_begin<T>::value;
#endif
//***************************************************************************
/// has_member_function_end
//***************************************************************************
template <typename T>
class has_end
{
typedef char one;
struct two { char x[2]; };
template <typename C> static constexpr one test(decltype(std::declval<C>().end()));
template <typename C> static constexpr two test(...);
public:
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
};
#if ETL_CPP17_SUPPORTED
template <typename T>
static constexpr bool has_end_v = hasend<T>::value;
#endif
//***************************************************************************
/// has_member_function_size
//***************************************************************************
template <typename T>
class has_size
{
typedef char one;
struct two { char x[2]; };
template <typename C> static one test(decltype(std::declval<C>().size()));
template <typename C> static two test(...);
public:
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
};
#if ETL_CPP17_SUPPORTED
template <typename T>
static constexpr bool has_size_v = has_size<T>::value;
#endif
//***************************************************************************
/// has_member_function_max_size
//***************************************************************************
template <typename T>
class has_max_size
{
typedef char one;
struct two { char x[2]; };
template <typename C> static one test(decltype(std::declval<C>().max_size()));
template <typename C> static two test(...);
public:
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
};
#if ETL_CPP17_SUPPORTED
template <typename T>
static constexpr bool has_max_size_v = has_max_size<T>::value;
#endif
//***************************************************************************
/// has_member_function_empty
//***************************************************************************
template <typename T>
class has_empty
{
typedef char one;
struct two { char x[2]; };
template <typename C> static constexpr one test(decltype(std::declval<C>().empty()));
template <typename C> static constexpr two test(...);
public:
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
};
#if ETL_CPP17_SUPPORTED
template <typename T>
static constexpr bool has_empty_v = has_empty<T>::value;
#endif
//***************************************************************************
/// has_member_function_data
//***************************************************************************
template <typename T>
class has_data
{
typedef char one;
struct two { char x[2]; };
template <typename C> static constexpr one test(decltype(std::declval<C>().data()));
template <typename C> static constexpr two test(...);
public:
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
};
#if ETL_CPP17_SUPPORTED
template <typename T>
static constexpr bool has_data_v = has_data<T>::value;
#endif
#endif
}
#endif
#endif // ETL_CLASS_TRAITS_INCLUDED

Binary file not shown.

Before

Width:  |  Height:  |  Size: 904 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 490 KiB

View File

@ -1,87 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2021 jwellbelove
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_SINGLETON_INCLUDED
#define ETL_SINGLETON_INCLUDED
#include "platform.h"
namespace etl
{
//***************************************************************************
/// Creates .
//***************************************************************************
template <typename TObject>
class singleton
{
public:
static TObject& get_instance()
{
return p_instance.get();
}
protected:
static TObject* p_instance;
private:
singleton() ETL_DELETE;
singleton(const singleton&) ETL_DELETE;
singleton& operator =(const singleton&) ETL_DELETE;
};
template <typename TSingleton>
class singleton_factory
{
virtual ~singleton_factory() {}
template <typename... TArgs>
TSingleton* create(TArgs args...)
{
if (is_created)
{
return TSingleton::mp_Instance.get();
}
is_created = true;
static Singleton Tmp;
_TSingleton::mp_Instance.reset(pTmp);
return _TSingleton::mp_Instance.get();
}
};
}
#endif

265
include/etl/persistence.h Normal file
View File

@ -0,0 +1,265 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2021 jwellbelove
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_PERSISTENCE_INCLUDED
#define ETL_PERSISTENCE_INCLUDED
#include "platform.h"
#include "memory.h"
#include "type_traits.h"
#include "error_handler.h"
#include "exception.h"
namespace etl
{
namespace experimental
{
//***************************************************************************
/// Exception base for persistence
//***************************************************************************
class persistence_exception : public etl::exception
{
public:
persistence_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
: exception(reason_, file_name_, line_number_)
{
}
};
//***************************************************************************
/// Size mismatch error
//***************************************************************************
class persistence_size_mismatch : public etl::experimental::persistence_exception
{
public:
persistence_size_mismatch(string_type file_name_, numeric_type line_number_)
: persistence_exception(ETL_ERROR_TEXT("persistence:size mismatch", ETL_PERSISTENCE_FILE_ID"A"), file_name_, line_number_)
{
}
};
//***************************************************************************
/// Persistence interface.
//***************************************************************************
class ipersistence
{
public:
virtual ~ipersistence()
{
}
virtual void start() = 0;
virtual void step(size_t n) = 0;
virtual void save(const char* data, size_t length) = 0;
virtual void load(char* data, size_t length) = 0;
virtual void flush() = 0;
struct stepper
{
stepper(size_t n_)
: n(n_)
{
}
size_t n;
};
};
//***************************************************************************
/// Persistence size calculator.
//***************************************************************************
class persistence_profiler : public ipersistence
{
public:
persistence_profiler()
: index(0U)
{
}
void start() ETL_OVERRIDE
{
index = 0U;
}
void step(size_t n) ETL_OVERRIDE
{
index += n;
}
void save(const char* data, size_t length) ETL_OVERRIDE
{
index += length;
}
void load(char* data, size_t length) ETL_OVERRIDE
{
}
void flush() ETL_OVERRIDE
{
}
size_t size() const
{
return index;
}
private:
size_t index;
};
//***************************************************************************
/// Generic Save Persistent.
//***************************************************************************
template <typename T>
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value || etl::is_pointer<T>::value || etl::is_trivially_copyable<T>::value, void>::type
persistence_save(etl::experimental::ipersistence& persistence, T value)
{
T temp(value);
const char* pvalue = reinterpret_cast<const char*>(&temp);
size_t length = sizeof(temp);
persistence.save(pvalue, length);
}
//***************************************************************************
/// Generic Load Persistent.
//***************************************************************************
template <typename T>
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value || etl::is_pointer<T>::value || etl::is_trivially_copyable<T>::value, void>::type
persistence_load(etl::experimental::ipersistence& persistence, T& value)
{
size_t length = sizeof(T);
persistence.load(reinterpret_cast<char*>(&value), length);
}
//***************************************************************************
/// Generic streaming operators.
//***************************************************************************
template <typename T>
etl::experimental::ipersistence& operator <<(etl::experimental::ipersistence& ip, const T& value)
{
persistence_save(ip, value);
return ip;
}
//*********************************
#if ETL_CPP11_SUPPORTED
template <typename T>
etl::experimental::ipersistence& operator <<(etl::experimental::ipersistence& ip, T&& value)
{
persistence_save(ip, etl::move(value));
return ip;
}
#endif
//*********************************
template <typename T>
etl::experimental::ipersistence& operator >>(etl::experimental::ipersistence& ip, T& value)
{
persistence_load(ip, value);
return ip;
}
//***************************************************************************
/// Find the require persistence size for a value.
//***************************************************************************
template <typename T>
size_t persistence_size(const T& value)
{
using etl::experimental::persistence_save;
persistence_profiler profiler;
persistence_save(profiler, value);
return profiler.size();
}
#if ETL_CPP11_SUPPORTED
template <typename T>
size_t persistence_size(T&& value)
{
using etl::experimental::persistence_save;
persistence_profiler profiler;
persistence_save(profiler, etl::move(value));
return profiler.size();
}
#endif
//***************************************************************************
/// Generic Step Persistent.
//***************************************************************************
template <typename T>
void persistence_step(etl::experimental::ipersistence& persistence, const T& value)
{
persistence.step(persistence_size(value));
}
#if ETL_CPP11_SUPPORTED
template <typename T>
void persistence_step(etl::experimental::ipersistence& persistence, T&& value)
{
persistence.step(persistence_size(etl::move(value)));
}
#endif
//*********************************
inline etl::experimental::ipersistence& operator <<(etl::experimental::ipersistence& ip, etl::experimental::ipersistence::stepper step)
{
persistence_step(ip, step.n);
return ip;
}
//*********************************
inline etl::experimental::ipersistence& operator >>(etl::experimental::ipersistence& ip, etl::experimental::ipersistence::stepper step)
{
persistence_step(ip, step.n);
return ip;
}
}
}
#endif

View File

@ -2741,7 +2741,9 @@
<ClInclude Include="..\..\include\etl\mutex\mutex_freertos.h" />
<ClInclude Include="..\..\include\etl\negative.h" />
<ClInclude Include="..\..\include\etl\nth_type.h" />
<ClInclude Include="..\..\include\etl\object_allocator.h" />
<ClInclude Include="..\..\include\etl\overload.h" />
<ClInclude Include="..\..\include\etl\persistence.h" />
<ClInclude Include="..\..\include\etl\placement_new.h" />
<ClInclude Include="..\..\include\etl\null_type.h" />
<ClInclude Include="..\..\include\etl\parameter_pack.h" />

View File

@ -1242,6 +1242,12 @@
<ClInclude Include="..\unittest++\Win32\TimeHelpers.h">
<Filter>UnitTest++\Header Files\Win32</Filter>
</ClInclude>
<ClInclude Include="..\..\include\etl\object_allocator.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\etl\persistence.h">
<Filter>ETL\Utilities</Filter>
</ClInclude>
<ClInclude Include="..\..\include\etl\ireference_counted_message_pool.h">
<Filter>ETL\Messaging</Filter>
</ClInclude>