octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Redirectable octave?


From: Michael Goffioul
Subject: Re: Redirectable octave?
Date: Thu, 18 Oct 2007 11:54:20 +0200

On 10/18/07, Michael Goffioul <address@hidden> wrote:
> > In any case, I don't have plans to do something like this myself, but
> > I would perhaps consider patches after 3.0.
>
> OK, I can have a look at it. I just wanted to know whether it was worth
> working on it.

Here's a proposal for the standard IO interface that could be used in
octave. The idea is then to add 3 FILE* arguments to octave_main and
to call octave_standard_streams::init with those 3 args. In the normal
case, you end up using std::cin/cout/cerr.

Michael.

class octave_standard_streams
{
    static std::istream* in;
    static std::ostream* out;
    static std::ostream* err;

    static FILE* stdio_in;
    static FILE* stdio_out;
    static FILE* stdio_err;

public:
    static void init (FILE* _in = stdin, FILE* _out = stdout, FILE*
_err = stderr)
    {
        in = (_in != stdin ? new i_c_file_ptr_stream (_in) : &std::cin);
        out = (_out != stdout ? new o_c_file_ptr_stream (_out) : &std::cout);
        err = (_err != stderr ? new o_c_file_ptr_stream (_err) : &std::cerr);
        stdio_in = _in;
        stdio_out = _out;
        stdio_err = _err;
    }

    static std::istream& stream_in () { return *in; }
    static std::ostream& stream_out () { return *out; }
    static std::ostream& stream_err () { return *err; }

    static FILE* c_stream_in () { return stdio_in; }
    static FILE* c_stream_out () { return stdio_out; }
    static FILE* c_stream_err () { return stdio_err; }
};

std::istream* octave_standard_streams::in = 0;
std::ostream* octave_standard_streams::out = 0;
std::ostream* octave_standard_streams::err = 0;
FILE* octave_standard_streams::stdio_in = 0;
FILE* octave_standard_streams::stdio_out = 0;
FILE* octave_standard_streams::stdio_err = 0;

#define octave_cin octave_standard_streams::stream_in()
#define octave_cout octave_standard_streams::stream_out()
#define octave_cerr octave_standard_streams::stream_err()

#define octave_stdio_in octave_standard_streams::c_stream_in()
#define octave_stdio_out octave_standard_streams::c_stream_out()
#define octave_stdio_err octave_standard_streams::c_stream_err()


reply via email to

[Prev in Thread] Current Thread [Next in Thread]