ppap4lmp  0.7.2
generator.cpp
Go to the documentation of this file.
1 
9 #include "generator.h"
10 #include "../core/element.h"
11 #include "../core/updater.h"
12 
13 /* ------------------------------------------------------------------ */
14 
16  const Vec<UpdatePair> &new_chain)
17 {
18  auto &chain = update_chain;
19 
20  for (auto it = new_chain.begin(); it != new_chain.end(); ++it)
21  {
22  if (std::find(chain.begin(), chain.end(), *it) == chain.end())
23  {
24  bool it_is_inserted = false;
25 
26  for (auto jt = chain.begin(); jt != chain.end(); ++jt)
27  {
28  bool jt_should_be_after_it = false;
29 
30  for (auto kt = it+1; kt != new_chain.end(); ++kt)
31  {
32  if (*kt == *jt)
33  {
34  jt_should_be_after_it = true;
35  break;
36  }
37  }
38 
39  if (jt_should_be_after_it)
40  {
41  chain.insert(jt, *it);
42  it_is_inserted = true;
43  break;
44  }
45  }
46 
47  if (!it_is_inserted)
48  {
49  chain.push_back(*it);
50  }
51  }
52  }
53 }
54 
55 /* ------------------------------------------------------------------ */
56 
58 {
59  for (const auto &item : update_chain)
60  {
61  item.first->increment_bookings();
62  }
63 }
64 
65 /* ------------------------------------------------------------------ */
66 
68 {
69  for (const auto &item : update_chain)
70  {
71  item.first->update_data(item.second);
72  }
73 }
74 
75 /* ------------------------------------------------------------------ */
76 
78 {
79  for (const auto &item : update_chain)
80  {
81  item.first->decrement_bookings();
82  }
83 }
84 
85 /* ------------------------------------------------------------------ */
86 
88 {
89  return update_chain;
90 }
This file has a definition of Generator class, which is one of the cores of this program.
void generate_data()
Hello to this Generator object.
Definition: generator.cpp:67
void merge_update_chain(const Vec< UpdatePair > &new_chain)
Definition: generator.cpp:15
std::vector< T > Vec
Vec is an alias for vector (same as list in Python).
Definition: std.h:27
void finish_using_generated_data()
Goodbye to this object.
Definition: generator.cpp:77
Vec< UpdatePair > update_chain
Definition: generator.h:52
const Vec< UpdatePair > & get_update_chain()
Get update_chain of this object.
Definition: generator.cpp:87
void book_to_generate_data()
Appoint to this Generator object.
Definition: generator.cpp:57