IDNumberGen.cxx
Go to the documentation of this file.
1 // IDNumberGen.cxx
2 // garsoft-mrb
3 //
4 // Created by Leo Bellantoni on 2 Aug, 2019
5 // With lots of help from Paul Russo :)
6 
7 
8 
10 
11 
12 
13 namespace gar {
14  namespace rec {
15 
16 
17 
19 
20  // Repeated calls to new here do not create a memory leak.
21  // Some kind of wierd C++11 magic.
22  static IDNumberGen* tmp = new IDNumberGen();
23  // If creating an instance with an initial value
24  if (iniValue != std::numeric_limits<IDNumber>::max()) {
25  // and if the iniValue isn't one of the previously used ones
27  if (itr==previousInitializers.end()) {
28  previousInitializers.insert(iniValue);
29  nextOneToMake.store(iniValue);
30  }
31  }
32  // Even if nextOneToMake.store() not called, still fine that tmp is
33  // uninitialized as getNewOne() only pulls info from a static field.
34  return tmp;
35  }
36 
37 
38 
42  return retval;
43  }
44 
45 
46 
48  previousInitializers.clear();
50  return;
51  }
52 
53 
54 
55  std::atomic<gar::rec::IDNumber> IDNumberGen::nextOneToMake = std::numeric_limits<IDNumber>::max();
56  std::set<gar::rec::IDNumber> IDNumberGen::previousInitializers = {};
57 
59 
60  } // rec
61 } // gar
intermediate_table::iterator iterator
rec
Definition: tracks.py:88
static std::atomic< gar::rec::IDNumber > nextOneToMake
Definition: IDNumberGen.h:99
static IDNumberGen * create(IDNumber iniValue=std::numeric_limits< IDNumber >::max())
Definition: IDNumberGen.cxx:18
static std::set< gar::rec::IDNumber > previousInitializers
Definition: IDNumberGen.h:100
string tmp
Definition: languages.py:63
static int max(int a, int b)
General GArSoft Utilities.
size_t IDNumber
Definition: IDNumberGen.h:71