This class provides some printing and cropping utilities. More...
#include <PrintCtrl.h>
Public Types | |
enum | CROP_TYPE { CT_OFF = 0, CT_OFF_GLOBALOBEY, CT_ON_GLOBALOBEY, CT_ON } |
enum for cropping control More... | |
enum | CROP_TYPE_GLOBAL { GCT_NOPREF = 0, GCT_CROP, GCT_NOCROP } |
enum for global cropping control More... | |
Public Member Functions | |
PrintCtrl (std::ostream &coutProxy=std::cout, int Ndec=-1000, CROP_TYPE ctlocal=CT_ON) | |
Constructor. | |
void | pr_de (const double d, int sigDigits=-1, const int wMin=-1, const int wMax=-1) |
Print a double using scientific notation. | |
void | pr_de_c10 (const double d, int sigDigits=-1, const int wMin=-1, const int wMax=-1) |
Print a double using scientific notation cropping decade values. | |
double | cropSigDigits (const double d, int sigDigits) const |
Crop a double at a certain number of significant digits. | |
double | cropAbs10 (const double d, const int nDecades) const |
Crop a double at a certain decade level. | |
int | setNdec (int nDecades) |
Set the default value of N decade. | |
int | setSigDigits (int sigDigits) |
Set the default significant digits to output. | |
int | setWmin (int wMin) |
Set the default minimum width. | |
int | setWmax (int wMax) |
Set the default maximum width. | |
void | setCropCntrl (CROP_TYPE ctlocal) |
Set the cropping control flag. | |
Static Public Attributes | |
static CROP_TYPE_GLOBAL | GlobalCrop = GCT_NOPREF |
static enum for turning on and off cropping | |
Private Member Functions | |
bool | doCrop () const |
private function to figure out cropping logic | |
Private Attributes | |
std::ostream & | m_cout |
This is the ostream to send all output from the object. | |
int | m_Ndec |
Default decade level to use for decade cropping. | |
int | m_precision |
default precision level to use in printing | |
int | m_wMin |
default minimimum field width | |
int | m_wMax |
Default maximum field width. | |
CROP_TYPE | m_cropCntrl |
Local Cropping Control. |
This class provides some printing and cropping utilities.
The class is used to provide some formatting options for printing out real numbers to files and to standard output. Specifically, it can make sure that a max and min field width is honored when conducting IO of numbers and strings. Basically, its the spot to house all wrappers around commonly used printing facilities.
It can also handle cropping of numbers below a certain decade level. This is useful for IO for testing purposes. For example, if you don't care about anything below 1.0E-20, you can set up the IO so that it won't print out any digits below 1.0E-20, even digits that are in numbers greater than 1.0E-20. In other words the number
1.12345E-19
whould be cropped to the value
1.1000E-19
The class wraps aroud a single std::ostream class. It's cropping functions are also available as a "double" conversion utility.
Definition at line 54 of file PrintCtrl.h.
enum CROP_TYPE |
enum for cropping control
Definition at line 58 of file PrintCtrl.h.
enum CROP_TYPE_GLOBAL |
enum for global cropping control
GCT_NOPREF |
no preference for global cropping |
GCT_CROP |
global toggle for turning on cropping |
GCT_NOCROP |
global toggle for turning off cropping |
Definition at line 70 of file PrintCtrl.h.
Constructor.
This also serves to initialize the ticks within the object
coutProxy | This is a reference to the ostream to use for all IO from ths object. | |
Ndec | value of Ndec. Defaults to -1000, i.e., no decade cropping | |
ctlocal | The default is to turn on cropping all the time. |
Definition at line 34 of file PrintCtrl.cpp.
double cropAbs10 | ( | const double | d, | |
const int | nDecades | |||
) | const |
Crop a double at a certain decade level.
This routine will crop a floating point number at a certain decade lvl. In other words everything below a power of 10^Ndec will be deleted. Note, it does rounding up of the last digit.
d | Double to be cropped | |
nDecades | Number of significant digits example: d = 1.1305E-15; nDecades = -16; This routine will return 1.1E-15 |
d = 8.0E-17 nDecades = -16 This routine will return 0.0
Definition at line 148 of file PrintCtrl.cpp.
References PrintCtrl::cropSigDigits(), and PrintCtrl::doCrop().
Referenced by LogPrintCtrl::cropAbs10(), and PrintCtrl::pr_de_c10().
double cropSigDigits | ( | const double | d, | |
int | sigDigits | |||
) | const |
Crop a double at a certain number of significant digits.
This routine will crop a floating point number at a certain number of significant digits. Note, it does rounding up of the last digit.
d | Double to be cropped | |
sigDigits | Number of significant digits example: d = 1.0305E-15; nsig = 3; This routine will return 1.03E-15 |
Definition at line 183 of file PrintCtrl.cpp.
References PrintCtrl::doCrop().
Referenced by PrintCtrl::cropAbs10(), and LogPrintCtrl::cropSigDigits().
bool doCrop | ( | ) | const [private] |
private function to figure out cropping logic
Definition at line 260 of file PrintCtrl.cpp.
References PrintCtrl::CT_OFF_GLOBALOBEY, PrintCtrl::CT_ON, PrintCtrl::CT_ON_GLOBALOBEY, PrintCtrl::GCT_CROP, PrintCtrl::GCT_NOCROP, PrintCtrl::GlobalCrop, and PrintCtrl::m_cropCntrl.
Referenced by PrintCtrl::cropAbs10(), and PrintCtrl::cropSigDigits().
void pr_de | ( | const double | d, | |
int | sigDigits = -1 , |
|||
const int | wMin = -1 , |
|||
const int | wMax = -1 | |||
) |
Print a double using scientific notation.
Prints a double using scientific notation in a fixed number of spaces.
The precision of the number will be adjusted to fit into the maximum space.
d | double to be printed | |
sigDigits | Number of significant digits (-1 = default, means to use the default number for the object, which is initially set to 13. | |
wMin | Minimum number of spaces to print out | |
wMax | Maximum number of spaces to print out |
Definition at line 74 of file PrintCtrl.cpp.
References PrintCtrl::m_cout, PrintCtrl::m_precision, PrintCtrl::m_wMax, and PrintCtrl::m_wMin.
Referenced by LogPrintCtrl::pr_de(), and PrintCtrl::pr_de_c10().
void pr_de_c10 | ( | const double | d, | |
int | sigDigits = -1 , |
|||
const int | wMin = -1 , |
|||
const int | wMax = -1 | |||
) |
Print a double using scientific notation cropping decade values.
Prints a double using scientific notation in a fixed number of spaces. This routine also crops number below the default decade level.
The precision of the number will be adjusted to fit into the maximum space.
d | double to be printed | |
sigDigits | Number of significant digits (-1 = default, means to use the default number for the object, which is initially set to 13. | |
wMin | Minimum number of spaces to print out | |
wMax | Maximum number of spaces to print out |
Definition at line 58 of file PrintCtrl.cpp.
References PrintCtrl::cropAbs10(), PrintCtrl::m_Ndec, and PrintCtrl::pr_de().
Referenced by LogPrintCtrl::pr_de_c10().
void setCropCntrl | ( | CROP_TYPE | ctlocal | ) |
Set the cropping control flag.
ctlocal | Local enum value for the cropping type |
Definition at line 274 of file PrintCtrl.cpp.
References PrintCtrl::m_cropCntrl.
int setNdec | ( | int | nDecades | ) |
Set the default value of N decade.
nDecades | new value of Ndec |
Definition at line 216 of file PrintCtrl.cpp.
References PrintCtrl::m_Ndec.
Referenced by LogPrintCtrl::setNdec().
int setSigDigits | ( | int | sigDigits | ) |
Set the default significant digits to output.
sigDigits | new value of the sig digits |
Definition at line 228 of file PrintCtrl.cpp.
References PrintCtrl::m_precision.
Referenced by LogPrintCtrl::setSigDigits().
int setWmax | ( | int | wMax | ) |
Set the default maximum width.
wMax | Default maximum width |
Definition at line 254 of file PrintCtrl.cpp.
References PrintCtrl::m_wMax.
Referenced by LogPrintCtrl::setWmax().
int setWmin | ( | int | wMin | ) |
Set the default minimum width.
wMin | Default minimum width |
Definition at line 241 of file PrintCtrl.cpp.
References PrintCtrl::m_wMin.
Referenced by LogPrintCtrl::setWmin().
PrintCtrl::CROP_TYPE_GLOBAL GlobalCrop = GCT_NOPREF [static] |
static enum for turning on and off cropping
The default is to not have a preference for cropping
Definition at line 83 of file PrintCtrl.h.
Referenced by PrintCtrl::doCrop().
std::ostream& m_cout [private] |
This is the ostream to send all output from the object.
It defaults to cout
Definition at line 225 of file PrintCtrl.h.
Referenced by PrintCtrl::pr_de().
CROP_TYPE m_cropCntrl [private] |
Local Cropping Control.
Definition at line 255 of file PrintCtrl.h.
Referenced by PrintCtrl::doCrop(), and PrintCtrl::setCropCntrl().
int m_Ndec [private] |
Default decade level to use for decade cropping.
This is initially set to -1000, which means that no cropping will be carried out
Definition at line 232 of file PrintCtrl.h.
Referenced by PrintCtrl::pr_de_c10(), and PrintCtrl::setNdec().
int m_precision [private] |
default precision level to use in printing
This actually is one less than the number of significant digits.
Initially set to 12
Definition at line 240 of file PrintCtrl.h.
Referenced by PrintCtrl::pr_de(), and PrintCtrl::setSigDigits().
int m_wMax [private] |
Default maximum field width.
Initially this is set to 19
Definition at line 252 of file PrintCtrl.h.
Referenced by PrintCtrl::pr_de(), and PrintCtrl::setWmax().
int m_wMin [private] |
default minimimum field width
Initially, this is set to 9
Definition at line 246 of file PrintCtrl.h.
Referenced by PrintCtrl::pr_de(), and PrintCtrl::setWmin().