473,737 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2608
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.h pp"
#include "program2.h pp"

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

"christophe r diggins" <cd******@video tron.ca> wrote in message
news:Po******** ***********@wag ner.videotron.n et...
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.h pp"
#include "program2.h pp"

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_ostre am 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_ostre am out( system_filter(" program2") |
file("C:/temp.txt") );
boost::io::copy (program_source ("program1") , out);

Jonathan
Jul 22 '05 #4

"Jonathan Turkanis" <te******@kanga roologic.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******@kanga roologic.com> wrote in message
news:33******** *****@individua l.net...

"christophe r diggins" <cd******@video tron.ca> wrote in message
news:Po******** ***********@wag ner.videotron.n et...
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.h pp"
#include "program2.h pp"

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.h pp" 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.h pp"
#include <iostream>

using namespace ootl;

struct HelloWorldProgr am : public Program {
HelloWorldProgr am(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() {
HelloWorldProgr am() > "c:\\tmp.tx t" > EchoProgram();
std::string s;
"c:\\tmp.tx t" > 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++.m oderated. First time posters: Do this! ]
Jul 22 '05 #7

"christophe r diggins" <cd******@video tron.ca> wrote in message
news:LT******** ************@wa gner.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.h pp" 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.h pp"
#include <iostream>

using namespace ootl;

struct HelloWorldProgr am : public Program {
HelloWorldProgr am(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() {
HelloWorldProgr am() > "c:\\tmp.tx t" > EchoProgram();
std::string s;
"c:\\tmp.tx t" > 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******@video tron.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++.m oderated. First time posters: Do this! ]
Jul 22 '05 #10

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

Similar topics

2
3958
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 create. If I destroy other objects that I don't need any more, then I can create more "cell" objects. Unfortunately, I cannot destroy any more of my other objects without breaking the program. This does not appear to be a problem that is...
73
8045
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 as a standard portable part of the core language, the LISP package, and the java.lang package, respectively. Both have big integers, although only LISP has rationals as far as I can tell. Because CL supports keyword arguments, it has a wider range...
11
9266
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 C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
8
2040
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 Object. There is no UBC in C++, nor will there ever be one (well, there actually /is/ a UBC in C++, but it is a pure abstraction). One feature of user defined Java classes is that they all have a member derived from the java.lang.Class object. The...
2
3148
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 procedures. It is enabled for SQL stored procedures. It is possible to "Build" and "Run" the Java SPs, it just isn't possible to click on the "Build for Debug" option. Thanks for any help in advance. Michael
1
9649
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 and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
6
2437
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 UnsatisfiedLinkError has something to do with a DLL that is not visible but I'm not sure why I'm having the problem given that both db2java.zip and db2jcc.jar are visible on my classpath and each of them contain the COM.ibm.db2.app.UDF class with a...
458
21332
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 simply aren't smart enough to understand C++? This is not merely a whimsical hypothesis. Given my experience with Java programmers --- the code they write and the conversations they have --- Occam's Razor points to this explanation. For example,...
5
6286
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 JDK 6 downloadable from http://java.sun.com/javase/downloads/index.jsp. I will be using JDK 5(update 8)
0
8966
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9331
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9257
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4567
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4823
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3278
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.