diff options
author | John Fultz <jfultz@wolfram.com> | 2015-08-22 01:39:47 -0500 |
---|---|---|
committer | John Fultz <jfultz@wolfram.com> | 2015-08-22 01:39:47 -0500 |
commit | 5e5d414c57d5c7dd8a3037dda1555db5fb7eb486 (patch) | |
tree | a442ebdafbb882f9fb3a620b8741e079a12e75a3 /lexiconparameters.h | |
parent | 6613f3fd45b4ecf6821ee7bb07c95f86f43b0db2 (diff) |
Add versioning of DAWGs.
If we're going to start writing these into user directories,
then we'd better start versioning them so we don't end
up generating bugs in the future.
LexiconParameters::loadDawg() implements a tiny
class factory which allows backward compatibility
of DAWGs. I'll soon be adding a "version 1" in
addition to the legacy "version 0". For now, version 1
is just dummied in.
Diffstat (limited to 'lexiconparameters.h')
-rw-r--r-- | lexiconparameters.h | 64 |
1 files changed, 22 insertions, 42 deletions
diff --git a/lexiconparameters.h b/lexiconparameters.h index 612c103..4c77cd1 100644 --- a/lexiconparameters.h +++ b/lexiconparameters.h @@ -25,6 +25,16 @@ namespace Quackle { +class DawgInterpreter +{ +public: + virtual void loadDawg(ifstream &file, unsigned char *dawg) = 0; + virtual void dawgAt(const unsigned char *dawg, int index, unsigned int &p, Letter &letter, bool &t, bool &lastchild, bool &british, int &playability) const = 0; + virtual int versionNumber() const = 0; + virtual ~DawgInterpreter() {}; +}; + + class LexiconParameters { public: @@ -34,68 +44,38 @@ public: void unloadAll(); // true if we have a dawg or a gaddag - bool hasSomething() const; + bool hasSomething() const { return hasDawg() || hasGaddag(); }; // loadDawg unloads the dawg if filename can't be opened void loadDawg(const string &filename); void unloadDawg(); - bool hasDawg() const; + bool hasDawg() const { return m_dawg != NULL; }; + int dawgVersion() const { return m_interpreter->versionNumber(); }; // loadGaddag unloads the gaddag if filename can't be opened void loadGaddag(const string &filename); void unloadGaddag(); - bool hasGaddag() const; + bool hasGaddag() const { return m_gaddag != NULL; }; // finds a file in the lexica data directory static string findDictionaryFile(const string &lexicon); // a convenience field; this is unused by libquackle - string lexiconName() const; - void setLexiconName(const string &name); + string lexiconName() const { return m_lexiconName; }; + void setLexiconName(const string &name) { m_lexiconName = name; }; - unsigned char dawgAt(int index) const; - const GaddagNode *gaddagRoot() const; + void dawgAt(int index, unsigned int &p, Letter &letter, bool &t, bool &lastchild, bool &british, int &playability) const + { + m_interpreter->dawgAt(m_dawg, index, p, letter, t, lastchild, british, playability); + } + const GaddagNode *gaddagRoot() const { return (GaddagNode *) &m_gaddag[0]; }; protected: unsigned char *m_dawg; unsigned char *m_gaddag; string m_lexiconName; + DawgInterpreter *m_interpreter; }; -inline bool LexiconParameters::hasSomething() const -{ - return hasDawg() || hasGaddag(); -} - -inline bool LexiconParameters::hasDawg() const -{ - return m_dawg != NULL; -} - -inline bool LexiconParameters::hasGaddag() const -{ - return m_gaddag != NULL; -} - -inline unsigned char LexiconParameters::dawgAt(int index) const -{ - return m_dawg[index]; -} - -inline const GaddagNode *LexiconParameters::gaddagRoot() const -{ - return (GaddagNode *) &m_gaddag[0]; -} - -inline string LexiconParameters::lexiconName() const -{ - return m_lexiconName; -} - -inline void LexiconParameters::setLexiconName(const string &name) -{ - m_lexiconName = name; -} - } #endif |