Streams
You can use the RAVL streams IStreamC, OStreamC, together with the standard C++
syntax of the I/O operators <<
and >>
, in
conjunction with most of the RAVL classes. These will read and write in ASCII
format, just as the standard C++ streams do for simple types. E.g. to load an
image of reals from standard input:
ImageC<RealT> x;
cin >> x;
This mechanism has been implemented for most of the RAVL classes. If you find
a class without it, please bug report.
N.B. For floating-point data types, there is generally a loss
of accuracy if data is written to a file in ASCII format and subsequently read
back in to a program.
You can use the same mechanism for reading from and writing to RAVL
strings, using the IStrStreamC and OStrStreamC classes. This is especially
useful for initialising small arrays, e.g.:
SArray1dC coeffs(5);
StrIStreamC ("5 0.363 0.291 0.135 0.012 -0.030") >> coeffs;
For some classes there are also stream operators for the BinIStreamC and BinOStreamC classes. These read and write
binary files. These streams have advantages over IStreamC and OStreamC: they
are faster; they are often more compact, and they store floating point data
without loss of precision. If you need this operator for the class you are
using, and it is not there, again it is worth asking.
- Both of the above input stream operators always
expect to read data in the format that is written by the corresponding
output streams, particularly in the case of
the more complex objects.
- Since the stream operators are not members of the classes being
read/written, they are not found in the class documentation itself. They
can however be found either in the namespace page, or in page listing
related classes.
Normal classes:
Normal functions:
Advanced functions: