Manticore  Version 1.0
Physics of Molecular Clouds
Classes | Functions | Variables
mutils Namespace Reference

MathUtils package. More...

Classes

class  CommandLine
 Command line options and arguments. More...
 
class  Exception
 MathUtils exception (base) class. More...
 
struct  Log
 Logging facility. More...
 

Functions

const char * Cform (const std::string &s)
 Converts input to well-defined type for stdio. More...
 
template<typename T >
T * Cform (T *p)
 Converts input to well-defined type for stdio. More...
 
double Cform (double i)
 Converts input to well-defined type for stdio. More...
 
unsigned long Cform (unsigned long long i)
 Converts input to well-defined type for stdio. More...
 
unsigned long Cform (unsigned long i)
 Converts input to well-defined type for stdio. More...
 
unsigned long Cform (unsigned i)
 Converts input to well-defined type for stdio. More...
 
long Cform (long long i)
 Converts input to well-defined type for stdio. More...
 
long Cform (long i)
 Converts input to well-defined type for stdio. More...
 
long Cform (int i)
 Converts input to well-defined type for stdio. More...
 
int Cform (unsigned char i)
 Converts input to well-defined type for stdio. More...
 
int Cform (char i)
 Converts input to well-defined type for stdio. More...
 
int cxxfclose (FILE *fp)
 Standardized fclose(). More...
 
FILE * cxxfopen (const std::string &file, const char *mode)
 Standardized fopen(). More...
 
template<typename... Args>
int cxxfprintf (FILE *f, Args &&... args)
 C fprintf() with type conversion (not safety). More...
 
template<typename... Args>
int cxxprintf (Args &&... args)
 C printf() with type conversion (not safety). More...
 
template<typename... Args>
int cxxsnprintf (char *buf, size_t len, Args &&... args)
 C snprintf() with type conversion (not safety). More...
 
void exitException (std::exception &ex, int status=EXIT_FAILURE)
 Exits program with exception message. Exits the program (with status) after displaying the exception ex. More...
 
const std::string nullStr (1, 0)
 
void printException (std::exception &ex)
 Prints exception message. More...
 
const std::string siPrefixes ("YZEPTGMkhDdcmunpfazy")
 

Variables

std::string::size_type npos = std::string::npos
 
const std::map< char, const char * > siScaleMap
 

Detailed Description

MathUtils package.

Function Documentation

◆ Cform() [1/11]

const char* mutils::Cform ( const std::string &  s)
inline

Converts input to well-defined type for stdio.

Definition at line 222 of file Log.h.

Referenced by cxxfprintf(), cxxprintf(), and cxxsnprintf().

◆ Cform() [2/11]

template<typename T >
T* mutils::Cform ( T *  p)
inline

Converts input to well-defined type for stdio.

Definition at line 225 of file Log.h.

◆ Cform() [3/11]

double mutils::Cform ( double  i)
inline

Converts input to well-defined type for stdio.

Definition at line 228 of file Log.h.

◆ Cform() [4/11]

unsigned long mutils::Cform ( unsigned long long  i)
inline

Converts input to well-defined type for stdio.

Definition at line 231 of file Log.h.

◆ Cform() [5/11]

unsigned long mutils::Cform ( unsigned long  i)
inline

Converts input to well-defined type for stdio.

Definition at line 234 of file Log.h.

◆ Cform() [6/11]

unsigned long mutils::Cform ( unsigned  i)
inline

Converts input to well-defined type for stdio.

Definition at line 237 of file Log.h.

◆ Cform() [7/11]

long mutils::Cform ( long long  i)
inline

Converts input to well-defined type for stdio.

Definition at line 240 of file Log.h.

◆ Cform() [8/11]

long mutils::Cform ( long  i)
inline

Converts input to well-defined type for stdio.

Definition at line 243 of file Log.h.

◆ Cform() [9/11]

long mutils::Cform ( int  i)
inline

Converts input to well-defined type for stdio.

Definition at line 246 of file Log.h.

◆ Cform() [10/11]

int mutils::Cform ( unsigned char  i)
inline

Converts input to well-defined type for stdio.

Definition at line 249 of file Log.h.

◆ Cform() [11/11]

int mutils::Cform ( char  i)
inline

Converts input to well-defined type for stdio.

Definition at line 252 of file Log.h.

◆ cxxfclose()

int mutils::cxxfclose ( FILE *  fp)
inline

Standardized fclose().

Equivalent to <cstdio> fclose(), except that the call is ignored if fp is stdin, stdout or stderr.

Parameters
[in]fpFile stream pointer.

Definition at line 325 of file Log.h.

Referenced by mutils::Log::setStream().

