OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
IndexMap.h
Go to the documentation of this file.
1 #ifndef OPAL_INDEXMAP_H
2 #define OPAL_INDEXMAP_H
3 
4 #include <ostream>
5 #include <map>
6 
9 
10 #include <set>
11 #include <utility>
12 
13 
14 class IndexMap
15 {
16 public:
17  typedef std::pair<double, double> key_t;
18  typedef std::set<std::shared_ptr<Component> > value_t;
19 
20  IndexMap();
21 
22  void add(key_t::first_type initialStep, key_t::second_type finalStep, const value_t &val);
23 
24  value_t query(key_t::first_type s, key_t::second_type ds);
25 
26  void tidyUp(double zstop);
27 
28  void print(std::ostream&) const;
29  void saveSDDS(double startS) const;
30  size_t size() const;
31 
32  size_t numElements() const;
33  std::pair<double, double> getRange(const IndexMap::value_t::value_type &element,
34  double position) const;
35  IndexMap::value_t getTouchingElements(const std::pair<double, double> &range);
36 
37  class OutOfBounds: public OpalException {
38  public:
39  OutOfBounds(const std::string &meth, const std::string &msg):
40  OpalException(meth, msg) { }
41 
42  OutOfBounds(const OutOfBounds &rhs):
43  OpalException(rhs) { }
44 
45  virtual ~OutOfBounds() { }
46 
47  private:
48  OutOfBounds();
49  };
50 
51 private:
52  class myCompare {
53  public:
54  bool operator()(const key_t x , const key_t y) const
55  {
56  if (x.first < y.first) return true;
57 
58  if (x.first == y.first) {
59  if (x.second < y.second) return true;
60  }
61 
62  return false;
63  }
64  };
65 
66  typedef std::map<key_t, value_t, myCompare> map_t;
67  typedef std::multimap<value_t::value_type, key_t> invertedMap_t;
70 
72 
73  static bool almostEqual(double, double);
74  static const double oneMinusEpsilon_m;
75 };
76 
77 inline
78 size_t IndexMap::size() const {
79  return mapRange2Element_m.size();
80 }
81 
82 inline
83 std::ostream& operator<< (std::ostream &out, const IndexMap &im)
84 {
85  im.print(out);
86  return out;
87 }
88 
89 inline
91  im.print(out.getStream());
92  return out;
93 }
94 
95 #endif
std::ostream & operator<<(std::ostream &os, const Attribute &attr)
Definition: Attribute.cpp:167
std::pair< double, double > key_t
Definition: IndexMap.h:17
value_t query(key_t::first_type s, key_t::second_type ds)
Definition: IndexMap.cpp:53
double totalPathLength_m
Definition: IndexMap.h:71
std::ostream & getStream()
Definition: Inform.h:88
The base class for all OPAL exceptions.
Definition: OpalException.h:28
virtual ~OutOfBounds()
Definition: IndexMap.h:45
OutOfBounds(const OutOfBounds &rhs)
Definition: IndexMap.h:42
OutOfBounds(const std::string &meth, const std::string &msg)
Definition: IndexMap.h:39
size_t size() const
Definition: IndexMap.h:78
void add(key_t::first_type initialStep, key_t::second_type finalStep, const value_t &val)
Definition: IndexMap.cpp:90
size_t numElements() const
void saveSDDS(double startS) const
Definition: IndexMap.cpp:155
IndexMap()
Definition: IndexMap.cpp:21
std::multimap< value_t::value_type, key_t > invertedMap_t
Definition: IndexMap.h:67
MMatrix< double > im(MMatrix< m_complex > mc)
Definition: MMatrix.cpp:398
T * value_type(const SliceIterator< T > &)
void print(std::ostream &) const
Definition: IndexMap.cpp:27
std::map< key_t, value_t, myCompare > map_t
Definition: IndexMap.h:66
map_t mapRange2Element_m
Definition: IndexMap.h:68
std::pair< double, double > getRange(const IndexMap::value_t::value_type &element, double position) const
Definition: IndexMap.cpp:350
static bool almostEqual(double, double)
Definition: IndexMap.cpp:385
invertedMap_t mapElement2Range_m
Definition: IndexMap.h:69
static const double oneMinusEpsilon_m
Definition: IndexMap.h:74
Definition: Inform.h:41
void tidyUp(double zstop)
Definition: IndexMap.cpp:125
IndexMap::value_t getTouchingElements(const std::pair< double, double > &range)
Definition: IndexMap.cpp:371
std::set< std::shared_ptr< Component > > value_t
Definition: IndexMap.h:18
bool operator()(const key_t x, const key_t y) const
Definition: IndexMap.h:54