Cryptography Reference
In-Depth Information
takes no argument and thus takes on the role of the
default
constructor of the
class
LINT
(cf. [Str1], Section 10.4.2). The following default constructor
LINT(void)
in
flintpp.cpp
creates a
LINT
object without assigning it a value:
LINT::LINT (void)
{
n_l = new CLINT;
if (NULL == n_l)
{
panic (E_LINT_NHP, "constructor 1", 0, __LINE__);
}
status = E_LINT_INV;
}
If a newly generated object is also to be initialized with a numerical value,
then a suitable constructor must be invoked to generate a
LINT
object and
then assign to it a predefined argument as the value. Depending on the type
of argument various overloaded constructors must be provided. The class
LINT
contains the constructor functions as shown in Table 14-1.
We would now like to consider a further example for the
LINT
construction of
the function
LINT (const char*)
, which generates a
LINT
object and associates
to it a value taken from a character string with ASCII digits. A prefix can be given
to the digits contained in the string that contains information about the base of
the numerical representation. If a character string is prefixed with
0x
or
0X
, then
hexadecimal digits from the domains
{
0,1,
...
,9
}
{
a,b,
...
,f
}
and
, respectively
{
A,B,
...
,F
}
, are expected. If the prefix is
0b
or
0B
, then binary digits from the set
{
0
,
1
}
are expected. If there is no prefix at all, then the digits are interpreted as
decimal digits. The constructor employs the function
str2clint_l()
to transform
the character string into an object of type
CLINT
, from which then in the second
step a
LINT
object is created:
LINT:: LINT (const char* str)
n_l = new CLINT;
if (NULL == n_l) // error with new?
{
panic (E_LINT _NHP, "constructor 4", 0, __LINE__);
}
if (strncmp (str, "0x", 2) == 0 || strncmp (str, "0X", 2) == 0)
{
int error = str2clint_l (n_l, (char*)str+2, 16);
}
else