coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
integer Struct Reference

Class integer encapsulates an integer of some type. More...

#include <integer.h>

Public Member Functions

 integer (integer_type type=INT_INT, unsigned long long val=0)
 
integer_type type () const
 Get the type of the integer
 
bool good () const
 Say whether the integer is of valid type, not INT_UNDEF
 
size_t size () const
 Get the size of the integer
 
bool is_signed () const
 Say whether the integer is of signed type.
 
unsigned long long raw () const
 Get the bits comprising the integer as an unsigned long long
 
char const * type_desc () const
 Get the text descriptor of this integer's type.
 
int sign () const
 
integer operator< (integer const &rhs) const
 
integer operator<= (integer const &rhs) const
 
integer operator> (integer const &rhs) const
 
integer operator>= (integer const &rhs) const
 
integer operator== (integer const &rhs) const
 
integer operator!= (integer const &rhs) const
 
integer operator&& (integer const &rhs) const
 
integer operator|| (integer const &rhs) const
 
integer operator& (integer const &rhs) const
 
integer operator| (integer const &rhs) const
 
integer operator^ (integer const &rhs) const
 
integer operator! () const
 
integer operator~ () const
 
integer operator- () const
 
integer operator+ () const
 
integer operator+ (integer const &rhs) const
 
integer operator- (integer const &rhs) const
 
integer operator* (integer const &rhs) const
 
integer operator/ (integer const &rhs) const
 
integer operator% (integer const &rhs) const
 
integer operator<< (integer const &rhs) const
 
integer operator>> (integer const &rhs) const
 

Private Member Functions

unsigned rank () const
 Get the conversion rank of an integer
 
void make_unsigned ()
 Make the integer unsigned.
 
void make_signed ()
 Make the integer signed.
 

Static Private Member Functions

static integer_type to_unsigned (integer_type type)
 
static integer_type to_signed (integer_type type)
 
static unsigned rank_of (integer_type type)
 
static integer_type result_type (integer const &lhs, integer const &rhs)
 
static bool valid_shift (int direction, integer const &lhs, integer const &rhs)
 
static char const * type_desc (integer_type it)
 Get textual descriptor of an integral type.
 

Private Attributes

unsigned long long _val
 The value of the integer
 
integer_type _type
 The type of the integer.
 

Friends

struct integer_constant
 

Detailed Description

Class integer encapsulates an integer of some type.

Definition at line 65 of file integer.h.

Constructor & Destructor Documentation

integer::integer ( integer_type  type = INT_INT,
unsigned long long  val = 0 
)
inlineexplicit

Explicitly construct given a type and value.

Parameters
typeThe type of the integer
valThe value of the integer

Definition at line 73 of file integer.h.

Member Function Documentation

integer integer::operator! ( ) const
inline

Logically negate an integer.

Returns
1 if the integer == 0, else 0.

Definition at line 178 of file integer.h.

integer integer::operator!= ( integer const &  rhs) const

Test whether the integer is not equal to another.

Parameters
rhsThe other integer to be compared.
Returns
1 iff the comparison is true, else 0.

Definition at line 221 of file integer.cpp.

integer integer::operator% ( integer const &  rhs) const

Mod the integer by another.

Parameters
rhsmodulus.
Returns
The result of the mod operation.

Definition at line 514 of file integer.cpp.

integer integer::operator& ( integer const &  rhs) const

Bitwise AND the integer with another.

Parameters
rhsThe other integer.
Returns
The result of the operation.

Definition at line 313 of file integer.cpp.

integer integer::operator&& ( integer const &  rhs) const

Logically AND the integer with another.

Parameters
rhsThe other integer to be conjoined.
Returns
1 iff the conjunction is true, else 0.

Definition at line 267 of file integer.cpp.

integer integer::operator* ( integer const &  rhs) const

Multiply the integer by another.

Parameters
rhsThe multiplier.
Returns
The result of the multiplication.

Definition at line 468 of file integer.cpp.

integer integer::operator+ ( ) const
inline

Apply unary plus to an integer.

Returns
The result of the operation.

Definition at line 195 of file integer.h.

integer integer::operator+ ( integer const &  rhs) const

Add the integer to another

Parameters
rhsThe other integer to be added.
Returns
The result of the addition.

Definition at line 422 of file integer.cpp.

integer integer::operator- ( ) const

Invert the sign of an integer.

Returns
The result of the operation.

Definition at line 382 of file integer.cpp.

integer integer::operator- ( integer const &  rhs) const

Subtract an integer from *this.

Parameters
rhsThe integer to be subtracted.
Returns
The result of the subtraction.

Definition at line 445 of file integer.cpp.

integer integer::operator/ ( integer const &  rhs) const

