473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

stream -> iobuf*

Is it possible in C++ to create some type of stream and pass something as
an iobuf* such that fprintf uses?

The reason is I am using some libraries that write to an open file pointer,
but I want to use the data in my program without having to change the
library source (all written in c).

--
Jim Langston
ta*******@rocketmail.com
Jun 27 '08 #1
3 5324
* Jim Langston:
Is it possible in C++ to create some type of stream and pass something as
an iobuf* such that fprintf uses?
'iobuf' is not a standard type (i.e., it's environment-specific).

The reason is I am using some libraries that write to an open file pointer,
but I want to use the data in my program without having to change the
library source (all written in c).
The description is a bit vague.

Depends what you want, but if you want to avoid disk access you might use a
memory mapped file. At the C++ stream level there's some support in Boost, as I
recall. At the C FILE* level I don't know, but surely something can be
arranged, although necessarily in a more or less environment specific manner.
Cheers, & hth.,

- Alf
Jun 27 '08 #2
Alf P. Steinbach wrote:
* Jim Langston:
> Is it possible in C++ to create some type of stream and pass
something as an iobuf* such that fprintf uses?

'iobuf' is not a standard type (i.e., it's environment-specific).

>The reason is I am using some libraries that write to an open file
pointer, but I want to use the data in my program without having to
change the library source (all written in c).

The description is a bit vague.

Depends what you want, but if you want to avoid disk access you might
use a memory mapped file. At the C++ stream level there's some
support in Boost, as I recall. At the C FILE* level I don't know,
but surely something can be arranged, although necessarily in a more
or less environment specific manner.
I just checked the Boost documentation online and didn't see anything that
would do it for me. Let me explain what I am wanting to do.

I am writing a program and it has some node type informatoin which I wish to
represent in a certain way. Looking around I found dot which text output
gives me exactly what I need for the data input. I downloaded the source
code and spent a day compiling it searching for the dependancies, getting
environment set up correctly, etc...

The program dot accepts input from a few methods, file, stdin for sure,
maybe memory. That I don't think I'll have too much trouble with although I
might. The real problem is the output. The output writes to stdout, a file
and looking through the docs into memory, except the memory portion doesn't
work for a few reasons. For one it leaks memory by allocating memory to a
pointer using malloc in a lib which can't be freed from the exe, doesn't
have a method to free it and doesn't allocate enough memory to begin. :Then
when it is used it tries to write to a FILE* which isn't created anyway and
crashes.

The source for thsi library, graphviz 2.18, is written in C, which is not
suprising considering it's apparent age, and is quite large, 1168 .c files
taking up 13,906,836 bytes. And that's not couting the headers. And it
does nasty things like having external global variables, etc.... To debug
and fix this will be quite a chore.

Well, what does work is stdin, stdout and fileio. So what I was hoping was
to be able to wrap dot in a class where I could pass it a memory block
loaded with the data to process (most likely contained in a std::vector),
have it call the libraries and catch either the file out put or stdout
output and return it to the program. Since it's C and not C++ it uses
stdout not std::cout so redirecting std::out's buffer isn't going to do me
much good.

I've been googling all day trying to find some method. The closest I've
found is some documentation talking about some VME low level driver
http://www.n4comm.com/utogenf.htm I think that if I created some type of
driver that caught the file output and kept it in a buffer that might be
workable, but will take me some time to develop (havn't written any drivers
yet would take some reasearch).

If nothing is doable I'll wind up hacking all the source code to get it to
work throwing away large portions of graphviz in the process as what I
implement breaks other things I have no need for at this time, but may in
the future. I don't like changing library source code when I don't have to.

--
Jim Langston
ta*******@rocketmail.com
Jun 27 '08 #3
* Jim Langston:
Alf P. Steinbach wrote:
>* Jim Langston:
>> Is it possible in C++ to create some type of stream and pass
something as an iobuf* such that fprintf uses?
'iobuf' is not a standard type (i.e., it's environment-specific).

>>The reason is I am using some libraries that write to an open file
pointer, but I want to use the data in my program without having to
change the library source (all written in c).
The description is a bit vague.

Depends what you want, but if you want to avoid disk access you might
use a memory mapped file. At the C++ stream level there's some
support in Boost, as I recall. At the C FILE* level I don't know,
but surely something can be arranged, although necessarily in a more
or less environment specific manner.

I just checked the Boost documentation online and didn't see anything that
would do it for me. Let me explain what I am wanting to do.

I am writing a program and it has some node type informatoin which I wish to
represent in a certain way. Looking around I found dot which text output
gives me exactly what I need for the data input. I downloaded the source
code and spent a day compiling it searching for the dependancies, getting
environment set up correctly, etc...

The program dot accepts input from a few methods, file, stdin for sure,
maybe memory. That I don't think I'll have too much trouble with although I
might. The real problem is the output. The output writes to stdout, a file
and looking through the docs into memory, except the memory portion doesn't
work for a few reasons. For one it leaks memory by allocating memory to a
pointer using malloc in a lib which can't be freed from the exe, doesn't
have a method to free it and doesn't allocate enough memory to begin. :Then
when it is used it tries to write to a FILE* which isn't created anyway and
crashes.

The source for thsi library, graphviz 2.18, is written in C, which is not
suprising considering it's apparent age, and is quite large, 1168 .c files
taking up 13,906,836 bytes. And that's not couting the headers. And it
does nasty things like having external global variables, etc.... To debug
and fix this will be quite a chore.

Well, what does work is stdin, stdout and fileio. So what I was hoping was
to be able to wrap dot in a class where I could pass it a memory block
loaded with the data to process (most likely contained in a std::vector),
have it call the libraries and catch either the file out put or stdout
output and return it to the program. Since it's C and not C++ it uses
stdout not std::cout so redirecting std::out's buffer isn't going to do me
much good.

I've been googling all day trying to find some method. The closest I've
found is some documentation talking about some VME low level driver
http://www.n4comm.com/utogenf.htm I think that if I created some type of
driver that caught the file output and kept it in a buffer that might be
workable, but will take me some time to develop (havn't written any drivers
yet would take some reasearch).

If nothing is doable I'll wind up hacking all the source code to get it to
work throwing away large portions of graphviz in the process as what I
implement breaks other things I have no need for at this time, but may in
the future. I don't like changing library source code when I don't have to.
It seems you need Boost.Process, which is in limbo (not accepted).

For the stream redirection you might think about Boost.Iostreams, they seem to
fit the bill (hm, I did this in C in 1984 or so, all was much easier then! :-) ).

However, for the process handling it seems you'll have to use environment
specific means, or some library other than Boost.
Cheers, & hth.,

- Alf
Jun 27 '08 #4

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

Similar topics

31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
10
by: Christopher Benson-Manica | last post by:
Sorry for the lame title, but it's hard to condense what I'm about to say... Here's my situation (my first real C++ situation, yay!). Currently we have a MyTCPThread (don't let the name scare you,...
16
by: Der Andere | last post by:
During every iteration in a loop, I need to convert a double value into a char*. Simple type-casting did not work, so I thought of using stringstreams. However, the stream would have to be...
4
by: Ook | last post by:
I'm a but fuzzy about this. You would call it like this:Polynomial poly; // Polynomial is my class with various properties cin >> poly; In the function itself, I would, for example, do the...
2
by: Brad Quinn | last post by:
Lets say I have an XmlNode that validates against some schema. I also have a class that was generated by the xsd tool using said schema. What is the best way to get from an XmlNode to an...
0
by: David Purton | last post by:
Hi, I have some ASP code to stream a binary file. It works well and looks something like the original ASP code shown below. I'm experimenting in creating ZIP files on the fly and am trying to...
2
by: noel.phillips | last post by:
Hi, I am porting a C++ console application to managed C++ dll - for now basically wrapping it in a class. The console app has the option to write to a file or stdout using fwrite. So, how do...
5
by: neowillis | last post by:
code: #include <iostream> #include <fstream> #include <string> using namespace std; int main() {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.