/*
File: speller.h
Copyright 2009 Chris Tonkinson (cmtonkinson@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
/**
* @file speller.h
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Header file for the Speller class (and associated classes).
* @note Wrapper for the Aspell C API
*/
#ifndef __H_SPELLER_
#define __H_SPELLER_
#include
#include
#include
#include
#define SPELLER_MAX_BUFFER 4096
#define SPELLER_DEFAULT_SUGGESTIONS 16
#define SPELLER_MAX_SUGGESTIONS 256
/**
* @class SpellerException
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Basic Speller exception class.
*/
class SpellerException {
private:
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Holds the text of the exception message.
*/
std::string _message;
public:
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Default constructor.
*/
SpellerException( void );
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Copy constructor.
*/
SpellerException( const SpellerException& ref );
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Constructor which initializes the _message member from the variable argument list.
* @arg format A printf() style format string.
* @arg ... A printf() style variable argument list.
*/
SpellerException( const char* format, ... );
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Destructor.
*/
~SpellerException( void );
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Public accessor method for _message.
* @arg message The new value of _message.
*/
void message( const std::string& message ) {
_message = message;
return;
}
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Public accessor method for _message.
* @return The current value of _message.
*/
std::string message( void ) const {
return _message;
}
};
/**
* @class Speller
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Main wrapper class for the GNU Aspell C API
*/
class Speller {
private:
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief A pointer to the AspellConfig object used to initialize Spellers
*/
AspellConfig* _config;
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief A pointer to the AspellSpeller object being wrapped
*/
AspellSpeller* _speller;
public:
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Default constructor
*/
Speller( void );
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Destructor
*/
~Speller( void );
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @param config An AspellConfig pointer
* @brief Sets the AspellConfig pointer
*/
void config( AspellConfig* config ) { _config = config; }
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @return A pointer to the AspellConfig object
*/
AspellConfig* config( void ) { return _config; }
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @param speller An AspellSpeller pointer
* @brief Sets the AspellSpeller pointer
*/
void speller( AspellSpeller* speller ) { _speller = speller; }
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @return A pointer to the AspellSpeller object
*/
AspellSpeller* speller( void ) { return _speller; }
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @param key The configuration option to set/reset
* @param value The new value of the option given by key
* @brief Updates the AspellConfig object
* @note If value is NULL, this method resets the configuration
* option given by key. If value is not null, then the
* given key is set to the value given.
*/
void config( const char* key, const char* value );
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @brief Creates a new AspellSpeller object, if one
* isn't already allocated
*/
void init( void );
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @param word A null-terminated word to be checked
* @return True if the given word is in the current dictionary,
* false otherwise
*/
bool check( const char* word );
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @param word A null-terminated word to be checked
* @param limit The maximum number of suggestions to return. Defaults to SPELLER_DEFAULT_SUGGESTIONS
* @return A vector containing no more than limit spelling
* suggestions (in order) of the given word
*/
std::vector suggest( const char* word, int limit = SPELLER_DEFAULT_SUGGESTIONS );
/**
* @author Chris Tonkinson (cmtonkinson@gmail.com)
* @date May 2009
* @param word A null-terminated word to be checked
* @return The first suggestion that would appear from using Speller::suggest( word )
* @note This method exists for convenience only. It is semantically equivalent
* to Speller::suggest(word)[0].
*/
const char* recommend( const char* word );
};
#endif // End of inclusion-guard