diff --git a/include/etl/experimental/bit_cast.h b/include/etl/experimental/bit_cast.h deleted file mode 100644 index eefa3bbd..00000000 --- a/include/etl/experimental/bit_cast.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "platform.h" - -template -typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) && - etl::is_trivially_copyable::value && - etl::is_trivially_copyable::value, TDestination>::type - bit_cast(const TSource& source) ETL_NOEXCEPT -{ - TDestination destination; - - memcpy(&destination, &source, sizeof(TDestination)); - - return destination; -} - -template -ETL_CONSTEXPR -typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) && - etl::is_trivially_copyable::value && - etl::is_trivially_copyable::value, TDestination>::type - bit_cast(const TSource& source) ETL_NOEXCEPT -{ - TDestination destination; - - __builtin_memcpy(&destination, &source, sizeof(TDestination)); - - return destination; -} - - - diff --git a/include/etl/experimental/class_traits.h b/include/etl/experimental/class_traits.h deleted file mode 100644 index c9456bad..00000000 --- a/include/etl/experimental/class_traits.h +++ /dev/null @@ -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 -#include -#include - -#include "platform.h" - -#if ETL_CPP11_SUPPORTED - -namespace etl -{ -#if ETL_CPP11_SUPPORTED - //*************************************************************************** - /// has_member_function_begin - //*************************************************************************** - template - class has_begin - { - typedef char one; - struct two { char x[2]; }; - - template static constexpr one test(decltype(&C::begin)*); - template static constexpr two test(...); - - public: - - static constexpr bool value = (sizeof(test(0)) == sizeof(char)); - }; - -#if ETL_CPP17_SUPPORTED - template - static constexpr bool has_begin_v = has_begin::value; -#endif - - //*************************************************************************** - /// has_member_function_end - //*************************************************************************** - template - class has_end - { - typedef char one; - struct two { char x[2]; }; - - template static constexpr one test(decltype(std::declval().end())); - template static constexpr two test(...); - - public: - - static constexpr bool value = (sizeof(test(0)) == sizeof(char)); - }; - -#if ETL_CPP17_SUPPORTED - template - static constexpr bool has_end_v = hasend::value; -#endif - - //*************************************************************************** - /// has_member_function_size - //*************************************************************************** - template - class has_size - { - typedef char one; - struct two { char x[2]; }; - - template static one test(decltype(std::declval().size())); - template static two test(...); - - public: - - static constexpr bool value = (sizeof(test(0)) == sizeof(char)); - }; - -#if ETL_CPP17_SUPPORTED - template - static constexpr bool has_size_v = has_size::value; -#endif - - //*************************************************************************** -/// has_member_function_max_size -//*************************************************************************** - template - class has_max_size - { - typedef char one; - struct two { char x[2]; }; - - template static one test(decltype(std::declval().max_size())); - template static two test(...); - - public: - - static constexpr bool value = (sizeof(test(0)) == sizeof(char)); - }; - -#if ETL_CPP17_SUPPORTED - template - static constexpr bool has_max_size_v = has_max_size::value; -#endif - - //*************************************************************************** - /// has_member_function_empty - //*************************************************************************** - template - class has_empty - { - typedef char one; - struct two { char x[2]; }; - - template static constexpr one test(decltype(std::declval().empty())); - template static constexpr two test(...); - - public: - - static constexpr bool value = (sizeof(test(0)) == sizeof(char)); - }; - -#if ETL_CPP17_SUPPORTED - template - static constexpr bool has_empty_v = has_empty::value; -#endif - - //*************************************************************************** - /// has_member_function_data - //*************************************************************************** - template - class has_data - { - typedef char one; - struct two { char x[2]; }; - - template static constexpr one test(decltype(std::declval().data())); - template static constexpr two test(...); - - public: - - static constexpr bool value = (sizeof(test(0)) == sizeof(char)); - }; - -#if ETL_CPP17_SUPPORTED - template - static constexpr bool has_data_v = has_data::value; -#endif -#endif -} - -#endif - -#endif // ETL_CLASS_TRAITS_INCLUDED diff --git a/include/etl/experimental/mid_point flt (typo abs(a) should be abs(b).png b/include/etl/experimental/mid_point flt (typo abs(a) should be abs(b).png deleted file mode 100644 index c8c41a82..00000000 Binary files a/include/etl/experimental/mid_point flt (typo abs(a) should be abs(b).png and /dev/null differ diff --git a/include/etl/experimental/mid_point ptr.png b/include/etl/experimental/mid_point ptr.png deleted file mode 100644 index 10276a0e..00000000 Binary files a/include/etl/experimental/mid_point ptr.png and /dev/null differ diff --git a/include/etl/experimental/mid_point.png b/include/etl/experimental/mid_point.png deleted file mode 100644 index 57415256..00000000 Binary files a/include/etl/experimental/mid_point.png and /dev/null differ diff --git a/include/etl/experimental/singleton.h b/include/etl/experimental/singleton.h deleted file mode 100644 index 9291d85b..00000000 --- a/include/etl/experimental/singleton.h +++ /dev/null @@ -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 - 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 - class singleton_factory - { - virtual ~singleton_factory() {} - - template - 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 diff --git a/include/etl/persistence.h b/include/etl/persistence.h new file mode 100644 index 00000000..c9a78d96 --- /dev/null +++ b/include/etl/persistence.h @@ -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 etl::enable_if::value || etl::is_floating_point::value || etl::is_pointer::value || etl::is_trivially_copyable::value, void>::type + persistence_save(etl::experimental::ipersistence& persistence, T value) + { + T temp(value); + + const char* pvalue = reinterpret_cast(&temp); + size_t length = sizeof(temp); + persistence.save(pvalue, length); + } + + //*************************************************************************** + /// Generic Load Persistent. + //*************************************************************************** + template + typename etl::enable_if::value || etl::is_floating_point::value || etl::is_pointer::value || etl::is_trivially_copyable::value, void>::type + persistence_load(etl::experimental::ipersistence& persistence, T& value) + { + size_t length = sizeof(T); + persistence.load(reinterpret_cast(&value), length); + } + + //*************************************************************************** + /// Generic streaming operators. + //*************************************************************************** + template + etl::experimental::ipersistence& operator <<(etl::experimental::ipersistence& ip, const T& value) + { + persistence_save(ip, value); + + return ip; + } + + //********************************* +#if ETL_CPP11_SUPPORTED + template + etl::experimental::ipersistence& operator <<(etl::experimental::ipersistence& ip, T&& value) + { + persistence_save(ip, etl::move(value)); + + return ip; + } +#endif + + //********************************* + template + 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 + 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 + 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 + void persistence_step(etl::experimental::ipersistence& persistence, const T& value) + { + persistence.step(persistence_size(value)); + } + +#if ETL_CPP11_SUPPORTED + template + 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 diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 2a6518f0..b5bce643 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -2741,7 +2741,9 @@ + + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 0be9eb80..6a683b2d 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -1242,6 +1242,12 @@ UnitTest++\Header Files\Win32 + + ETL\Containers + + + ETL\Utilities + ETL\Messaging