472,372 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,372 software developers and data experts.

java style program objects in C++

I am wondering if any can point me to any open-source library with program
objects for C++ like there is in Java? I would like to be able to write
things like

MyProgram1 >> MyProgram2 >> Fork(MyProgram3, SomeFile);

If not would this be something of interest to others?

Thanks in advance,

--
Christopher Diggins
http://www.cdiggins.com
http://www.heron-language.com
Jul 22 '05 #1
11 2417
christopher diggins wrote:
I am wondering if any can point me to any open-source library with program
objects for C++ like there is in Java? I would like to be able to write
things like

MyProgram1 >> MyProgram2 >> Fork(MyProgram3, SomeFile);

The C++ language specification does not say about fork etc.

<OT>
Out of interest,

MyProgram1 >> MyProgram2 >> Fork(MyProgram3, SomeFile);

What is this supposed to mean ?
</OT>

If not would this be something of interest to others?


If you can ask this in a newsgroups specific to your OS,
you may get better answers.

--
Karthik.
Jul 22 '05 #2
Allow me to rephrase the question:

I want to write programs as objects. Given the source code from two
programs, I want to easily write a program, like I would a shell script. For
instance:

#include "program1.hpp"
#include "program2.hpp"

int main() {
program1() >> program2() >> filestream("c:\\temp.txt");
}

This would run the program1, store the output in a buffer. Then run program2
using the buffer as the standard in, and using the filestream as the
standard out. I want to do this without resorting to OS calls.

Thanks!

--
Christopher Diggins
http://www.cdiggins.com
http://www.heron-language.com
Jul 22 '05 #3

"christopher diggins" <cd******@videotron.ca> wrote in message
news:Po*******************@wagner.videotron.net...
Allow me to rephrase the question:

I want to write programs as objects. Given the source code from two
programs, I want to easily write a program, like I would a shell script. For
instance:

#include "program1.hpp"
#include "program2.hpp"

int main() {
program1() >> program2() >> filestream("c:\\temp.txt");
}

This would run the program1, store the output in a buffer. Then run program2
using the buffer as the standard in, and using the filestream as the
standard out. I want to do this without resorting to OS calls.


Hi Christopher,

Jan Christiaan van Winkel and John van Krieken outline something like this in
their paper "GNIRTS ESAC REWOL: Bringing UNIX filters to iostream" presented at
the ACCU spring conference in 2003. I can't find it on the web, but will send it
to you if you like.

They describe a filtering framework similar to the Boost Iostreams library. One
of the filters they define is a "UNIX filter" which pumps data through the
standard input and output of a child process given a command line. At some point
I'm planning to implement something like this for Boost.Iostreams, but right now
it's low on my list of priorities.

Use might look like this:

filtering_ostream out( system_filter("program1") |
system_filter("program2") |
file("C:/temp.txt") );
// Data written to out will be filtered through program1
// and program2 before being written to temp.txt.

Or, if program1 simply produces output:

filtering_ostream out( system_filter("program2") |
file("C:/temp.txt") );
boost::io::copy(program_source("program1"), out);

Jonathan
Jul 22 '05 #4

"Jonathan Turkanis" <te******@kangaroologic.com> wrote:
boost::io::copy(program_source("program1"), out);
This should probably be system_source("program1"). There would also be a
system_sink, for writing to the standard input of a child process.
Jonathan

Jul 22 '05 #5
"Jonathan Turkanis" <te******@kangaroologic.com> wrote in message
news:33*************@individual.net...

"christopher diggins" <cd******@videotron.ca> wrote in message
news:Po*******************@wagner.videotron.net...
Allow me to rephrase the question:

I want to write programs as objects. Given the source code from two
programs, I want to easily write a program, like I would a shell script.
For
instance:

#include "program1.hpp"
#include "program2.hpp"

int main() {
program1() >> program2() >> filestream("c:\\temp.txt");
}

This would run the program1, store the output in a buffer. Then run
program2
using the buffer as the standard in, and using the filestream as the
standard out. I want to do this without resorting to OS calls.


Hi Christopher,

Jan Christiaan van Winkel and John van Krieken outline something like this
in
their paper "GNIRTS ESAC REWOL: Bringing UNIX filters to iostream"
presented at
the ACCU spring conference in 2003. I can't find it on the web, but will
send it
to you if you like.

They describe a filtering framework similar to the Boost Iostreams
library. One
of the filters they define is a "UNIX filter" which pumps data through the
standard input and output of a child process given a command line. At some
point
I'm planning to implement something like this for Boost.Iostreams, but
right now
it's low on my list of priorities.


Hi Jonathan,

Thank you very much for suggesting this paper. I want to avoid using
processes due to their platform specificity. What I am looking for is a
library for building programs as objects in C++ (as done in Java), for
instance:

class Program {
virtual void Run() = 0;
// ...
}

