[Next] [Up] [Previous] [Contents]
Next: 5. International Support Up: Aspell .26.2 alpha A Previous: 3. The Aspell utility   Contents

Subsections

4. Library Interface

4.1 The C++ Library

Note: The information on the C++ library interface is currently outdated. This section will be updated once the interface stabilizes which should be within a release or two.

The C++ library is very easy to use however it is not 100% stable yet. Fell free to use it but be aware that you may need to make minor changes in your code. To use the library include link it with libaspell.

4.1.1 Class aspell

Declared in file <aspell.hh>

4.1.1.1 Synopses

4.1.1.2 Struct aspell::Error

4.1.2 Utility Functions

4.1.2.1 CheckResults

Declared in <as_check.hh>.

template <class ForwardIterator>  
struct CheckResults {  
  ForwardIterator begin; 
  ForwardIterator end  
  operator bool()  
}; 
  
template <class ForwardIterator [, class StatusFunc]> 
CheckResults<ForwardIterator> check (const aspell &sc  
                           , ForwardIterator begin, ForwardIterator end  
                          [, const StatusFunc &print_status])
Checks the data between between begin and end. When it encounters an unknown word it will return CheckResults. CheckResults::begin will contain an iterator pointing to the begging of the word and CheckResults::end will contain an iterator pointing to the end of the word and CheckResults will evaluate to true. If check reached the end then CheckResults will evaluate to false.

print_status is an optional generator (a function object this is called with no augments) that check will call after it successfully checked a word.

4.1.3 Examples

I hope to provide some soon but for right now please see the file aspell.cc.

4.2 The C Library Interface

I am also providing a C interface so that C programmers can use my library without a lot of hassle. Unfortunately because my actually library is C++ code there are several cravats to linking C to C++ code according to the C++FAQ Lite:

However depending on the compiler and/or linker you are using you may be able to get away with not doing one or more of these things. Your mileage may vary.

The C interface library is still not 100 percent finished yet so for now here is the header file aspell-c.h which should give you a rough idea of how to use it. Link your code with libaspell to use.

#include <stdlib.h> 
  
typedef struct aspell aspell; 
typedef struct SC_Error aspellError; 
  
typedef enum aspellProblem { 
  as_none, as_nonexistent, as_bad_format,  
  as_cant_write, as_duplicates,  
  as_unknown_lang, as_mismatched_lang 
} aspellProblem; 
  
typedef const char * aspellString; 
  
typedef struct aspellSuggestions { 
  size_t size; 
  aspellString * data; /* an array of size elements */ 
  void *internal_obj; 
} aspellSuggestions; 
  
typedef struct aspellWordList { 
  size_t size; 
  aspellString * data; 
  void *internal_obj; 
} aspellWordList; 
  
#ifdef __cplusplus 
extern "C" { 
#endif 
  
  aspell * aspell_new(const char *master, const char *personal); 
  void aspell_free(aspell *sc); 
  const aspellError * aspell_error(aspell *sc); 
  const char * aspell_lang_name(aspell *sc); 
  aspellSuggestions * aspell_suggest(aspell *sc, const char *word); 
  int aspell_check(aspell *sc, const char *word); 
  int aspell_check_raw(aspell *sc, const char *word); 
  void aspell_add_personal(aspell *sc, const char *word); 
  void aspell_add_session(aspell *sc, const char *word); 
  void aspell_save_personal(aspell *sc); 
  void aspell_clear_session(aspell *sc); 
  void aspell_change_personal(aspell *sc, const char *base); 
  aspellWordList * get_personal(aspell *sc); /* not implemented yet */ 
  aspellWordList * get_session(aspell *sc);  /* not implemented yet */ 
  
  void aspell_free_suggestions(aspellSuggestions *wl); 
  void aspell_free_word_list(aspellWordList *wl); 
  
  const char *  aspell_error_file(const aspellError *error); 
  const char *  aspell_error_addinfo(const aspellError *error); 
  aspellProblem aspell_error_problem(const aspellError *error); 
  const char *  aspell_error_message(const aspellError *error); 
  
#ifdef __cplusplus 
}; 
#endif 

4.3 Notes About Thread Safety

Read only Aspell methods and functions are thread safe as long as new, delete, delete[], and STL allocators are thread safe. To the best of my knowledge gcc and egcs meet these requirements. It is up to the programmer to make sure multiple threads do not do thing such as change the dictionaries and add or delete items from the personal or session dictionaries.


[Next] [Up] [Previous] [Contents]
Next: 5. International Support Up: Aspell .26.2 alpha A Previous: 3. The Aspell utility   Contents

1999-01-04