HCE project C++ developers source code library  1.1.1
HCE project developer library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ReducingPartsCountersStorage.cpp
Go to the documentation of this file.
2 #include "Exceptions.hpp"
3 
4 namespace HCE{
5 namespace reduce{
6 
8 }
9 
11 }
12 
13 void ReducingPartsCountersStorage::incrementBy(unsigned long long keyId)
14 {
15  StorageIterator storageIterator = findIteratorBy(keyId);
16  storageIterator->second++;
17 }
18 
20 {
21  keyIdCountersStorage[keyId] = 0;
22 }
23 
24 bool ReducingPartsCountersStorage::findBy(unsigned long long keyId)
25 {
26  try{
27  findIteratorBy(keyId);
28  return true;
29  }
30  catch(NotFoundByKeyException& e){
31  return false;
32  }
33 }
34 
35 void ReducingPartsCountersStorage::deleteBy(unsigned long long keyId)
36 {
37  StorageIterator storageIterator = findIteratorBy(keyId);
38  keyIdCountersStorage.erase(storageIterator);
39 }
40 
42 {
43  StorageIterator storageIterator = findIteratorBy(keyId);
44  return storageIterator->second;
45 }
46 
48 {
49  return static_cast<unsigned int>(keyIdCountersStorage.size());
50 }
51 
53  ReducingPartsCountersStorage::findIteratorBy(unsigned long long keyId)
54 {
55  StorageIterator storageIterator = keyIdCountersStorage.find(keyId);
56  if (storageIterator != keyIdCountersStorage.end()){
57  return storageIterator;
58  }
59  throw NotFoundByKeyException("ReducingPartsCountersStorage - not found key " + std::to_string(keyId));
60 }
61 
62 
63 }
64 }