libwreport  2.9
dtable.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005--2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Author: Enrico Zini <enrico@enricozini.com>
18  */
19 
20 #ifndef WREPORT_DTABLE_H
21 #define WREPORT_DTABLE_H
22 
23 #include <wreport/opcode.h>
24 #include <string>
25 #include <vector>
26 
27 namespace wreport {
28 
34 namespace dtable {
38 struct Entry
39 {
43  unsigned begin;
45  unsigned end;
46 
47 protected:
49  Entry(Varcode code, unsigned begin, unsigned end)
50  : code(code), begin(begin), end(end) {}
51 
52  friend class wreport::DTable;
53 };
54 }
55 
59 struct DTable
60 {
61 protected:
63  std::string m_id;
64 
65 public:
70  std::vector<Varcode> varcodes;
71 
75  std::vector<dtable::Entry> entries;
76 
77  DTable();
78  ~DTable();
79 
81  const std::string& id() const throw () { return m_id; }
82 
84  bool loaded() const throw () { return !m_id.empty(); }
85 
92  void load(const std::pair<std::string, std::string>& idfile);
93 
103  Opcodes query(Varcode var) const;
104 
117  static const DTable* get(const char* id);
118 
125  static const DTable* get(const std::pair<std::string, std::string>& idfile);
126 };
127 
128 }
129 
130 #endif
131 /* vim:set ts=4 sw=4: */
void load(const std::pair< std::string, std::string > &idfile)
Load a table.
bool loaded() const
True if the table has been loaded.
Definition: dtable.h:84
unsigned begin
Position in the main table where the expansion begins.
Definition: dtable.h:43
std::vector< dtable::Entry > entries
Expansion entries with pointers inside varcodes.
Definition: dtable.h:75
Entry(Varcode code, unsigned begin, unsigned end)
Constructor used internally by DTable::load.
Definition: dtable.h:49
D-table entry.
Definition: dtable.h:38
unsigned end
Position in the main table one past where the expansion ends.
Definition: dtable.h:45
Sequence of opcodes, as a slice of a Varcode vector.
Definition: opcode.h:50
D-table with Dxxyyy aggregate code expansions.
Definition: dtable.h:59
short unsigned int Varcode
Holds the WMO variable code of a variable.
Definition: varinfo.h:78
Opcodes query(Varcode var) const
Query the DTable.
std::vector< Varcode > varcodes
One single table with the concatenation of all the expansion varcodes.
Definition: dtable.h:70
Varcode code
Varcode to be expanded.
Definition: dtable.h:41
Implementation of opcode chains, that are used to drive the encoding and decoding process...
const std::string & id() const
Table ID.
Definition: dtable.h:81
std::string m_id
Table ID.
Definition: dtable.h:63