CoastalME (Coastal Modelling Environment)
Simulates the long-term behaviour of complex coastlines
Loading...
Searching...
No Matches
utils_global.cpp File Reference

Globally-available utility routines. More...

#include <cmath>
#include <cfloat>
#include <cstdio>
#include <sstream>
#include <ios>
#include <iomanip>
#include "cme.h"

Go to the source code of this file.

Data Structures

class  istringstream
 STL class. More...
 

Functions

double dRound (double const d)
 Correctly rounds doubles.
 
int nRound (double const d)
 Version of the above that returns an int.
 
bool bIsStringValidDouble (string &str)
 Checks to see if a string can be read as a valid double number. Does not find trailing (i.e.post-number) rubbish, but then neither does strtod(). From https://stackoverflow.com/questions/392981/how-can-i-convert-string-to-double-in-c.
 
bool bIsStringValidInt (string &str)
 Checks to see if a string can be read as a valid integer, from https://stackoverflow.com/questions/2844817/how-do-i-check-if-a-c-string-is-an-int.
 
ostreamoperator<< (ostream &ostr, const FillToWidth &args)
 Operator that inserts a given fill character, to a given width, into an output stream. From http://stackoverflow.com/questions/2839592/equivalent-of-02d-with-stdstringstream.
 
string strDbl (double const dX, int const nDigits)
 Converts double to string with specified number of places after the decimal. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.
 
string strDblRight (double const dX, int const nDigits, int const nWidth, bool const bShowDash)
 Converts double to string with specified number of decimal places, within a field of given width, pads with blank spaces to enforce right alignment. Modified from https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.
 
string strIntRight (int const nX, int const nWidth)
 Converts int to string within a field of given width, pads with blank spaces to enforce alignment.. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.
 
string strCentre (const char *pchIn, int const nWidth)
 Centre-aligns char array within a field of given width, pads with blank spaces to enforce alignment. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.
 
string strCentre (const string &strIn, int const nWidth)
 Centre-aligns string within a field of given width, pads with blank spaces to enforce alignment. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.
 
string strRight (const string &strIn, int const nWidth)
 Right-aligns string within a field of given width, pads with blank spaces to enforce alignment. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.
 
string strRight (const char *pchIn, int const nWidth)
 Right-aligns char array within a field of given width, pads with blank spaces to enforce alignment. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.
 
string strLeft (const string &strIn, int const nWidth)
 Left-aligns string within a field of given width, pads with blank spaces to enforce alignment. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.
 
string strLeft (const char *pchIn, int const nWidth)
 Left-aligns char array within a field of given width, pads with blank spaces to enforce alignment. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.
 
string strRightPerCent (double const d1, double const d2, int const nWidth, int const nDigits, bool const bShowDash)
 Calculates a percentage from two numbers then, if the result is non-zero, right-aligns the result as a string within a field of given width, pads with blank spaces to enforce alignment. Modified from https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.
 

Detailed Description

Globally-available utility routines.

TODO 001 A more detailed description of these routines.

Author
David Favis-Mortlock
Andres Payo
Date
2025

Definition in file utils_global.cpp.

Function Documentation

◆ bIsStringValidDouble()

bool bIsStringValidDouble ( string & str)

Checks to see if a string can be read as a valid double number. Does not find trailing (i.e.post-number) rubbish, but then neither does strtod(). From https://stackoverflow.com/questions/392981/how-can-i-convert-string-to-double-in-c.

Definition at line 71 of file utils_global.cpp.

Referenced by CSimulation::bReadRunDataFile(), CSimulation::nReadSedimentInputEventFile(), CSimulation::nReadShapeFunctionFile(), CSimulation::nReadTideDataFile(), and CSimulation::nReadWaveStationInputFile().

◆ bIsStringValidInt()

◆ dRound()

double dRound ( double const d)

◆ nRound()

◆ operator<<()

ostream & operator<< ( ostream & ostr,
const FillToWidth & args )

Operator that inserts a given fill character, to a given width, into an output stream. From http://stackoverflow.com/questions/2839592/equivalent-of-02d-with-stdstringstream.

Definition at line 103 of file utils_global.cpp.

◆ strCentre() [1/2]

◆ strCentre() [2/2]

string strCentre ( const string & strIn,
int const nWidth )

Centre-aligns string within a field of given width, pads with blank spaces to enforce alignment. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.

Definition at line 187 of file utils_global.cpp.

◆ strDbl()

string strDbl ( double const dX,
int const nDigits )

Converts double to string with specified number of places after the decimal. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.

Definition at line 114 of file utils_global.cpp.

◆ strDblRight()

◆ strIntRight()

◆ strLeft() [1/2]

string strLeft ( const char * pchIn,
int const nWidth )

Left-aligns char array within a field of given width, pads with blank spaces to enforce alignment. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.

Definition at line 248 of file utils_global.cpp.

◆ strLeft() [2/2]

string strLeft ( const string & strIn,
int const nWidth )

Left-aligns string within a field of given width, pads with blank spaces to enforce alignment. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.

Definition at line 235 of file utils_global.cpp.

Referenced by CSimulation::DoEndOfTimestepTotals(), and CSimulation::WritePolygonActualMovement().

◆ strRight() [1/2]

string strRight ( const char * pchIn,
int const nWidth )

Right-aligns char array within a field of given width, pads with blank spaces to enforce alignment. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.

Definition at line 220 of file utils_global.cpp.

◆ strRight() [2/2]

string strRight ( const string & strIn,
int const nWidth )

Right-aligns string within a field of given width, pads with blank spaces to enforce alignment. From https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.

Definition at line 206 of file utils_global.cpp.

Referenced by CSimulation::WritePolygonSortedSequence().

◆ strRightPerCent()

string strRightPerCent ( double const d1,
double const d2,
int const nWidth,
int const nDigits,
bool const bShowDash )

Calculates a percentage from two numbers then, if the result is non-zero, right-aligns the result as a string within a field of given width, pads with blank spaces to enforce alignment. Modified from https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c.

Definition at line 262 of file utils_global.cpp.

Referenced by CSimulation::DoEndOfTimestepTotals().