Cryptography Reference
In-Depth Information
operators so that they support input and output of LINT objects. To this end the
class LINT defines the following stream operators:
friend ostream& operator<< (ostream& s, const LINT& ln);
friend fstream& operator<< (fstream& s, const LINT& ln);
friend ofstream& operator<< (ofstream& s, const LINT& ln);
friend fstream& operator>> (fstream& s, LINT& ln);
friend ifstream& operator>> (ifstream& s, LINT& ln);
A simple formulation of the overloaded insert operators for the output of LINT
objects might look something like the following:
#include <iostream.h>
ostream& operator<< (ostream& s, const LINT& ln)
{
if (ln.status == E_LINT_INV)
LINT::panic (E_LINT_VAL, "ostream operator <<", 0, __LINE__);
s << xclint2str (ln.n_l, 16, 0) << endl;
s << ld (ln) << " bit" << endl;
return s;
}
The operator << thus defined outputs the digits of a LINT object as hexadecimal
values and adds the binary length of the number in a separate line. In the next
section we shall consider the possibilities of improving the appearance of the
output of LINT objects with the aid of formatting functions, and we shall also use
manipulators to make the output customizable.
15.3.1 Formatted Output of LINT Objects
In this section we shall make use of the base class ios of the C++ standard library
and of its member functions to define our own LINT -specific formatting functions
for the purpose of controlling the output format of LINT objects. Furthermore, we
shall create manipulators that will make the customization of the output format
for LINT objects as simple as it is for the standard types defined in C++.
The crucial point in the creation of formatted output of LINT objects is the
possibility of setting formatting specifications that will be handled by the insert
operator. To this end we shall consider the mechanism provided for the class ios
(for details see [Teal], Chapter 6, and [Pla2], Chapter 6), whose member function
xalloc() in the objects of the classes derived from ios allocates a status variable
of type long and returns an index to this status variable also of type long . We store
this index in the long variable flagsindex . By means of this index the member
function ios::iword() can be used to access reading and writing to the allocated
status variable (cf. [Pla2], page 125).
 
Search WWH ::




Custom Search