ReFRACtor
bin_map.h
Go to the documentation of this file.
1 #ifndef BIN_MAP_H
2 #define BIN_MAP_H
3 #include <map>
4 
5 namespace FullPhysics {
6 /****************************************************************/
11 template<class T> class BinMap {
12 public:
13  typedef typename std::map<double, T>::const_iterator const_iterator;
14  typedef typename std::map<double, T>::iterator iterator;
15  const_iterator begin() const {return val.begin();}
16  iterator begin() {return val.begin();}
17  const_iterator end() const {return val.end();}
18  iterator end() {return val.end();}
19 
20  BinMap() {}
21 
22 //-----------------------------------------------------------------------
25 //-----------------------------------------------------------------------
26  template<class It> BinMap(It xstart, It xend, const T& Initial_value)
27  {
28  if(xstart == xend) // Handle degenerate case
29  return;
30  xstart++; // Don't care what the lower edge is,
31  // since we extrapolate anyways.
32  while(xstart != xend)
33  val.insert(std::pair<double, T>(*xstart++, Initial_value));
34  }
35 
36 //-----------------------------------------------------------------------
39 //-----------------------------------------------------------------------
40  template<class It, class C>
41  BinMap(It xstart, It xend, const C& Initial_value_creator)
42  {
43  if(xstart == xend) // Handle degenerate case
44  return;
45  xstart++; // Don't care what the lower edge is,
46  // since we extrapolate anyways.
47  while(xstart != xend)
48  val.insert(std::pair<double, T>(*xstart++, Initial_value_creator()));
49  }
50 
51 //-----------------------------------------------------------------------
53 //-----------------------------------------------------------------------
54 
55  const T& operator[](double x) const
56  {
57  typedef typename
58  std::map<double, T>::const_iterator Itype;
59  Itype i = val.lower_bound(x);
60  if(i == val.end())
61  return val.rbegin()->second;
62  else
63  return i->second;
64  }
65  T& operator[](double x)
66  {
67  typedef typename
68  std::map<double, T>::iterator Itype;
69  Itype i = val.lower_bound(x);
70  if(i == val.end())
71  return val.rbegin()->second;
72  else
73  return i->second;
74  }
75 
76 //-----------------------------------------------------------------------
77 // Return all the values. This is ordered by the bins.
78 //-----------------------------------------------------------------------
79 
80  std::vector<T> value() const
81  {
82  std::vector<T> res;
83  typedef typename std::map<double, T>::value_type vt;
84  for(typename std::map<double, T>::const_iterator i = val.begin();
85  i != val.end(); ++i)
86  res.push_back(i->second);
87  return res;
88  }
89 private:
90  std::map<double, T> val;
91 };
92 }
93 #endif
BinMap(It xstart, It xend, const C &Initial_value_creator)
Constructor.
Definition: bin_map.h:41
T & operator[](double x)
Definition: bin_map.h:65
std::vector< T > value() const
Definition: bin_map.h:80
const_iterator end() const
Definition: bin_map.h:17
BinMap(It xstart, It xend, const T &Initial_value)
Constructor.
Definition: bin_map.h:26
This is a map that takes and index and returns a value.
Definition: bin_map.h:11
std::map< double, T >::const_iterator const_iterator
Definition: bin_map.h:13
iterator begin()
Definition: bin_map.h:16
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
const_iterator begin() const
Definition: bin_map.h:15
std::map< double, T >::iterator iterator
Definition: bin_map.h:14
iterator end()
Definition: bin_map.h:18
const T & operator[](double x) const
Return bin that "x" falls into.
Definition: bin_map.h:55

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11