libwreport  3.40
tabledir.h
1 #ifndef WREPORT_TABLEDIR_H
2 #define WREPORT_TABLEDIR_H
3 
4 #include <filesystem>
5 #include <string>
6 #include <vector>
7 #include <wreport/tableinfo.h>
8 
9 namespace wreport {
10 struct Vartable;
11 struct DTable;
12 
13 namespace tabledir {
14 struct Index;
15 
16 struct Table
17 {
18  std::string btable_id;
19  std::filesystem::path btable_pathname;
20  std::string dtable_id;
21  std::filesystem::path dtable_pathname;
22 
23  Table(const std::filesystem::path& dirname, const std::string& filename);
24  virtual ~Table() {}
25 
26  virtual void print_id(FILE* out) const;
27 };
28 
30 struct BufrTable : Table
31 {
32  BufrTableID id;
33 
34  BufrTable(const BufrTableID& id, const std::string& dirname,
35  const std::string& filename)
36  : Table(dirname, filename), id(id)
37  {
38  }
39 
40  void print_id(FILE* out) const override;
41 };
42 
44 struct CrexTable : Table
45 {
46  CrexTableID id;
47 
48  CrexTable(const CrexTableID& id, const std::string& dirname,
49  const std::string& filename)
50  : Table(dirname, filename), id(id)
51  {
52  }
53 
54  void print_id(FILE* out) const override;
55 };
56 
58 struct Dir
59 {
60  std::string pathname;
61  time_t mtime;
62  std::vector<Table*> tables;
63 
64  Dir(const std::string& pathname);
65  Dir(const Dir&) = delete;
66  Dir(Dir&&) = default;
67  ~Dir();
68 
69  Dir& operator=(const Dir&) = delete;
70 
72  void refresh();
73 };
74 
75 class Tabledirs
76 {
77 protected:
78  std::vector<std::string> dirs;
79  Index* index;
80 
81 public:
82  Tabledirs();
83  Tabledirs(const Tabledirs&) = delete;
84  ~Tabledirs();
85 
86  Tabledirs& operator=(const Tabledirs&) = delete;
87 
93 
95  void add_directory(const std::string& dir);
96 
99 
102 
104  const tabledir::Table* find(const std::string& basename);
105 
107  void print(FILE* out);
108 
110  void explain_find_bufr(const BufrTableID& id, FILE* out);
111 
113  void explain_find_crex(const CrexTableID& id, FILE* out);
114 
116  static Tabledirs& get();
117 };
118 
119 } // namespace tabledir
120 } // namespace wreport
121 
122 #endif
Identifying information for one distinct instance of BUFR tables.
Definition: tableinfo.h:15
Identifying information for one distinct instance of CREX tables.
Definition: tableinfo.h:63
Definition: tabledir.h:76
const tabledir::Table * find_crex(const CrexTableID &id)
Find a CREX table.
const tabledir::Table * find_bufr(const BufrTableID &id)
Find a BUFR table.
void add_default_directories()
Add the default directories according to compile-time and environment variables.
void explain_find_bufr(const BufrTableID &id, FILE *out)
Print the step by step process by which a table is selected for id.
void add_directory(const std::string &dir)
Add a table directory to this collection.
void print(FILE *out)
Print a list of all tables found.
void explain_find_crex(const CrexTableID &id, FILE *out)
Print the step by step process by which a table is selected for id.
const tabledir::Table * find(const std::string &basename)
Find a BUFR or CREX table by file name.
static Tabledirs & get()
Get the default tabledir instance.
String functions.
Definition: benchmark.h:13
Information about a version of a BUFR table.
Definition: tabledir.h:31
Information about a version of a CREX table.
Definition: tabledir.h:45
Indexed version of a table directory.
Definition: tabledir.h:59
void refresh()
Reread the directory contents if it has changed.
Definition: tabledir.h:17