converting from OMANIP

J

Joe C

I'm in the process of trying to convert/recompile an existing C++
program, written in 1995, to compile and link in a Sun Solaris 8
environment using the C++ compiler that comes with Sun One Studio.

The old code uses the OMANIP macro that is not supported in the new
environment. The functionality of the class is to initialize an
ostream buffer and use manipulators to fill in portions of the buffer.
So for example I may have an ostream called mylabel. mylabel would be
initialized with "Name: City: State: Zip:
".

By invoking :

mylabel << Name("John Doe") << City("Austin") << State("Texas") <<
Zip("11111") the following output would be produced:

Name: John Doe City: Austin State: Texas Zip: 11111

Using the OMANIP macro the code looked like

mylabel::mylabel
{
.... (initialize buffer - my_LogBuffer) ...

OMANIP(std_string)
mylabel::Name(std_string name)
{
return OMANIP(std_string)(DoName, name);
}

ostream &
mylabel::DoName(ostream & o, std_string name)
{
((my_LogBuffer*)o.rdbuf())->m_name = name;
return o;
}

similar methods for City State and Zip
}

I looked at defining the operator << in this class, but I need to be
able to call different methods to change the buffer for a Name , City
etc. Thanks for any help.
 
I

Ivan Vecerina

Joe C said:
So for example I may have an ostream called mylabel. mylabel would be
initialized with "Name: City: State: Zip:
".

By invoking :

mylabel << Name("John Doe") << City("Austin") << State("Texas") <<
Zip("11111") the following output would be produced:

Name: John Doe City: Austin State: Texas Zip: 11111

Using the OMANIP macro the code looked like
[....]

If you would like to preserve your existing code as is, the best
might be to get a peek at the original implementation of the macro...

But you may want to consider changing your code and base it
on another free library. I would suggest one from boost:
http://www.boost.org/libs/format/index.htm

Boost is a popular collection of peer-reviewed C++ libraries,
designed to be candidates for inclusion in a future standard.
(and there are several successful examples...)


I hope this helps,
Ivan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top