"Victor Bazarov" <v.********@comAcast.net> writes:
Randy Yates wrote: [...]
Has NO one EVER wanted to "peek" (at more than one character at a
time) into an extractor stream???? I'm amazed the istream class
doesn't provide this function "out-of-the-box."
What's the point? Extract all available characters into a string-
based stream and peek (peer) as much as you need.
Character-based streams only have characters. And either they are
empty, or you can extract one and work on it. If your streams are
not file-based, extracting a single character can probably trigger
extraction of the next one. How would you peek at others?
Can you describe why you'd need to peek at more than one and what
is the reason extracting all available chars into a separate buffer
and working with it doesn't solve your problem?
Yes.
I need to peek at more than one character at a time because I'm trying
to match a string of the form "propertyX=valueY." I need to peek rather
than extract the characters because, if any one overloaded extractor
doesn't match the property/value pair being passed, the string should
stay "in the stream" for searching by other class instances (other
class member elements within a class).
It's like this. I've got a set of enumeration classes that are derived
from a CENUM(propertyName, comma-delimited-property-value-list) class that
defines a set of property/value pairs. Any one class, say, classA, may contain
several of these enumeration classes as member elements. For example,
class Cars : CENUM
{
CENUM("CARS", "Mustang, Pinto, Maverick"); /* am I showing my age? */
}
class Trucks : CENUM
{
CENUM("TRUCKS", "Mack, International");
}
class Vehicles
{
Cars cars;
Trucks trucks;
AnotherClass ac;
friend istream& operator>> (istream& is, Vehicles& vehicles);
}
I want to be able to "parse" a set of property/value pairs coming down
an istream like this:
istream& operator>> (istream& is, Vehicles& vehicles)
{
is >> vehicles.cars;
is >> vehicles.trucks;
is >> vehicles.ac;
return is;
}
So if I wanted to set the trucks parameter to "International", I
can simply stream the string "TRUCKS=International" into the
vehicles class.
I can't extract all available chars in any one overloaded extractor
because if the property/value pair doesn't match, I want it to
remain in the stream for passing to subsequent classes.
Does that help explain the predicament?
--
% Randy Yates % "Watching all the days go by...
%% Fuquay-Varina, NC % Who are you and who am I?"
%%% 919-577-9882 % 'Mission (A World Record)',
%%%% <ya***@ieee.org> % *A New World Record*, ELO
http://home.earthlink.net/~yatescr