John Levon <[EMAIL PROTECTED]> writes:

| On 15 Jan 2001, Jean-Marc Lasgouttes wrote:
| 
| > That would probably be a good idea. One thing which would be nice too
| > is to declare the arguments expected by the func and maybe their type. 
| 
| Any suggestions on how this might work ?


for one arg LFUN (all LFUN's return what? bool?)

template<class F, class A>
class function_1_holder : public base_function {
public:
        typedef A Arg;
        typedef bool(Func)(A); // find correct syntax
        function_1_holder(F f) : f_(f) {}
        bool operator(A a) {
                return f_(a);  
        }
        bool operator(string const & arg) {
                // we know that there should be only one arg
                string first = <extract first arg or use whole string>;
                // f.ex. using lexical_cast throw exception if first
                // is not convertible to A
                try {
                        A a = lexical_cast<A>(first);
                        return operator(a);
                }
                catch (WrongType const & wt) {
                        lyxerr << "You stupid looser!!!" << endl;
                        throw;
                }
        }
private:
        Func f_;
};


And we could have a wrapper func for this:

template <class F, class A>
function_1_holder LyXFunction(bool(F f)(A)) {
        return function_1_holder(f);
}


This fits also nicely in the scheme I described in a previous mail.


        Lgb

Reply via email to