From c98e0b97e818fed26f8c75b0f1684172b17ef1cf Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 10 Nov 2021 10:24:17 +0300 Subject: [PATCH] Start convert from C# to C++. Issue: https://github.com/linksplatform/Converters/issues/48 --- .../CachingConverterDecorator.h | 26 +++++++++++---- ...latform.Converters.TemplateLibrary.vcxproj | 14 +++++++- ...Converters.TemplateLibrary.vcxproj.filters | 33 +++++++++++++++++-- 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/cpp/Platform.Converters/CachingConverterDecorator.h b/cpp/Platform.Converters/CachingConverterDecorator.h index f8610a4..b58aad3 100644 --- a/cpp/Platform.Converters/CachingConverterDecorator.h +++ b/cpp/Platform.Converters/CachingConverterDecorator.h @@ -1,15 +1,29 @@ -namespace Platform::Converters +#pragma once +#include +#include + +namespace Platform::Converters { + using namespace Platform::Collections::Dictionaries; + using namespace Platform::Interfaces; + template class CachingConverterDecorator; template class CachingConverterDecorator : public IConverter { - private: readonly IConverter *_baseConverter; - private: readonly IDictionary *_cache; + private: std::unique_ptr> _baseConverter; + private: std::unique_ptr> _cache; - public: CachingConverterDecorator(IConverter &baseConverter, IDictionary &cache) { (_baseConverter, _cache) = (baseConverter, cache); } + public: CachingConverterDecorator(IConverter& baseConverter, IDictionary& cache) + : _baseConverter(baseConverter) + , _cache(cache) + {} - public: CachingConverterDecorator(IConverter &baseConverter) : this(baseConverter, Dictionary()) { } + public: CachingConverterDecorator(IConverter &baseConverter) + : _baseConverter(baseConverter) + { + _cache = std::make_unique>(); + } - public: TTarget Convert(TSource source) { return _cache.GetOrAdd(source, _baseConverter.Convert); } + public: TTarget Convert(TSource source) { return GetOrAdd(_cache->get(), source, _baseConverter->Convert); } }; } \ No newline at end of file diff --git a/cpp/Platform.Converters/Platform.Converters.TemplateLibrary.vcxproj b/cpp/Platform.Converters/Platform.Converters.TemplateLibrary.vcxproj index 7522d6d..95727d5 100644 --- a/cpp/Platform.Converters/Platform.Converters.TemplateLibrary.vcxproj +++ b/cpp/Platform.Converters/Platform.Converters.TemplateLibrary.vcxproj @@ -99,6 +99,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp20 Console @@ -138,12 +139,23 @@ + + + + + - + + + + + + + diff --git a/cpp/Platform.Converters/Platform.Converters.TemplateLibrary.vcxproj.filters b/cpp/Platform.Converters/Platform.Converters.TemplateLibrary.vcxproj.filters index 57128ab..045230f 100644 --- a/cpp/Platform.Converters/Platform.Converters.TemplateLibrary.vcxproj.filters +++ b/cpp/Platform.Converters/Platform.Converters.TemplateLibrary.vcxproj.filters @@ -27,11 +27,40 @@ Header Files - + Header Files - + + Header Files + + + Header Files + + + Header Files + + Header Files + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + \ No newline at end of file