Embedded Template Library  1.0
icache.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 https://github.com/ETLCPP/etl
8 http://www.etlcpp.com
9 
10 Copyright(c) 2017 jwellbelove, rlindeman
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files(the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions :
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
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 
43 namespace 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
Definition: delegate.h:91
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.
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.
virtual const T & read(const TKey &key) const =0
Reads from the cache. May read from the store using read_store.
Definition: absolute.h:37