SatAndLight  2.2.2-hubble
Simulation toolkit for space telescopes
CUtils.h File Reference

This module offers C++ utility functions. More...

#include "Config.h"
Include dependency graph for CUtils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CMSQ2MMSQ   1.0e2
 cm^2 -> mm^2 More...
 
#define ERG2KEV   6.242e8
 erg -> keV More...
 
#define KEV2J   1.602176634e-16
 keV -> J (SI) More...
 
#define LN10   2.30258509299404590109361379290930926799774169921875
 log(10) More...
 
#define LN2   0.6931471805599453094172321214581766
 log_e 2 More...
 
#define MM2M   1.0e-3
 mm -> m More...
 
#define PI   3.141592653589793115997963468544185161590576171875
 pi
More...
 
#define PIOVERTWO   1.5707963267948965579989817342720925807952880859375
 pi/2
More...
 
#define S2MS   1.0e3
 s -> ms More...
 
#define SQRT2   1.4142135623730951454746218587388284504413604736328125
 sqrt(2) More...
 
#define SQRT2PI   2.506628274631000241612355239340104162693023681640625
 sqrt(2pi) More...
 
#define TWOPI   6.28318530717958623199592693708837032318115234375
 2pi
More...
 

Functions

string GetDirectoryFromFilePath (const string aFilePath)
 Returns the directory from the file path. More...
 
string GetFileNameFromPath (const string aFilePath)
 Returns the file name given the file path. More...
 
unsigned int GetGcd (unsigned int aN1, unsigned int aN2)
 Returns the greater common divisor between 2 numbers. More...
 
vector< string > Glob (const char *aPattern)
 C utility to extract a list of files from a given file pattern. More...
 
bool IsDirectory (const string aDirPath)
 Checks if a directory exists. More...
 
bool IsFile (const string aFileName)
 Checks if a file exists. More...
 
bool IsPowerOfTwo (const unsigned int aN)
 Tests whether an integer is a power of 2. More...
 
int NextPowerOfTwo (const double aX)
 Returns the next power of 2. More...
 
string ReplaceAll (string aStr, const string &aFrom, const string &aTo)
 Replaces all occurences of a sub-string by another sub-string. More...
 
vector< string > SplitString (const string aStringToSplit, const char aSeparator)
 Splits a string. More...
 

Detailed Description

This module offers C++ utility functions.

Authors
Florent Robinet, flore.nosp@m.nt.r.nosp@m.obine.nosp@m.t@ij.nosp@m.clab..nosp@m.in2p.nosp@m.3.fr

Macro Definition Documentation

◆ CMSQ2MMSQ

#define CMSQ2MMSQ   1.0e2

cm^2 -> mm^2

◆ ERG2KEV

#define ERG2KEV   6.242e8

erg -> keV

◆ KEV2J

#define KEV2J   1.602176634e-16

keV -> J (SI)

◆ LN10

#define LN10   2.30258509299404590109361379290930926799774169921875

log(10)

◆ LN2

#define LN2   0.6931471805599453094172321214581766

log_e 2

◆ MM2M

#define MM2M   1.0e-3

mm -> m

◆ PI

#define PI   3.141592653589793115997963468544185161590576171875

pi

◆ PIOVERTWO

#define PIOVERTWO   1.5707963267948965579989817342720925807952880859375

pi/2

◆ S2MS

#define S2MS   1.0e3

s -> ms

◆ SQRT2

#define SQRT2   1.4142135623730951454746218587388284504413604736328125

sqrt(2)

◆ SQRT2PI

#define SQRT2PI   2.506628274631000241612355239340104162693023681640625

sqrt(2pi)

◆ TWOPI

#define TWOPI   6.28318530717958623199592693708837032318115234375

2pi

Function Documentation

◆ GetDirectoryFromFilePath()

string GetDirectoryFromFilePath ( const string  aFilePath)

Returns the directory from the file path.

Parameters
[in]aFilePathFile path.

◆ GetFileNameFromPath()

string GetFileNameFromPath ( const string  aFilePath)
inline

Returns the file name given the file path.

For example "myprog.exe" is returned from:

  • the full path "/usr/bin/myprog.exe"
  • the relative path "./bin/myprog.exe"
Parameters
[in]aFilePathfile path
Returns
The file name with path.

◆ GetGcd()

unsigned int GetGcd ( unsigned int  aN1,
unsigned int  aN2 
)

Returns the greater common divisor between 2 numbers.

Parameters
[in]aN1First number.
[in]aN2Second number.

◆ Glob()

vector<string> Glob ( const char *  aPattern)

C utility to extract a list of files from a given file pattern.

Returns
a list of files matching a pattern.
Parameters
[in]aPatternFile pattern to match.

◆ IsDirectory()

bool IsDirectory ( const string  aDirPath)

Checks if a directory exists.

Returns
true if the directory path exists.
Parameters
[in]aDirPathPath to the directory to test.

◆ IsFile()

bool IsFile ( const string  aFileName)

Checks if a file exists.

Returns
true if the input file exists, false otherwise.
Parameters
[in]aFileNamePath to the file to test.

◆ IsPowerOfTwo()

bool IsPowerOfTwo ( const unsigned int  aN)
inline

Tests whether an integer is a power of 2.

Parameters
[in]aNInteger to test.
Returns
true if the integer is a power of 2, false otherwise.

◆ NextPowerOfTwo()

int NextPowerOfTwo ( const double  aX)
inline

Returns the next power of 2.

Parameters
[in]aXnumber to consider.
Returns
The power of 2 next to the given number.

◆ ReplaceAll()

string ReplaceAll ( string  aStr,
const string &  aFrom,
const string &  aTo 
)

Replaces all occurences of a sub-string by another sub-string.

All occurences of sub-string 'aFrom' are replaced by 'aTo'.

Returns
The modified string.
Parameters
aStrString to modify.
aFromSubstring to replace from.
aToSubstring to replace to.

◆ SplitString()

vector<string> SplitString ( const string  aStringToSplit,
const char  aSeparator 
)

Splits a string.

A string is divided into a vector of sub-strings. The separator defines where to break the input string. The separator must be a single character.

Returns
A vector of string, excluding the separator
Parameters
[in]aStringToSplitString to divide.
[in]aSeparatorSeparator.