00001 #ifndef DBALLE_CPP_BUFREX_H
00002 #define DBALLE_CPP_BUFREG_H
00003
00004 #include <dballe/bufrex/msg.h>
00005 #include <dballe++/var.h>
00006
00007 namespace dballe {
00008
00009 class BufrexSubset
00010 {
00011
00012 bufrex_subset m_sub;
00013
00014 public:
00015 BufrexSubset(bufrex_subset sub) : m_sub(sub) {}
00016
00017 void reset();
00018 void truncate(int idx);
00019 void appendvar(dba_varcode code, const Var& var);
00020 void appendvar(const Var& var);
00021
00022 bool empty() const { return m_sub->vars_count == 0; }
00023 size_t size() const { return m_sub->vars_count; }
00024
00025 Var operator[](int idx) const { return getVar(idx); }
00026 Var getVar(int idx) const;
00027
00028 void appendi(dba_varcode code, int val)
00029 {
00030 checked(bufrex_subset_store_variable_i(m_sub, code, val));
00031 }
00032 void appendd(dba_varcode code, double val)
00033 {
00034 checked(bufrex_subset_store_variable_d(m_sub, code, val));
00035 }
00036 void appendc(dba_varcode code, const char* val)
00037 {
00038 checked(bufrex_subset_store_variable_c(m_sub, code, val));
00039 }
00040 void appends(dba_varcode code, const std::string& val)
00041 {
00042 checked(bufrex_subset_store_variable_c(m_sub, code, val.c_str()));
00043 }
00044 void appendu(dba_varcode code)
00045 {
00046 checked(bufrex_subset_store_variable_undef(m_sub, code));
00047 }
00048
00049
00050 void append(dba_varcode code, const Var& var) { appendvar(code, var); }
00051 void append(const Var& var) { appendvar(var); }
00052 void append(dba_varcode code, int val) { appendi(code, val); }
00053 void append(dba_varcode code, double val) { appendd(code, val); }
00054 void append(dba_varcode code, const char* val) { appendc(code, val); }
00055 void append(dba_varcode code, const std::string& val) { appends(code, val); }
00056 void append(dba_varcode code) { appendu(code); }
00057 };
00058
00062 class Bufrex
00063 {
00064 bufrex_msg m_msg;
00065
00066 Bufrex(bufrex_msg msg);
00067 public:
00069 Bufrex(const Bufrex& var);
00070 ~Bufrex();
00071
00073 Bufrex& operator=(const Bufrex& var);
00074
00075 static Bufrex createBUFR(int centre, int subcentre,
00076 int mastertable, int localtable,
00077 bool compressed = false);
00078
00079 void setTemplate(int type, int subtype, int localsubtype);
00080 void setEdition(int edition);
00081 void setTime(int year, int month, int day, int hour, int minute, int second);
00082
00083 void appendDatadesc(dba_varcode code);
00084
00085 std::string encode();
00086
00087 bool empty() const { return m_msg->subsets_count == 0; }
00088 size_t size() const { return m_msg->subsets_count; }
00089
00090
00091 BufrexSubset operator[](int idx) { return getSubset(idx); }
00092
00093 BufrexSubset getSubset(int idx);
00094
00095 BufrexSubset append();
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00110 const bufrex_msg msg() const
00111 {
00112 return m_msg;
00113 }
00115 bufrex_msg msg()
00116 {
00117 return m_msg;
00118 }
00119 };
00120
00121 }
00122
00123 #endif