Divide the integer by another.

Parameters
rhsThe divisor.
Returns
The result of the division.

Definition at line 491 of file integer.cpp.

integer integer::operator< ( integer const &  rhs) const

Test whether the integer is less than another.

Parameters
rhsThe other integer to be compared.
Returns
1 iff the comparison is true, else 0.

Definition at line 129 of file integer.cpp.

integer integer::operator<< ( integer const &  rhs) const

Left-shift integer by another.

Parameters
rhsThe shift value.
Returns
The result of the left-shift.

Definition at line 537 of file integer.cpp.

integer integer::operator<= ( integer const &  rhs) const

Test whether the integer is less than or equal to another.

Parameters
rhsThe other integer to be compared.
Returns
1 iff the comparison is true, else 0.

Definition at line 152 of file integer.cpp.

integer integer::operator== ( integer const &  rhs) const

Test whether the integer is equal to another.

Parameters
rhsThe other integer to be compared.
Returns
1 iff the comparison is true, else 0.

Definition at line 244 of file integer.cpp.

integer integer::operator> ( integer const &  rhs) const

Test whether the integer is greater than another.

Parameters
rhsThe other integer to be compared.
Returns
1 iff the comparison is true, else 0.

Definition at line 175 of file integer.cpp.

integer integer::operator>= ( integer const &  rhs) const

Test whether the integer is greater than or equal to another.

Parameters
rhsThe other integer to be compared.
Returns
1 iff the comparison is true, else 0.

Definition at line 198 of file integer.cpp.

integer integer::operator>> ( integer const &  rhs) const

Right-shift the integer by another.

Parameters
rhsThe shift-value.
Returns
The result of the right-shift.

Definition at line 563 of file integer.cpp.

integer integer::operator^ ( integer const &  rhs) const

Bitwise XOR the integer with another.

Parameters
rhsThe other integer.
Returns
The result of the operation.

Definition at line 359 of file integer.cpp.

integer integer::operator| ( integer const &  rhs) const

Bitwise OR the integer with another.

Parameters
rhsThe other integer.
Returns
The result of the operation.

Definition at line 336 of file integer.cpp.

integer integer::operator|| ( integer const &  rhs) const

Logically OR the integer with another.

Parameters
rhsThe other integer to be disjoined.
Returns
1 iff the disjunction is true, else 0.

Definition at line 290 of file integer.cpp.

integer integer::operator~ ( ) const

Bitwise negate an integer.

Returns
The result of the operation.

Definition at line 402 of file integer.cpp.

static unsigned integer::rank_of ( integer_type  type)
inlinestaticprivate

Get the conversion rank of an integer type

Parameters
typeThe type whose conversion rank is wanted.
Returns
The conversion rank of type.

Definition at line 263 of file integer.h.

integer_type integer::result_type ( integer const &  lhs,
integer const &  rhs 
)
staticprivate

Get the integer_type that results when the the usual arithmetic conversions are applied to on a pair of integer arithmetic operands.

Parameters
lhsThe lefthand operand
rhsThe righthand operand
Returns
If either operand's type is INT_UNDEF the returned type is INT_UNDEF. Otherwise it is the maximum of lhs.type() and rhs.type(). The constants of enum integer_type are so defined as to make this the correct result.

The function emits a warning if the usual arithmetic conversions result in a change of sign on either operand.

Definition at line 69 of file integer.cpp.

int integer::sign ( ) const

Return the sign of an integer's value.

Returns
-1 if the value is of signed integral type and is negative, 1 if the value is of signed integral type and is non-negative; otherwise 0.

Definition at line 48 of file integer.cpp.

static integer_type integer::to_signed ( integer_type  type)
inlinestaticprivate

Get the signed variant to an integer type

Parameters
typeThe type whose signed variant is wanted.
Returns
The signed variant of type.

Definition at line 255 of file integer.h.

static integer_type integer::to_unsigned ( integer_type  type)
inlinestaticprivate

Get the unsigned variant to an integer type

Parameters
typeThe type whose unsigned variant is wanted.
Returns
The unsigned variant of type.

Definition at line 247 of file integer.h.

bool integer::valid_shift ( int  direction,
integer const &  lhs,
integer const &  rhs 
)
staticprivate

Check the validity of a shift operation. A shift has undefined behaviour if the promoted righthand operand is negative or is >= the width in bits of the lefthand operand.

Parameters
directionIf < 0, a left shift is indicated, else a right-shift.
lhsThe lefthand operand.
rhsThe righthand operand.
Returns
True if the shift operation is valid. Otherwise the function returns false and issues a diagnostic.

Definition at line 105 of file integer.cpp.


The documentation for this struct was generated from the following files: