libdballe 5.10
defs.h
Go to the documentation of this file.
00001 /*
00002  * msg/defs - Common definitions
00003  *
00004  * Copyright (C) 2010--2011  ARPA-SIM <urpsim@smr.arpa.emr.it>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00018  *
00019  * Author: Enrico Zini <enrico@enricozini.com>
00020  */
00021 
00022 #ifndef DBA_MSG_DEFS_H
00023 #define DBA_MSG_DEFS_H
00024 
00031 #include <limits.h>
00032 #include <string>
00033 #include <iosfwd>
00034 
00035 namespace dballe {
00036 
00040 typedef enum {
00041     BUFR = 0,
00042     CREX = 1,
00043     AOF = 2,
00044 } Encoding;
00045 
00046 const char* encoding_name(Encoding enc);
00047 
00051 static const int MISSING_INT = INT_MAX;
00052 
00053 struct Level
00054 {
00056     int ltype1;
00058     int l1;
00060     int ltype2;
00062     int l2;
00063 
00064     Level(int ltype1=MISSING_INT, int l1=MISSING_INT, int ltype2=MISSING_INT, int l2=MISSING_INT)
00065         : ltype1(ltype1), l1(l1), ltype2(ltype2), l2(l2) {}
00066     Level(const char* ltype1, const char* l1=NULL, const char* ltype2=NULL, const char* l2=NULL);
00067 
00068     bool operator==(const Level& l) const
00069     {
00070         return ltype1 == l.ltype1 && l1 == l.l1
00071             && ltype2 == l.ltype2 && l2 == l.l2;
00072     }
00073 
00074     bool operator!=(const Level& l) const
00075     {
00076         return ltype1 != l.ltype1 || l1 != l.l1
00077             || ltype2 != l.ltype2 || l2 != l.l2;
00078     }
00079 
00086     int compare(const Level& l) const
00087     {
00088         int res;
00089         if ((res = ltype1 - l.ltype1)) return res;
00090         if ((res = l1 - l.l1)) return res;
00091         if ((res = ltype2 - l.ltype2)) return res;
00092         return l2 - l.l2;
00093     }
00094 
00098     std::string describe() const;
00099 
00100     void format(std::ostream& out, const char* undef="-") const;
00101 
00102     static inline Level cloud(int ltype2, int l2=MISSING_INT) { return Level(256, MISSING_INT, ltype2, l2); }
00103     static inline Level ana() { return Level(257); }
00104 };
00105 
00106 std::ostream& operator<<(std::ostream& out, const Level& l);
00107 
00108 struct Trange
00109 {
00111     int pind;
00113     int p1;
00115     int p2;
00116 
00117     Trange(int pind=MISSING_INT, int p1=MISSING_INT, int p2=MISSING_INT)
00118         : pind(pind), p1(p1), p2(p2) {}
00119     Trange(const char* pind, const char* p1=NULL, const char* p2=NULL);
00120 
00121     bool operator==(const Trange& tr) const
00122     {
00123         return pind == tr.pind && p1 == tr.p1 && p2 == tr.p2;
00124     }
00125 
00126     bool operator!=(const Trange& tr) const
00127     {
00128         return pind != tr.pind || p1 != tr.p1 || p2 != tr.p2;
00129     }
00130 
00137     int compare(const Trange& t) const
00138     {
00139         int res;
00140         if ((res = pind - t.pind)) return res;
00141         if ((res = p1 - t.p1)) return res;
00142         return p2 - t.p2;
00143     }
00144 
00148     std::string describe() const;
00149 
00150     void format(std::ostream& out, const char* undef="-") const;
00151 
00152     static inline Trange instant() { return Trange(254, 0, 0); }
00153     static inline Trange ana() { return Trange(); }
00154 };
00155 
00156 std::ostream& operator<<(std::ostream& out, const Trange& l);
00157 
00158 }
00159 
00160 // vim:set ts=4 sw=4:
00161 #endif