SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Friends | Related Functions

Represents an arbitrary precision decimal fraction, providing maximum portability. More...

#include <rw/tools/decport.h>

Inheritance diagram for RWDecimalPortable:
RWDecimalBase

Public Member Functions

 RWDecimalPortable ()
 
 RWDecimalPortable (const char *input)
 
 RWDecimalPortable (long intPart)
 
 RWDecimalPortable (const RWDecimalPortable &dp)
 
 RWDecimalPortable (RWDecimalPortable &&dp)
 
RWCString asString () const
 
RWCString asString (const RWLocale &loc) const
 
size_t binaryStoreSize () const
 
unsigned hash () const
 
bool isNumber () const
 
 operator RWCString () const
 
RWDecimalPortableoperator= (const RWDecimalPortable &dp)
 
RWDecimalPortableoperator= (RWDecimalPortable &&dp)
 
void restoreFrom (RWvistream &vis)
 
void restoreFrom (RWFile &file)
 
void saveOn (RWvostream &vos) const
 
void saveOn (RWFile &file) const
 
void swap (RWDecimalPortable &rhs)
 
void trimZeros ()
 
- Public Member Functions inherited from RWDecimalBase
void swap (RWDecimalBase &rhs)
 

Friends

RWDecimalPortable operator* (const RWDecimalPortable &, const RWDecimalPortable &)
 
RWDecimalPortable operator+ (const RWDecimalPortable &, const RWDecimalPortable &)
 
RWDecimalPortable operator- (const RWDecimalPortable &)
 
bool operator< (const RWDecimalPortable &x, const RWDecimalPortable &y)
 
bool operator== (const RWDecimalPortable &x, const RWDecimalPortable &y)
 
RWDecimalPortable round (const RWDecimalPortable &, RWssize_t, RoundingMethod)
 
double toDouble (const RWDecimalPortable &)
 
long double toLongDouble (const RWDecimalPortable &)
 

Related Functions

(Note that these are not member functions.)

bool operator!= (const RWDecimalPortable &x, const RWDecimalPortable &y)
 
RWDecimalPortable operator- (const RWDecimalPortable &x, const RWDecimalPortable &y)
 
std::ostream & operator<< (std::ostream &ostrm, const RWDecimalPortable &x)
 
bool operator<= (const RWDecimalPortable &x, const RWDecimalPortable &y)
 
bool operator> (const RWDecimalPortable &x, const RWDecimalPortable &y)
 
bool operator>= (const RWDecimalPortable &x, const RWDecimalPortable &y)
 
std::istream & operator>> (std::istream &strm, RWDecimalPortable &n)
 
typedef unspecified_type RWssize_t
 

Additional Inherited Members

- Public Types inherited from RWDecimalBase
enum  Op {
  assign, add, sub, mult,
  div, powop, pow10op, conversion
}
 
enum  RoundingMethod {
  PLAIN, UP, DOWN, BANKERS,
  TRUNCATE
}
 
enum  State {
  normal, nullstate, NaNstate, ctorError,
  missingstate, SNaNstate, infinitystate
}
 

Detailed Description

RWDecimalPortable represents an arbitrary precision decimal fraction.

The RWDecimalPortable class is designed to provide maximum portability. However, its portability is gained at the expense of speed and power. For example, RWDecimalPortable does not support all functionality of the other decimal classes in the Currency Module. In most cases we recommend that you use another of the decimal classes from the Currency Module, but in situations in which the portability of a number is paramount, RWDecimalPortable is useful.

When constructing an RWDecimalPortable from a string, the constructor parses the initial characters of the string until the first non-digit, behaving similarly to the C++ Standard Library function std::strtod(). For example, a string "12E3" creates an RWDecimalPortable value of 12000.

If an RWDecimalPortable is provided an invalid string, either in the constructor or through assignment, it does not throw an exception. Use isNumber() to determine if the object is valid.

RWDecimalPortable a("555AAA");
a.isNumber(); // returns true
b = "A555AAA";
b.isNumber(); // returns false (NAN)

Note that:

Synopsis
#include <rw/tools/decport.h>
RWDecimalPortable dec; // construct a decimal == 0
dec = "1.23"; // construct a decimal == 1.23

Constructor & Destructor Documentation

RWDecimalPortable::RWDecimalPortable ( )
inline

The default constructor creates a value initialized to zero (0).

RWDecimalPortable::RWDecimalPortable ( const char *  input)

Parses the initial portion of input formatted as a decimal number up to the end of the string, or the first non-decimal character, whichever comes first. The parse behavior is locale-dependent (for decimal points, thousands separator, grouping, etc). If no locale is specified, the default locale is used, and parsing behavior will be defined by that locale, creating possibly unexpected results. To ensure predictable and expected behavior, the program should explicitly specify the locale before using this constructor, and input strings should be formatted according the numeric string facets for that locale.

For more information on conversions between strings and numbers, see the section on numbers in the internationalization chapter of the Essential Tools Module User's Guide.

RWDecimalPortable::RWDecimalPortable ( long  intPart)
inline

Constructs a value with intPart as the part before the decimal point.

