Particle Identification and Tracking
data_map.h
Go to the documentation of this file.
1 //Copyright 2009 Thomas A Caswell
2 //tcaswell@uchicago.edu
3 //http://jfi.uchicago.edu/~tcaswell
4 //
5 //This program is free software; you can redistribute it and/or modify
6 //it under the terms of the GNU General Public License as published by
7 //the Free Software Foundation; either version 3 of the License, or (at
8 //your option) any later version.
9 //
10 //This program is distributed in the hope that it will be useful, but
11 //WITHOUT ANY WARRANTY; without even the implied warranty of
12 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 //General Public License for more details.
14 //
15 //You should have received a copy of the GNU General Public License
16 //along with this program; if not, see <http://www.gnu.org/licenses>.
17 //
18 //Additional permission under GNU GPL version 3 section 7
19 //
20 //If you modify this Program, or any covered work, by linking or
21 //combining it with MATLAB (or a modified version of that library),
22 //containing parts covered by the terms of MATLAB User License, the
23 //licensors of this Program grant you additional permission to convey
24 //the resulting work.
25 
26 #ifndef DATA_MAP
27 #define DATA_MAP
28 
29 #include <map>
30 #include <stdexcept>
31 #include "enum_utils.h"
32 
33 namespace utilities
34 {
42 class Data_map
43 {
44 public:
48  Data_map(const std::map<utilities::D_TYPE,int>& in);
49 
53  Data_map();
62  {
63  if( in == D_SENTRY)
64  throw std::runtime_error("D_SENTRY is not a valid data type");
65 
66  return data_layout_[in];
67  }
68 
72  int operator()(int in)const
73  {
74  // if(in>=D_SENTRY)
75  // throw runtime_error("index out of range");
77 
78  return data_layout_[in];
79  }
83  void set_lookup(D_TYPE dt,int loc);
84 
85 
86 private:
93 };
94 
95 
96 
101 template<typename _CharT, class _Traits>
102 std::basic_ostream<_CharT, _Traits>&
103 operator<<(std::basic_ostream<_CharT, _Traits>& __os, const Data_map& in)
104 {
105 
106 
107  std::basic_ostringstream<_CharT, _Traits> s;
108  s.flags(__os.flags());
109  s.imbue(__os.getloc());
110  s.precision(__os.precision());
111 
112 
113  s << '(' ;
114  s<< in(0) ;
115  for(int j = 1;j<D_SENTRY;++j)
116  s<< ','<<in(j) ;
117  s << ')';
118 
119  return __os << s.str();
120 }
121 }
122 
123 
124 
125 
126 #endif