FBB::A2x - Objects performing ascii-to-x (anything)
conversions
#include <bobcat/a2x>
Linking option: -lbobcat
FBB::A2x objects offer the C++ equivalent of the
standard C++ string conversion functions like stol, stoul,
stod etc. These standard C++ string functions are extremely
useful and should probably be preferred over using the members of A2x
objects, but A2x offers additional benefits in that it generalizes
these functions to any type that can be extracted from a
istream objects.
FBB
All constructors, members, and operators, mentioned in this man-page, are
defined in the namespace FBB.
- o
- A2x():
This constructor constructs an empty A2x object. No information can
be converted from a thus constructed A2x object.
- o
- A2x(char const *text):
This constructor stores text. If text represents a textual
value of some type, the A2x object may be used to initialize or
assign this value to a variable of that particular type. Extraction,
however is also still possible.
- o
- A2x(std::string const &str):
This constructor stores the text contained in str. If this text
represents a textual value of some type, the A2x object may be used
to initialize or assign this value to a variable of that particular type.
Extraction is also still possible.
The copy and move constructors are available.
- o
- bool lastFail():
This member returns true if the last conversion failed (i.e., the
object’s fail() member returned true and returns
false otherwise). This member allows checks on the success of the
extraction/conversion using anonymous A2x objects. The member also
returns true when no conversions have as yet been performed.
Note that this member returns the value of a thread_local static
member: different threads cannot inspect other threads’
lastFail status.
All members of the istringstream class are available.
- o
- Type to():
This member returns any type Type supporting extractions from
i[string]streams. If the extraction fails, the A2x
object’s good() member returns false, and the
Type’s default value is returned. This operator was
implemented as a template member function. There is also a type conversion
operator available (see below), but the member function variant may be
preferred over the conversion operator in situations where explicit
disambiguation is required (e.g., in cases where a conversion has no
obvious type solution such as direct insertions) An example is provided in
the EXAMPLE section below.
- o
- operator Type():
Conversion to any type Type supporting extractions from
istreams. If the extraction fails, the A2x object’s
good() member will return false, and the
Type’s default value is returned. This operator was
implemented as a member template.
- o
- istream &operator>>(istream &, Type &):
Extraction to any type Type supporting extractions from
istreams. If the extraction fails, the A2x object’s
good() member returns false, and the Type’s
default value is returned (this facility is implied by the fact that this
class inherits from istringstream, but it’s probably useful
to stress that the extraction operation is still available).
- o
- A2x &operator=(char const *):
Stores new text in the A2x object, resets the status flags to
ios::good. If a 0-pointer is passed, an empty string is
stored.
- o
- A2x &operator=(std::string const &):
Stores the text stored in the std::string argument in the A2x
object, resets the status flags to ios::good.
The overloaded assignment operator is available
int x = A2x("12");
A2x a2x("12.50");
double d;
d = a2x;
a2x = "err";
d = a2x; // d now 0
a2x = " a";
char c = a2x; // c now ’a’
// explicit conversion to `double’
cout << A2x("12.4").to<double>() << endl;
bobcat/a2x - defines the class interface
- o
- https://fbb-git.gitlab.io/bobcat/: gitlab project page;
- o
- bobcat_5.07.00-x.dsc: detached signature;
- o
- bobcat_5.07.00-x.tar.gz: source archive;
- o
- bobcat_5.07.00-x_i386.changes: change log;
- o
- libbobcat1_5.07.00-x_*.deb: debian package containing the
libraries;
- o
- libbobcat1-dev_5.07.00-x_*.deb: debian package containing the
libraries, headers and manual pages;
Bobcat is an acronym of `Brokken’s Own Base Classes And
Templates’.
This is free software, distributed under the terms of the GNU
General Public License (GPL).
Frank B. Brokken (f.b.brokken@rug.nl).