casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlotMSPageHeaderParam.h
Go to the documentation of this file.
1 #ifndef PLOTMSPAGEHEADERPARAM_H_
2 #define PLOTMSPAGEHEADERPARAM_H_
3 
4 #include <iostream>
5 #include <string>
6 #include <vector>
7 #include <map>
8 #include <array>
9 #include <algorithm>
10 
11 #include <casa/namespace.h>
13 
14 
15 namespace casa {
16 
17 using namespace std;
18 using std::array; // Disambiguation against casacore::array
19 
20 
22 public:
23  HeaderItemInfo(String name=String(),String shortLabel=String(),String longLabel=String())
24  : name_(name),
25  shortLabel_(shortLabel),
26  longLabel_(longLabel) {}
27 
28  const String& name() const { return name_ ; }
29  const String& shortLabel() const { return shortLabel_ ; }
30  const String& longLabel() const { return longLabel_ ; }
31 private:
35 };
36 
37 inline bool operator<(const HeaderItemInfo& left, const HeaderItemInfo& right){
38  return left.name() < right.name();
39 }
40 
41 
42 // Definition of supported Page Header Items
44 public:
45  enum class Item {
46  begin=0,
47  // Plot Data Storage
48  Filename=begin,
49  YColumns,
50  // Queries on MeasurementSet
51  ms_begin,
52  // ---- Queries on Observation table
53  Obs_Start_Date=ms_begin,
54  Obs_Start_Time,
55  Obs_Observer,
56  Obs_Project,
57  Obs_Telescope_Name,
58  // ---- "Target" information
59  Target_Name,
60  Target_Direction,
61  ms_end,
62  // Queries on CalTable: currently none
63  // cal_begin=ms_end, cal_end=ms_end, end=cal_end
64  end=ms_end,
65  n_items=end
66  };
67  static constexpr size_t n_items = static_cast<size_t>(Item::n_items);
68  static constexpr size_t size() { return n_items; }
69 
70  static const map<HeaderItemInfo,Item>& info2Item_() {
71  static const map<HeaderItemInfo,Item> info2item = {
72  // Name Short label Long label Item
73  { {"filename" , "File" , "Filename" } , Item::Filename },
74  { {"y_columns" , "Y Column(s)" , "Y Column(s)" } , Item::YColumns },
75  { {"obs_start_date" , "Observation date", "Observation Start Date" } , Item::Obs_Start_Date },
76  { {"obs_start_time" , "Observation time", "Observation Start Time" } , Item::Obs_Start_Time },
77  { {"obs_observer" , "Observer" , "Observer" } , Item::Obs_Observer },
78  { {"obs_project" , "Project ID" , "Project ID" } , Item::Obs_Project },
79  { {"obs_telescope_name" , "Telescope" , "Telescope Name" } , Item::Obs_Telescope_Name },
80  { {"target_name" , "Target name" , "Target Name" } , Item::Target_Name },
81  { {"target_direction" , "Target RA,Dec" , "Target Direction" } , Item::Target_Direction }
82  };
83  return info2item;
84  }
85 
86  struct Reverse {
87  Reverse() {}
88  void operator()(pair<HeaderItemInfo,Item> p)
89  {
90  item2Info[p.second] = p.first;
91  }
92  const map<Item,HeaderItemInfo> & result() { return item2Info; }
93  map<Item,HeaderItemInfo> item2Info;
94  };
95 
96  static map<Item,HeaderItemInfo> reverseMap(const map<HeaderItemInfo,Item>& map ) {
97  return for_each(map.begin(),map.end(),Reverse()).result();
98  }
99 
100  static const map<Item,HeaderItemInfo>& item2Info_() {
101  static const auto item2info = reverseMap(info2Item_());
102  return item2info;
103  }
104 
105  struct GetName {
106  GetName() {}
107  void operator()(pair<HeaderItemInfo,Item> p)
108  {
109  toItem[p.first.name()] = p.second;
110  }
111  map<String,Item> toItem;
112  };
113 
114  static const map<String,Item>& name2Item_() {
115  static const auto & info = info2Item_();
116  static const auto name2item = for_each(info.begin(),info.end(),GetName()).toItem ;
117  return name2item;
118  }
119 
120  static const array<Item,n_items>& items();
121  static const array<String,n_items>& itemNames();
122  static bool isItemName(const String& s);
123 
124  static const map<HeaderItemInfo,Item>& info2Item;
125  static const map<Item,HeaderItemInfo>& item2Info;
126  static const map<String,Item>& name2Item;
127 
128 private:
130 };
131 
132 // Ordered selection of distinct (no duplicates) page header items.
133 // Enforce a maximum of 10 header items per plot.
135 public:
136  static constexpr size_t kMaxItems = 10;
138 
139  PageHeaderItems(const String& items=String(),const char sep=',');
140  const std::vector<HeaderItem>& items() const;
141  void setItems(const String& items=String(),const char sep=',');
142  void clear();
143  bool append(const String& item);
144  bool append(HeaderItem item);
145  bool remove(HeaderItem item);
146  bool full() const;
147  bool selected(HeaderItem item) const;
148  pair<bool,size_t> index(HeaderItem item) const;
149 
150  bool operator==(const PageHeaderItems& other) const {
151  return items_ == other.items() ; }
152  bool operator!=(const PageHeaderItems& other) const {
153  return !(operator==(other)); }
154 
155 private:
156  std::vector<HeaderItem> items_;
157  map<HeaderItem,size_t> item2index_;
158 };
159 
160 
161 }
162 
163 
164 #endif /* PLOTMSPAGEHEADERPARAM_H_ */
bool operator!=(const PageHeaderItems &other) const
static const map< String, Item > & name2Item
std::vector< HeaderItem > items_
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1886
const map< Item, HeaderItemInfo > & result()
map< HeaderItem, size_t > item2index_
map< Item, HeaderItemInfo > item2Info
const String & longLabel() const
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
const_iterator end() const
static map< Item, HeaderItemInfo > reverseMap(const map< HeaderItemInfo, Item > &map)
static const map< HeaderItemInfo, Item > & info2Item_()
const_iterator begin() const
static const map< HeaderItemInfo, Item > & info2Item
static const map< Item, HeaderItemInfo > & item2Info
const String & name() const
static const map< String, Item > & name2Item_()
bool operator<(const HeaderItemInfo &left, const HeaderItemInfo &right)
const String & shortLabel() const
HeaderItemInfo(String name=String(), String shortLabel=String(), String longLabel=String())
const std::vector< HeaderItem > & items() const
void operator()(pair< HeaderItemInfo, Item > p)
static constexpr size_t size()
Definition of supported Page Header Items.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Bool operator==(const MVTime &lh, const MVTime &rh)
is equal operator, uses operator Double which returns days
Definition: MVTime.h:465
static const map< Item, HeaderItemInfo > & item2Info_()
Ordered selection of distinct (no duplicates) page header items.
void operator()(pair< HeaderItemInfo, Item > p)
bool operator==(const PageHeaderItems &other) const