SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
randomizer_cache.hpp
Go to the documentation of this file.
1 /*
2 SeComLib
3 Copyright 2012-2013 TU Delft, Information Security & Privacy Lab (http://isplab.tudelft.nl/)
4 
5 Contributors:
6 Inald Lagendijk (R.L.Lagendijk@TUDelft.nl)
7 Mihai Todor (todormihai@gmail.com)
8 Thijs Veugen (P.J.M.Veugen@tudelft.nl)
9 Zekeriya Erkin (z.erkin@tudelft.nl)
10 
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
14 
15 http://www.apache.org/licenses/LICENSE-2.0
16 
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
30 #ifndef RANDOMIZER_CACHE_IMPLEMENTATION_GUARD
31 #define RANDOMIZER_CACHE_IMPLEMENTATION_GUARD
32 
33 namespace SeComLib {
34 namespace Core {
41  template <typename T_Container>
42  RandomizerCache<T_Container>::RandomizerCache (const typename T_Container::CryptoProvider &cryptoProvider, const std::string &configurationPath) :
43  cryptoProvider(cryptoProvider),
44  parameters(configurationPath),
45  index(0) {
46  this->initialize();
47  }
48 
55  template <typename T_Container>
56  RandomizerCache<T_Container>::RandomizerCache (const typename T_Container::CryptoProvider &cryptoProvider, const typename T_Container::Parameters &parameters) :
57  cryptoProvider(cryptoProvider),
58  parameters(parameters),
59  index(0) {
60  this->initialize();
61  }
62 
68  template <typename T_Container>
69  const T_Container &RandomizerCache<T_Container>::Pop () {
70  size_t currentIndex = this->index;
71 
72  ++this->index;
73  //wrap the index around once the cache is exhausted
74  this->index %= this->parameters.capacity;
75 
76  return this->cache[currentIndex];
77  }
78 
82  template <typename T_Container>
84  this->cache.reserve(this->parameters.capacity);
85 
86  for (size_t i = 0; i < this->parameters.capacity; ++i) {
87  this->cache.emplace_back(T_Container(this->cryptoProvider, this->parameters));
88  }
89  }
90 }//namespace Core
91 }//namespace SeComLib
92 
93 #endif//RANDOMIZER_CACHE_IMPLEMENTATION_GUARD
const T_Container & Pop()
Extracts one element.
RandomizerCache(const typename T_Container::CryptoProvider &cryptoProvider, const std::string &configurationPath)
Constructor.
void initialize()
Populates the cache.