SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

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 (const RWDecimalPortable &dp)
 
 RWDecimalPortable (long intPart)
 
 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 (RWFile &file)
 
void restoreFrom (RWvistream &vis)
 
void saveOn (RWFile &file) const
 
void saveOn (RWvostream &vos) const
 
void swap (RWDecimalPortable &rhs)
 
void trimZeros ()
 
- Public Member Functions inherited from RWDecimalBase
void swap (RWDecimalBase &rhs)
 

Friends

RWDecimalPortable operator* (const RWDecimalPortable &x, const RWDecimalPortable &y)
 
RWDecimalPortable operator+ (const RWDecimalPortable &x, const RWDecimalPortable &y)
 
RWDecimalPortable operator- (const RWDecimalPortable &x)
 
bool operator< (const RWDecimalPortable &x, const RWDecimalPortable &y)
 
bool operator== (const RWDecimalPortable &x, const RWDecimalPortable &y)
 
RWDecimalPortable round (const RWDecimalPortable &dp, RWssize_t digits, RWDecimalBase::RoundingMethod method=RWDecimalBase::PLAIN)
 
double toDouble (const RWDecimalPortable &dp)
 
long double toLongDouble (const RWDecimalPortable &dp)
 

Related Symbols

(Note that these are not member symbols.)

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)
Represents an arbitrary precision decimal fraction, providing maximum portability.
Definition tools/decport.h:103
bool isNumber() const
Definition tools/decport.h:217

Note that:

  • The validity or non-validity of the provided string is locale-dependent, as discussed below in the description for the constructor that takes a string, RWDecimalPortable(const char*).
  • In the first example above, the likely value of the RWDecimalPortable would be 555. That is, the string parser parses until it encounters an invalid character, and constructs the number from the characters up to that point.
Synopsis
#include <rw/tools/decport.h>
RWDecimalPortable dec; // construct a decimal == 0
dec = "1.23"; // construct a decimal == 1.23

Constructor & Destructor Documentation

◆ RWDecimalPortable() [1/5]

RWDecimalPortable::RWDecimalPortable ( )
inline

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

◆ RWDecimalPortable() [2/5]

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() [3/5]

RWDecimalPortable::RWDecimalPortable ( long intPart)
inline

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

◆ RWDecimalPortable() [4/5]

RWDecimalPortable::RWDecimalPortable ( const RWDecimalPortable & dp)

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

◆ RWDecimalPortable() [5/5]

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

◆ asString() [1/2]

RWCString RWDecimalPortable::asString ( ) 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.

◆ asString() [2/2]

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.

◆ binaryStoreSize()

size_t RWDecimalPortable::binaryStoreSize ( ) const
inline

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

◆ hash()

unsigned RWDecimalPortable::hash ( ) const
inline

Returns a value suitable for hashing.

◆ isNumber()

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.

◆ operator RWCString()

RWDecimalPortable::operator RWCString ( ) const
inline

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

◆ operator=() [1/2]

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

Assignment operator. Self is made a copy of dp.

◆ operator=() [2/2]

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.

◆ restoreFrom() [1/2]

void RWDecimalPortable::restoreFrom ( RWFile & file)

Reads file, replacing the contents of self.

◆ restoreFrom() [2/2]

void RWDecimalPortable::restoreFrom ( RWvistream & vis)

Reads vis, replacing the contents of self.

◆ saveOn() [1/2]

void RWDecimalPortable::saveOn ( RWFile & file) const

Writes the contents of self to file.

◆ saveOn() [2/2]

void RWDecimalPortable::saveOn ( RWvostream & vos) const

Writes the contents of self to vos.

◆ swap()

void RWDecimalPortable::swap ( RWDecimalPortable & rhs)
inline

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

◆ trimZeros()

void RWDecimalPortable::trimZeros ( )
inline

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

Friends And Related Symbol Documentation

◆ operator!=()

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

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

◆ operator*

RWDecimalPortable operator* ( const RWDecimalPortable & x,
const RWDecimalPortable & y )
friend

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

◆ operator+

RWDecimalPortable operator+ ( const RWDecimalPortable & x,
const RWDecimalPortable & y )
friend

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

◆ operator- [1/2]

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.

◆ operator-() [2/2]

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.

◆ operator<

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.

◆ operator<<()

std::ostream & operator<< ( std::ostream & ostrm,
const RWDecimalPortable & x )
related

Writes an RWDecimalPortable to an output stream.

◆ operator<=()

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.

◆ operator==

bool operator== ( const RWDecimalPortable & x,
const RWDecimalPortable & y )
friend

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

◆ operator>()

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.

◆ operator>=()

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.

◆ operator>>()

std::istream & operator>> ( std::istream & strm,
RWDecimalPortable & n )
related

Reads an RWDecimalPortable from an input stream.

◆ round

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

◆ RWssize_t

typedef unspecified_type RWssize_t
related

An unspecified signed integer type.

◆ toDouble

double toDouble ( const RWDecimalPortable & dp)
friend

Returns a double which approximates the value of dp.

◆ toLongDouble

long double toLongDouble ( const RWDecimalPortable & dp)
friend

Returns a long double which approximates the value of dp.

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