class MyProgram1 : public Program {
void Run() {
// ...
}
...
}

class MyProgram2 : public Program {
void Run() {
// ...
}
...
}

class MyProgram3 : public Program {
void Run() {
MyProgram1() > MyProgram2();
}
}

int main() {
MyProgram3 p;
p.Run();
return 0;
}

Am I making sense? I am almost done a library which does exactly that, and I
want to make sure I am not reinventing the wheel.

--
Christopher Diggins
http://www.cdiggins.com
http://www.heron-language.com
Jul 22 '05 #6
I am writing a library which allows programs to be written as objects. This
is intended to make it easier to reuse programs to build new programs, in
part by redirecting their standard input and output. This is done without
resorting to OS specific calls, but rather through object oriented
programming techniques and operator overloading. What I am doing is
overloading the ">" operator so that:

1. Program > Program : The first program is run, with the stdout stored in
memory. When finished the stored output is fed to the stdin of the second
program
2. Program > char const* : The char const* is treated as a file name, and a
filestream is created, and the output
3. char const* > Program : just like #2, but the filestream is fed as
standard input to the program
4. std::string > Program : the string is fed as standard input to Program
5. Program > std::string : the output of program is stored in the string
variable

There are other combinations as well, and expressions can be built in
sequence such as:

Program > std::string > char const*;

This runs the program, redirects output to the string variable, and copies
it to a file as well.

The approach I am using requires that a programmer replace std::cin,
std::cout, and std::cerr with ootl::cin, ootl::cout, and ootl::cerr.

I have included an example of the technique in action below (which doesn't
compile because I haven't finished "programs.hpp" yet).

What I would like to know is
a) are there other libraries which already do this in a platform independant
manner
b) is this approach of interest to anyone
c) any suggestions or ideas on how to make it more powerful and interesting?
d) what should this technique be called?

//========================================

#include "programs.hpp"
#include <iostream>

using namespace ootl;

struct HelloWorldProgram : public Program {
HelloWorldProgram(int argc = 0, char** argv = NULL)
: Program(argc, argv) { }
virtual int Run() {
ootl::cin << "Hello world!\n" << std::endl;
return 0;
}
};

struct EchoProgram : public Program {
EchoProgram(int argc = 0, char** argv = NULL)
: Program(argc, argv) { }
virtual int Run() {
while (!ootl::cin.eof()) {
ootl::cout << ootl::cin.get();
}
return 0;
}
};

struct Test1 : public Program {
Test1(int argc = 0, char** argv = NULL)
: Program(argc, argv) { }
virtual int Run() {
HelloWorldProgram() > "c:\\tmp.txt" > EchoProgram();
std::string s;
"c:\\tmp.txt" > s;
s > EchoProgram();
return 0;
}
};

int main(int argc, char** argv) {
Test1 myProgram(argc, argv);
return myProgram.Run();
}

//==================================================

Thanks in advance!
Christopher Diggins
http://www.cdiggins.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #7

"christopher diggins" <cd******@videotron.ca> wrote in message
news:LT********************@wagner.videotron.net.. .
I am writing a library which allows programs to be written as objects. This
is intended to make it easier to reuse programs to build new programs, in
part by redirecting their standard input and output. This is done without
resorting to OS specific calls, but rather through object oriented
programming techniques and operator overloading. What I am doing is
overloading the ">" operator so that:

1. Program > Program : The first program is run, with the stdout stored in
memory. When finished the stored output is fed to the stdin of the second
program
2. Program > char const* : The char const* is treated as a file name, and
a
filestream is created, and the output
3. char const* > Program : just like #2, but the filestream is fed as
standard input to the program
4. std::string > Program : the string is fed as standard input to Program
5. Program > std::string : the output of program is stored in the string
variable

There are other combinations as well, and expressions can be built in
sequence such as:

Program > std::string > char const*;

This runs the program, redirects output to the string variable, and copies
it to a file as well.

The approach I am using requires that a programmer replace std::cin,
std::cout, and std::cerr with ootl::cin, ootl::cout, and ootl::cerr.

I have included an example of the technique in action below (which doesn't
compile because I haven't finished "programs.hpp" yet).

What I would like to know is
a) are there other libraries which already do this in a platform
independant
manner
b) is this approach of interest to anyone
c) any suggestions or ideas on how to make it more powerful and
interesting?
d) what should this technique be called?

//========================================

#include "programs.hpp"
#include <iostream>

using namespace ootl;

struct HelloWorldProgram : public Program {
HelloWorldProgram(int argc = 0, char** argv = NULL)
: Program(argc, argv) { }
virtual int Run() {
ootl::cin << "Hello world!\n" << std::endl;
return 0;
}
};

struct EchoProgram : public Program {
EchoProgram(int argc = 0, char** argv = NULL)
: Program(argc, argv) { }
virtual int Run() {
while (!ootl::cin.eof()) {
ootl::cout << ootl::cin.get();
}
return 0;
}
};