RWDecimalPortable::RWDecimalPortable ( const RWDecimalPortable dp)

Copy constructor. The constructed instance is a copy of dp.

RWDecimalPortable::RWDecimalPortable ( RWDecimalPortable &&  dp)

Move constructor. The constructed instance takes ownership of the data owned by dp.

Condition:
This method is available only on platforms with rvalue reference support.

Member Function Documentation

RWCString RWDecimalPortable::asString ( void  ) const
inline

Returns self as an RWCString using the global locale as determined by the static member function RWLocale::global() for numeric formatting. For example, an English locale could return strings such as -23.21, 0.32, or 432.

RWCString RWDecimalPortable::asString ( const RWLocale loc) const

Returns self as an RWCString using the provided RWLocale instance for numeric formatting. For example, an English locale could return strings such as -23.21, 0.32, or 432.

size_t RWDecimalPortable::binaryStoreSize ( ) const
inline

Returns the number of bytes required to store self using the saveOn() methods.

unsigned RWDecimalPortable::hash ( ) const
inline

Returns a value suitable for hashing.

bool RWDecimalPortable::isNumber ( ) const
inline

Returns false if self represents a NaN, a missing value, infinity or a NULL; otherwise returns true.

Note
In this instance, the mathematical rather than the RDBMS meaning of NULL is intended. Please see RWDBNullIndicator.
RWDecimalPortable::operator RWCString ( ) const
inline

Returns self as an RWCString. Format is, for example -23.21 or 0.32 or 432.

RWDecimalPortable& RWDecimalPortable::operator= ( const RWDecimalPortable dp)

Assignment operator. Self is made a copy of dp.

RWDecimalPortable& RWDecimalPortable::operator= ( RWDecimalPortable &&  dp)

Move assignment. Self takes ownership of the data owned by dp.

Condition:
This method is available only on platforms with rvalue reference support.
void RWDecimalPortable::restoreFrom ( RWvistream vis)

Reads vis, replacing the contents of self.

void RWDecimalPortable::restoreFrom ( RWFile file)

Reads file, replacing the contents of self.

void RWDecimalPortable::saveOn ( RWvostream vos) const

Writes the contents of self to vos.

void RWDecimalPortable::saveOn ( RWFile file) const

Writes the contents of self to file.

void RWDecimalPortable::swap ( RWDecimalPortable rhs)
inline

Swaps the data owned by self with the data owned by rhs.

void RWDecimalPortable::trimZeros ( )
inline

Removes leading zeros before self's decimal point and trailing zeros after.

Friends And Related Function Documentation

bool operator!= ( const RWDecimalPortable x,
const RWDecimalPortable y 
)
related

Relational operator. Returns true if x is not equal to y.

RWDecimalPortable operator* ( const RWDecimalPortable ,
const RWDecimalPortable  
)
friend

Rudimentary multiplication operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.

RWDecimalPortable operator+ ( const RWDecimalPortable ,
const RWDecimalPortable  
)
friend

Rudimentary addition operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.

RWDecimalPortable operator- ( const RWDecimalPortable x)
friend

Rudimentary negation operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.

RWDecimalPortable operator- ( const RWDecimalPortable x,
const RWDecimalPortable y 
)
related

Rudimentary subtraction operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.

bool operator< ( const RWDecimalPortable x,
const RWDecimalPortable y 
)
friend

Relational operator. Returns true if x is less than y.

Note
If the state of either one of the operands is anything other than normal or infinitystate, the result of the operator is undefined.
std::ostream & operator<< ( std::ostream &  ostrm,
const RWDecimalPortable x 
)
related

Writes an RWDecimalPortable to an output stream.

bool operator<= ( const RWDecimalPortable x,
const RWDecimalPortable y 
)
related

Relational operator. Returns true if x is less than or equal to y.

Note
If the state of either one of the operands is anything other than normal or infinitystate, the result of the operator is undefined.
bool operator== ( const RWDecimalPortable x,
const RWDecimalPortable y 
)
friend

Relational operator. Returns true if x is equal to y.

bool operator> ( const RWDecimalPortable x,
const RWDecimalPortable y 
)
related

Relational operator. Returns true if x is greater than y.

Note
If the state of either one of the operands is anything other than normal or infinitystate, the result of the operator is undefined.
bool operator>= ( const RWDecimalPortable x,
const RWDecimalPortable y 
)
related

Relational operator. Returns true if x is greater than or equal to y.

Note
If the state of either one of the operands is anything other than normal or infinitystate, the result of the operator is undefined.
std::istream & operator>> ( std::istream &  strm,
RWDecimalPortable n 
)
related

Reads an RWDecimalPortable from an input stream.

RWDecimalPortable round ( const RWDecimalPortable ,
RWssize_t  ,
RoundingMethod   
)
friend

Returns an RWDecimalPortable which is the result of rounding self according to the applied specifications.

typedef unspecified_type RWssize_t
related

An unspecified signed integer type.

double toDouble ( const RWDecimalPortable )
friend

Returns a double which approximates the value of dp.

long double toLongDouble ( const RWDecimalPortable )
friend

Returns a long double which approximates the value of dp.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.