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 int edition = 3,
00078 bool compressed = false);
00079
00080 void setTemplate(int type, int subtype, int localsubtype);
00081 void setEdition(int edition);
00082 void setTime(int year, int month, int day, int hour, int minute, int second);
00083
00084 void appendDatadesc(dba_varcode code);
00085
00086 std::string encode();
00087
00088 bool empty() const { return m_msg->subsets_count == 0; }
00089 size_t size() const { return m_msg->subsets_count; }
00090
00091
00092 BufrexSubset operator[](int idx) { return getSubset(idx); }
00093
00094 BufrexSubset getSubset(int idx);
00095
00096 BufrexSubset append();
00097
00098 void resetSections();
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00113 const bufrex_msg msg() const
00114 {
00115 return m_msg;
00116 }
00118 bufrex_msg msg()
00119 {
00120 return m_msg;
00121 }
00122 };
00123
00124 }
00125
00126 #endif