Edwin Leuven <[EMAIL PROTECTED]> writes:

| While we are at it. I am having some scarce free moments again in which I am 
| looking at the spellcheck code.
| 
| What I was thinking was to have something like the following (watch out, a 
| flow of consciousness of a c++ beginner follows!):
| 
| A base class:

Yes to put all this in a class framework is needed.

But I am not sure if using inheritance is the best option, imho some
sort of traits class might work equally well:

template <typename Speller>
struct speller_traits {};

struct ispell {};

template <>
struct speller_traits<ispell> {
        bool check_word(string const &);
};
typedef speller_traints<ispell> ispell_traits;


template <typename SpellTraits>
class SpellChecker {
        typedef SpellTraits traits;

};

_OR_ perhaps more in the iostream fassion:
(I think I like this one even better and it is quite similar to yours)

class spell_base {
        ....
};

class ispell : public spell_base {
        ...
};


class SpellChecker {
        SpellChecker(BufferView & bv) : bv_(bv), speller_(new ispell) {}
        SpellCheker(BufferView & bv, spellbase * sb)
                 : bv_(bv), speller_(sb) {}
        bool check_word(string const & w) {
                if (bv_->buffer()->is_in_ignore_words(w))
                        return true;
                return speller_->check_word(w);
        }
        void add_to_personal(string const & w) {
                return speller_->add(w);
        }
        void add_to_document(string const & w) {
                bv_->buffer()->add_to_ignore_words(w);
        }
private:
        spell_base * speller_;
};



| Class SpellBase
| {
|  public:
|   SpellBase();
|   virtual ~SpellBase();
|   /// check word
|   virtual check(string word);
|   /// insert word in personal dict
|   virtual add(string word);
|   /// etc.
|  private:
|   /// data here
| }
| 
| and then inherit from this to have an ispell or pspell implementation
| 
| Class SpellISpell : SpellBase
| {
|   /// override stuff 
|   /// basically copy what is already there
| }
| 
| I think we can then have in the SpellChecker code
| 
| SpellBase * spell_ = new SpellISpell
| 
| or 
| 
| SpellBase * spell_ = new SpellPSpell
| 
| maybe I'am wrong though.
| 
| The SpellChecker code should do something like this
| 
| 1. Initialize spellchecker
| 2. Draw dialog

well... ask the dialog to be drawn...

| 3. Check next word until we run out of words
| 4. Update dialog
| 5. Stop: listen to dialog

should (ideally) be part of the main event loop.

| 6. Dialog returns info
| 7. Continue: Act on info and go to 3.
| 
| I have some uncertainties especially about points 4 and 5. This should be 
| done in a way that all frontends can be easily hooked on. How would you guys 
| do this? Have virtual UpdateDialog and ListenToDialog functions that are 
| implemented separately for each frontend?
| 
| I am also not very familiar with sigc++ and its compatibility with the 
| signals and slots of qt2 (can we attach a qt2 signal to a sigc++ slot and 
| vice versa?)
| 
| Your help is greatly appreciated.
| 
| Greets, Edwin.
| 
| ps. is it Friday yet? ;-)

Not quite.

-- 
        Lgb

Reply via email to