Embedded Template Library 1.0
icache.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8http://www.etlcpp.com
9
10Copyright(c) 2017 jwellbelove, rlindeman
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31//*****************************************************************************
32#error This header is in development. Do not use.
33//*****************************************************************************
34
35#ifndef __ETL_ICACHE__
36#define __ETL_ICACHE__
37
38#include "platform.h"
39#include "delegate.h"
40
41#include <utility>
42
43namespace etl
44{
48 template <typename TKey, typename TValue>
49 class icache
50 {
51 public:
52
57 icache()
58 : write_through(true),
59 read_store(nullptr),
60 write_store(nullptr)
61 {
62 }
63
68 virtual ~icache()
69 {
70 if (!write_through)
71 {
72 flush();
73 }
74 }
75
79 void set_read_function(etl::delegate<key_value_t&(void)> reader_)
80 {
81 read_store = reader;
82 }
83
87 void set_write_function(etl::delegate<void(const key_value_t&)> writer_)
88 {
89 write_store = writer;
90 }
91
95 void set_write_through(bool write_through_)
96 {
97 write_through = write_through_;
98 }
99
100 virtual const T& read(const TKey& key) const = 0;
101 virtual void write(const TKey& key, const TValue& value) = 0;
102 virtual void flush() = 0;
103
104 protected:
105
106 typedef ETL_OR_STD::pair<TKey, TValue> key_value_t;
107
109
110 etl::delegate<key_value_t&(void)>* read_store;
111 etl::delegate<void(const key_value_t&)>* write_store;
112 }
113}
114
115#endif
Declaration.
Definition: delegate_cpp03.h:175
Definition: icache.h:50
bool write_through
If true, the cache should write changed items back to the store immediately. If false then a flush() ...
Definition: icache.h:108
etl::delegate< key_value_t &(void)> * read_store
A function that will read a value from the store into the cache.
Definition: icache.h:110
virtual void flush()=0
The overridden function should write all changed values to the store.
virtual const T & read(const TKey &key) const =0
Reads from the cache. May read from the store using read_store.
etl::delegate< void(const key_value_t &)> * write_store
A function that will write a value from the cache into the store.
Definition: icache.h:111
virtual void write(const TKey &key, const TValue &value)=0
Writes to the cache. May write to the store using write_store.
bitset_ext
Definition: absolute.h:38