#include "lexicon.h"
Public Member Functions | |
| Lexicon () | |
| Lexicon (string filename) | |
| ~Lexicon () | |
| int | size () |
| bool | isEmpty () |
| void | add (string word) |
| void | addWordsFromFile (string filename) |
| bool | containsWord (string word) |
| bool | containsPrefix (string prefix) |
| void | clear () |
| template<typename ClientDataType> | |
| void | mapAll (void(fn)(string word, ClientDataType &), ClientDataType &data) |
| Lexicon (const Lexicon &rhs) | |
| const Lexicon & | operator= (const Lexicon &rhs) |
| template<typename ClientDataType> | |
| void | recMapAll (Edge *edge, bool first, string soFar, void(fn)(string word, ClientDataType &), ClientDataType &clientData) |
Classes | |
| struct | Edge |
Lexicon lex("lexicon.dat"); // read words from lexicon.dat file lex.add("doughnut"); if (lex.containsPrefix("fru") || lex.containsWord("ball")) ...
| Lexicon::Lexicon | ( | ) |
The constructor initializes a new empty lexicon.
| Lexicon::Lexicon | ( | string | filename | ) |
The constructor initializes a new lexicon which is populated with the words read from the specified file. The file is expected to be either a special special binary format that represents a saved lexicon or a plain text file of words, one word per line. The constructor reads the file and adds all of its words to this lexicon. The file must be in the same folder as the program to be found. If the file doesn't exist or is malformed, Error is called to exit the program.
| Lexicon::~Lexicon | ( | ) |
The destructor deallocates any storage associated with the lexicon.
| Lexicon::Lexicon | ( | const Lexicon & | rhs | ) |
This copy constructor and operator= are defined to make a deep copy, making it possible to pass/return lexicons by value and assign from one lexicon to another. The entire contents of the lexicon, including all words, are copied. Making copies is generally avoided because of the expense and thus, lexicons are typically passed by reference, however, when a copy is needed, these operations are supported.
| int Lexicon::size | ( | ) |
This member function returns the number of words contained in this lexicon.
| bool Lexicon::isEmpty | ( | ) |
This member function returns true if this lexicon contains no words, false otherwise.
| void Lexicon::add | ( | string | word | ) |
This member function adds the specified word to this lexicon.
| void Lexicon::addWordsFromFile | ( | string | filename | ) |
This member function reads the file and adds all of its words to this lexicon. The file is expected to be either a special special binary format that represents a saved lexicon or a plain text file of words, one word per line. The file must be in the same folder as the program to be found. If the file doesn't exist or is malformed, Error is called to exit the program.
| bool Lexicon::containsWord | ( | string | word | ) |
This member function returns true if word is contained in this lexicon, false otherwise. Words are considered case-insensitively, "zoo" is the same as "ZOO" or "zoo".
| bool Lexicon::containsPrefix | ( | string | prefix | ) |
This member function returns true if any words in this lexicon begin with prefix, false otherwise. A word is defined to be a prefix of itself and the empty string is a prefix of everything. Prefixes are considered case-insensitively, "mo" is a prefix of "MONKEY" or "Monday".
| void Lexicon::clear | ( | ) |
This member function removes all words from this lexicon. The lexicon will be empty after being cleared.
| void Lexicon::mapAll | ( | void(fn)(string word, ClientDataType &) | , | |
| ClientDataType & | data | |||
| ) |
This member function iterates through this lexicon and calls the function fn once for each word, passing the word and the client's data. That data can be of whatever type is needed for the client's callback.
| void Lexicon::recMapAll | ( | Edge * | edge, | |
| bool | first, | |||
| string | soFar, | |||
| void(fn)(string word, ClientDataType &) | , | |||
| ClientDataType & | clientData | |||
| ) |
1.5.1