| 1 |
// -*- related-file-name: "../../libefont/psres.cc" -*- |
| 2 |
#ifndef EFONT_PSRES_HH |
| 3 |
#define EFONT_PSRES_HH |
| 4 |
#include <lcdf/vector.hh> |
| 5 |
#include <lcdf/hashmap.hh> |
| 6 |
#include <lcdf/string.hh> |
| 7 |
#include <lcdf/filename.hh> |
| 8 |
class Slurper; |
| 9 |
namespace Efont { |
| 10 |
class PsresDatabaseSection; |
| 11 |
|
| 12 |
class PsresDatabase { public: |
| 13 |
|
| 14 |
PsresDatabase(); |
| 15 |
~PsresDatabase(); |
| 16 |
|
| 17 |
void add_psres_path(const char* path, const char* defaults, bool override); |
| 18 |
bool add_psres_file(Filename&, bool override); |
| 19 |
void add_database(PsresDatabase*, bool override); |
| 20 |
|
| 21 |
inline PsresDatabaseSection* section(PermString section) const; |
| 22 |
const String& value(PermString section, PermString key) const; |
| 23 |
const String& unescaped_value(PermString section, PermString key) const; |
| 24 |
Filename filename_value(PermString section, PermString key) const; |
| 25 |
|
| 26 |
private: |
| 27 |
|
| 28 |
HashMap<PermString, int> _section_map; |
| 29 |
Vector<PsresDatabaseSection*> _sections; |
| 30 |
|
| 31 |
PsresDatabaseSection* force_section(PermString); |
| 32 |
bool add_one_psres_file(Slurper&, bool override); |
| 33 |
void add_psres_directory(PermString); |
| 34 |
|
| 35 |
}; |
| 36 |
|
| 37 |
class PsresDatabaseSection { public: |
| 38 |
|
| 39 |
PsresDatabaseSection(PermString); |
| 40 |
|
| 41 |
PermString section_name() const { return _section_name; } |
| 42 |
|
| 43 |
void add_psres_file_section(Slurper&, PermString, bool); |
| 44 |
void add_section(PsresDatabaseSection*, bool override); |
| 45 |
|
| 46 |
const String& value(PermString key) { return value(_map[key]); } |
| 47 |
inline const String& unescaped_value(PermString key) const; |
| 48 |
Filename filename_value(PermString key); |
| 49 |
|
| 50 |
private: |
| 51 |
|
| 52 |
PermString _section_name; |
| 53 |
HashMap<PermString, int> _map; |
| 54 |
Vector<PermString> _directories; |
| 55 |
Vector<String> _values; |
| 56 |
Vector<int> _value_escaped; |
| 57 |
|
| 58 |
const String& value(int index); |
| 59 |
|
| 60 |
}; |
| 61 |
|
| 62 |
inline PsresDatabaseSection* PsresDatabase::section(PermString n) const |
| 63 |
{ |
| 64 |
return _sections[_section_map[n]]; |
| 65 |
} |
| 66 |
|
| 67 |
inline const String& PsresDatabaseSection::unescaped_value(PermString key) const |
| 68 |
{ |
| 69 |
assert(!_value_escaped[_map[key]]); |
| 70 |
return _values[_map[key]]; |
| 71 |
} |
| 72 |
|
| 73 |
} |
| 74 |
#endif |