TextDB handles dependency checking the db vs text files, creating the db, loading, and destroying the DB.
| 28 | // TextDB handles dependency checking the db vs text files, creating the |
| 29 | // db, loading, and destroying the DB. |
| 30 | class TextDB |
| 31 | { |
| 32 | public: |
| 33 | // db_name is the savedir-relative name of the db file, |
| 34 | // minus the "db" extension. |
| 35 | TextDB(const char* db_name, const char* dir, vector<string> files); |
| 36 | TextDB(TextDB *parent); |
| 37 | ~TextDB() { shutdown(true); delete translation; } |
| 38 | void init(); |
| 39 | void shutdown(bool recursive = false); |
| 40 | DBM* get() { return _db; } |
| 41 | |
| 42 | // Make it easier to migrate from raw DBM* to TextDB |
| 43 | operator bool() const { return _db != 0; } |
| 44 | operator DBM*() const { return _db; } |
| 45 | |
| 46 | private: |
| 47 | bool _needs_update() const; |
| 48 | void _regenerate_db(); |
| 49 | |
| 50 | private: |
| 51 | bool open_db(); |
| 52 | const char* const _db_name; |
| 53 | string _directory; |
| 54 | vector<string> _input_files; |
| 55 | DBM* _db; |
| 56 | string timestamp; |
| 57 | TextDB *_parent; |
| 58 | const char* lang() { return _parent ? Options.lang_name : 0; } |
| 59 | public: |
| 60 | TextDB *translation; |
| 61 | }; |
| 62 | |
| 63 | // Convenience functions for (read-only) access to generic |
| 64 | // berkeley DB databases. |