|
Boost : |
From: christopher diggins (cdiggins_at_[hidden])
Date: 2005-01-07 14:42:23
----- Original Message -----
From: "Rob Stewart" <stewart_at_[hidden]>
To: <boost_at_[hidden]>
Cc: <boost_at_[hidden]>
Sent: Friday, January 07, 2005 2:00 PM
Subject: Re: [boost] Any interest in a library for supporting program reuse?
>> What would you suggest the name of the class be instead? It is intended
>> to
>> provide the main entry point for a program, so that the program can be
>> easily reused separately.
>
>>From what I see, you're packaging functions, not system() calls
> to executables or separate processes connected by some IPC.
I am trying to describe a way to write a C++ program by packaging the entire
thing (entry point, global functions, global variable) in a single object.
So what I propose is that rather than write a program in a single cpp file
as follows:
/////////////////
// my_prog.cpp
#include <iostream>
char const* s = "hello world\n"
int main() {
std::cout << s << std::endl;
return 0;
}
Instead what I propose is that instead you write the programs in two files
as:
/////////////////
// my_prog.hpp
#include "programs.hpp"
#include <iostream>
class MyProgram : Program {
const char* s;
protected:
virtual void Main() {
std::cout << s << std::endl;
}
};
char const* MyProgram::s = "hello world\n";
/////////////////
// my_prog.cpp
#include "my_prog.hpp"
int main() {
MyProgram().Run();
return 0;
}
Now having done that, the entire program can now be treated as a single
object which can be redirected or piped.
/////////////////
// my_prog3.hpp
#include <fstream>
#include "programs.hpp"
#include "my_prog.hpp"
#include "my_prog2.hpp"
class MyProgram3 : Program {
protected:
virtual void Main() {
MyProgram() > MyProgram2() > filestream("c:\\tmp.txt");
}
};
My desire is to make it trivial to reuse the entire source code from
programs, using a simple syntax as if they were shell scripts, and in a
completely portable manner from within C++. This foregoes any kind of
process call or whatever, because in C++ the notion of threads or process
doesn't exist. I have written a small blog entry on the subject as well at
http://www.artima.com/weblogs/viewpost.jsp?thread=87459
Is it more clear what I am trying to get at? Am I missing something about
Jonathan's iostreams library, that makes it trivial to achieve the same
thing?
CD
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk