libdballe  5.18
defs.h
Go to the documentation of this file.
1 /*
2  * msg/defs - Common definitions
3  *
4  * Copyright (C) 2010--2011 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
22 #ifndef DBA_MSG_DEFS_H
23 #define DBA_MSG_DEFS_H
24 
31 #include <limits.h>
32 #include <string>
33 #include <iosfwd>
34 
35 namespace dballe {
36 
40 typedef enum {
41  BUFR = 0,
42  CREX = 1,
43  AOF = 2,
44 } Encoding;
45 
46 const char* encoding_name(Encoding enc);
47 
51 static const int MISSING_INT = INT_MAX;
52 
53 struct Level
54 {
56  int ltype1;
58  int l1;
60  int ltype2;
62  int l2;
63 
64  Level(int ltype1=MISSING_INT, int l1=MISSING_INT, int ltype2=MISSING_INT, int l2=MISSING_INT)
65  : ltype1(ltype1), l1(l1), ltype2(ltype2), l2(l2) {}
66  Level(const char* ltype1, const char* l1=NULL, const char* ltype2=NULL, const char* l2=NULL);
67 
68  bool operator==(const Level& l) const
69  {
70  return ltype1 == l.ltype1 && l1 == l.l1
71  && ltype2 == l.ltype2 && l2 == l.l2;
72  }
73 
74  bool operator!=(const Level& l) const
75  {
76  return ltype1 != l.ltype1 || l1 != l.l1
77  || ltype2 != l.ltype2 || l2 != l.l2;
78  }
79 
86  int compare(const Level& l) const
87  {
88  int res;
89  if ((res = ltype1 - l.ltype1)) return res;
90  if ((res = l1 - l.l1)) return res;
91  if ((res = ltype2 - l.ltype2)) return res;
92  return l2 - l.l2;
93  }
94 
98  std::string describe() const;
99 
100  void format(std::ostream& out, const char* undef="-") const;
101 
102  static inline Level cloud(int ltype2, int l2=MISSING_INT) { return Level(256, MISSING_INT, ltype2, l2); }
103  static inline Level ana() { return Level(257); }
104 };
105 
106 std::ostream& operator<<(std::ostream& out, const Level& l);
107 
108 struct Trange
109 {
111  int pind;
113  int p1;
115  int p2;
116 
117  Trange(int pind=MISSING_INT, int p1=MISSING_INT, int p2=MISSING_INT)
118  : pind(pind), p1(p1), p2(p2) {}
119  Trange(const char* pind, const char* p1=NULL, const char* p2=NULL);
120 
121  bool operator==(const Trange& tr) const
122  {
123  return pind == tr.pind && p1 == tr.p1 && p2 == tr.p2;
124  }
125 
126  bool operator!=(const Trange& tr) const
127  {
128  return pind != tr.pind || p1 != tr.p1 || p2 != tr.p2;
129  }
130 
137  int compare(const Trange& t) const
138  {
139  int res;
140  if ((res = pind - t.pind)) return res;
141  if ((res = p1 - t.p1)) return res;
142  return p2 - t.p2;
143  }
144 
148  std::string describe() const;
149 
150  void format(std::ostream& out, const char* undef="-") const;
151 
152  static inline Trange instant() { return Trange(254, 0, 0); }
153  static inline Trange ana() { return Trange(); }
154 };
155 
156 std::ostream& operator<<(std::ostream& out, const Trange& l);
157 
158 }
159 
160 // vim:set ts=4 sw=4:
161 #endif