Scheduler
counter.cpp
Go to the documentation of this file.
1 
10 #include "counter.h"
11 #include <cstdlib>
12 
13 using namespace Utils;
14 
16 {
17  for (size_t i = 0; i < wheels.size(); i++)
18  {
19  delete wheels[i];
20  }
21 }
22 
23 void Counter::addWheel(unsigned int base)
24 {
25  wheels.push_back(new CountingWheel(base));
26 }
27 
29 {
30  for (unsigned int i = 0; i < wheels.size(); i++)
31  {
32  wheels[i]->initialize();
33  }
34 }
35 
37 {
38  bool overflow = false;
39  for (unsigned int i = 0; i < wheels.size(); i++)
40  {
41  overflow = wheels[i]->increment();
42  if (!overflow)
43  break;
44  }
45  return overflow;
46 }
47 
48 std::vector<unsigned int> Counter::getValue()
49 {
50  std::vector<unsigned int> value(wheels.size());
51  for (unsigned int i = 0; i < wheels.size(); i++)
52  {
53  value[i] = wheels[i]->getValue();
54  }
55  return value;
56 }
57 
58 
59 
60 long long unsigned int Counter::getNumberOfValues()
61 {
62  long long int value = 1;
63  for (unsigned int i = 0; i < wheels.size(); i++)
64  {
65  value *= wheels[i]->getBase();
66  }
67  return value;
68 }
69 
bool increment()
Definition: counter.cpp:36
std::vector< unsigned int > getValue()
Definition: counter.cpp:48
void addWheel(unsigned int base)
Definition: counter.cpp:23
long long unsigned int getNumberOfValues()
Definition: counter.cpp:60
void initialize()
Definition: counter.cpp:28
Definition: context.h:16