struct Test1 : public Program {
Test1(int argc = 0, char** argv = NULL)
: Program(argc, argv) { }
virtual int Run() {
HelloWorldProgram() > "c:\\tmp.txt" > EchoProgram();
std::string s;
"c:\\tmp.txt" > s;
s > EchoProgram();
return 0;
}
};

int main(int argc, char** argv) {
Test1 myProgram(argc, argv);
return myProgram.Run();
}


I'm confused as to how those objects are in any way "programs"...? Except
for the use of the > operator in the Test1 struct, they look like normal
source code to me. A program is generally considered to be an executable,
the result of compiling some source code, isn't it?

Also, this concept limits your idea of what a "program" is to processes
which operate in a fashion like 1) Take Input, 2) Process Data, 3) Report
Results. What about programs that interact with the user? And what about
programs whose "output" might exceed your buffer size? And what if I have a
program that needs the output of multiple other programs as its input,
instead of just the preceding one in the sequence?

I guess I just don't see what practical use this kind of design would be.
If I want to "build" on the abilities of one program when creating a new
one, it's the classes and their implementations that I usually want, and in
that case I just include the source code created for the old program(s) in
my new one. And if I want to pipe the output from one app to another, I do
so on the command line or a batch/script file (assuming support in the given
OS, of course).

Just my 2 cents, of course.

-Howard



Jul 22 '05 #8
> I'm confused as to how those objects are in any way "programs"...? Except
for the use of the > operator in the Test1 struct, they look like normal
source code to me. A program is generally considered to be an executable,
the result of compiling some source code, isn't it?
I was trying to show a way of writing a program so that it can be easily
included as is, in another program, and redirected.
Also, this concept limits your idea of what a "program" is to processes
which operate in a fashion like 1) Take Input, 2) Process Data, 3) Report
Results. What about programs that interact with the user? And what about
programs whose "output" might exceed your buffer size? And what if I have
a program that needs the output of multiple other programs as its input,
instead of just the preceding one in the sequence?
This is precisely the same problems that one has to deal with when piping
data from one program to another on the command line. Perhaps I should
rename the "program" to "filter_program" in reference to unix filters.
I guess I just don't see what practical use this kind of design would be.
If I want to "build" on the abilities of one program when creating a new
one, it's the classes and their implementations that I usually want, and
in that case I just include the source code created for the old program(s)
in my new one.
And if I want to pipe the output from one app to another, I do so on the
command line or a batch/script file (assuming support in the given OS, of
course).


The goal of my work is to provide command line style interface to source
code in C++. The problem with shell scripts is that every OS has a different
shell language (assuming you have an OS with a shell language), and
sometimes it is nice to execute shell-like commands from within the code.

What motivated this work is: I prefer to write lots of small programs, which
call each other. Always doing so from the OS is not portable at all, and is
not very useful.

--
Christopher Diggins
http://www.cdiggins.com
http://www.heron-language.com
Jul 22 '05 #9
On 2 Jan 2005 04:28:49 -0500, christopher diggins <cd******@videotron.ca> wrote:
....
1. Program > Program : The first program is run, with the stdout stored in
memory. When finished the stored output is fed to the stdin of the second
program .... What I would like to know is .... c) any suggestions or ideas on how to make it more powerful and interesting?


Well, I note that Unix shell pipes are infinitely more useful than those in
MS-DOS. Think of the tee(1) utility, for example -- noone would use it if it
delayed screen output until its provider was done.

Your 'p > p' seems to be of the MS-DOS kind, so that's an improvement
suggestion.

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #10
For what it's worth, I have completed the first version of the library for
reusing C++ program like unix filters:

fstream f("c:\\tmp.txt");
stringstream s;
HelloWorldProgram() > f > UpperCaseProgram() > s;

For those interested, the source and a detailed explanation are available at
http://www.codeproject.com/useritems...am-objects.asp

Christopher Diggins
http://www.cdiggins.com
http://www.heron-language.com
Jul 22 '05 #11
you want Python :-)

which is obviously off topic here :-)

Jul 22 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Patrick | last post by:
I'm using Jakarta-POI to create a huge Excel spreadsheet. I get the error below when the spreadsheet grows to a large size. It seems to have something to do with the number of "cell" objects that I...
73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
8
by: Steven T. Hatton | last post by:
I've had an idea kicking around in my head regarding how to create a library of classes (templates?) that provide the same kind of functionality as do Java classes which all derive from the UBC...
2
by: Michael | last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP, I am unable to find out why the "Build for Debug" option within Stored Procedure Builder is not enabled on Java stored...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
6
by: Rhino | last post by:
I'm trying to debug a simple Java UDF written in the DB2General style within Eclipse. I'm getting a java.lang.UnsatisfiedLinkError when I execute the set() method in the UDF. I know that the...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
5
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.