◆ cxxfopen()

FILE* mutils::cxxfopen ( const std::string &  file,
const char *  mode 
)
inline

Standardized fopen().

Equivalent to <cstdio> fopen(), except:

  • the file name argument is a std::string
  • file names of "-" and "!" are interpreted as stdin/stdout and stderr, respectively.
Parameters
[in]fileFile name.
[in]modeFile mode.

Definition at line 311 of file Log.h.

Referenced by mutils::Log::setStream().

◆ cxxfprintf()

template<typename... Args>
int mutils::cxxfprintf ( FILE *  f,
Args &&...  args 
)
inline

C fprintf() with type conversion (not safety).

Parameters
[in]fOpen output file stream.
[in]argsInput arguments (beginning with format string).
Returns
Number of bytes successfully written, or a negative value on error.
Warning
This method defeats all compile-time format checking (alas).
See also
mutils::cxxprintf, mutils::xfprintf

Definition at line 284 of file Log.h.

References Cform().

Referenced by mutils::Log::message().

◆ cxxprintf()

template<typename... Args>
int mutils::cxxprintf ( Args &&...  args)
inline

C printf() with type conversion (not safety).

Wraps each argument in a Cform() call and passes them to printf(). This converts all signed integers to type long and all unsigned integers to type unsigned long, so that the format conversion applied to them must be %ld or %lu, respectively. Characters are converted to type int and hence should use either %c or %d. Both C-strings and C++ std::string can be given as arguments using the %s conversion. All the usual format qualifiers may also be used.

Parameters
[in]argsInput arguments (beginning with format string).
Returns
Number of bytes successfully written, or a negative value on error.
Warning
This method defeats all compile-time format checking (alas).
See also
mutils::xprintf

Definition at line 273 of file Log.h.

References Cform().

◆ cxxsnprintf()

template<typename... Args>
int mutils::cxxsnprintf ( char *  buf,
size_t  len,
Args &&...  args 
)
inline

C snprintf() with type conversion (not safety).

Parameters
[in]bufOutput buffer.
[in]lenBuffer length.
[in]argsInput arguments (beginning with format string).
Returns
Minimum required buffer size minus one, or a negative value on error.
Warning
This method defeats all compile-time format checking (alas).
See also
mutils::cxxprintf

Definition at line 297 of file Log.h.

References Cform().

◆ exitException()

void mutils::exitException ( std::exception &  ex,
int  status = EXIT_FAILURE 
)
inline

Exits program with exception message. Exits the program (with status) after displaying the exception ex.

Note
This method does not return.
Parameters
[in]exInput exception.
[in]statusExit status.
See also
printException()

Definition at line 208 of file Exception.h.

References mutils::Log::file, and printException().

◆ nullStr()

const std::string mutils::nullStr ( ,
 
)

◆ printException()

void mutils::printException ( std::exception &  ex)
inline

Prints exception message.

If ex is an mutils::Exception, calls mutils::Exception::print(); otherwise, prints ex.what() (to stderr).

Parameters
[in]exInput exception.

Definition at line 194 of file Exception.h.

References mutils::Exception::print().

Referenced by exitException().

◆ siPrefixes()

const std::string mutils::siPrefixes ( "YZEPTGMkhDdcmunpfazy"  )
Prefix Name Value Prefix Name Value
Y yotta 1024 y yocto 10-24
Z zetta 1021 z zepto 10-21
E exa 1018 a atto 10-18
P peta 1015 f femto 10-15
T tera 1012 p pico 10-12
G giga 109 n nano 10-9
M mega 106 u micro 10-6
k kilo 103 m milli 10-3
h hetco 102 c centi 10-2
D deka 101 d deci 10-1
See also
siScale(), siHasPrefix()

Variable Documentation

◆ npos

std::string::size_type mutils::npos = std::string::npos

Definition at line 24 of file statics.cc.

Referenced by mutils::CommandLine::Option::keyword(), and mutils::CommandLine::usage().

◆ siScaleMap

const std::map<char, const char *> mutils::siScaleMap
Initial value:
{
{'Y', "1e24"}, {'Z', "1e21"}, {'E', "1e18"}, {'P', "1e15"},
{'T', "1e12"}, {'G', "1e9"}, {'M', "1e6"}, {'k', "1e3"},
{'h', "1e2"}, {'D', "1e1"}, {'d', "1e-1"}, {'c', "1e-2"},
{'m', "1e-3"}, {'u', "1e-6"}, {'n', "1e-9"}, {'p', "1e-12"},
{'f', "1e-15"}, {'a', "1e-18"}, {'z', "1e-21"}, {'y', "1e-24"}
}

Definition at line 45 of file statics.cc.