Classes | Typedefs | Enumerations | Functions
Classes for basic data types and vectors/arrays (tjutils library)

Classes

class  ndim
 
class  tjarray< V, T >
 
class  ProgressDisplayDriver
 
class  ProgressMeter
 
class  LockProxy< T >
 
class  SingletonHandler< T, thread_safe >
 
class  UniqueIndex< T >
 
class  Labeled
 
class  List< I, P, R >
 
struct  LogMessage
 
class  LogBase
 
class  Log< C >
 
class  RandomDist
 
class  MinimizationFunction
 
class  Process
 
class  Profiler
 
class  StaticHandler< T >
 
class  UnitTest
 
class  Mutex
 
class  MutexLock
 
class  Event
 
class  Thread
 
class  ThreadedLoop< In, Out, Local >
 
class  TypeTraits
 
class  ValList< T >
 
class  tjvector< T >
 
struct  svector
 

Typedefs

typedef tjarray< fvector, float > farray
 
typedef tjarray< dvector, double > darray
 
typedef tjarray< ivector, int > iarray
 
typedef tjarray< cvector, STD_complex > carray
 
typedef tjarray< svector, STD_string > sarray
 
typedef void(* tracefunction) (const LogMessage &msg)
 
typedef tjvector< float > fvector
 
typedef tjvector< double > dvector
 
typedef tjvector< int > ivector
 
typedef tjvector< STD_complex > cvector
 

Enumerations

enum  logPriority
 
enum  whichOccurences
 
enum  expFormat
 
enum  fopenMode
 

Functions

STD_string print_table (const sarray &table)
 
sarray parse_table (const STD_string &str)
 
STD_string ctos (const STD_complex &z)
 
STD_complex stoc (const STD_string &s)
 
bool operator< (const STD_complex &c1, const STD_complex &c2)
 
bool operator> (const STD_complex &c1, const STD_complex &c2)
 
void default_tracefunction (const LogMessage &msg)
 
int solve_cubic (double a, double b, double c, double *x0, double *x1, double *x2)
 
fvector bruteforce_minimize1d (const MinimizationFunction &f, float low, float upp)
 
STD_string replaceStr (const STD_string &s, const STD_string &searchstring, const STD_string &replacement, whichOccurences mode=allOccurences)
 
STD_string extract (const STD_string &s, const STD_string &blockbegin, const STD_string &blockend, bool hierachical=false, int beginpos=0)
 
STD_string rmblock (const STD_string &s, const STD_string &blockbegin, const STD_string &blockend, bool rmbegin=true, bool rmend=true, bool rmall=true, bool hierachical=false)
 
STD_string toupperstr (const STD_string &s)
 
STD_string tolowerstr (const STD_string &s)
 
STD_string ftos (double f, unsigned int digits=_DEFAULT_DIGITS_, expFormat eformat=autoExp)
 
STD_string itos (int i, unsigned int maxabs=0)
 
STD_string ptos (const void *p)
 
STD_string n_times (const STD_string &s, unsigned int n)
 
STD_string justificate (const STD_string &s, unsigned int indention=0, bool ignore_firstline=false, unsigned int linewidth=_DEFAULT_LINEWIDTH_)
 
int textbegin (const STD_string &s, int startpos=0, const char custom_separator=0)
 
int sepbegin (const STD_string &s, int startpos=0, const char custom_separator=0)
 
STD_string shrink (const STD_string &s)
 
int noccur (const STD_string &s, const STD_string &searchstring)
 
STD_string dos2unix (const STD_string &s)
 
int load (STD_string &str, const STD_string &filename)
 
int write (const STD_string &str, const STD_string &filename, fopenMode mode=overwriteMode)
 
double norm (double x, double y)
 
double norm3 (double x, double y, double z)
 
double maxof3 (double f1, double f2, double f3)
 
const char * modestring (fopenMode mode)
 
LONGEST_INT filesize (const char *filename)
 
const char * getpwd ()
 
int chpwd (const char *dirname)
 
int createdir (const char *dirname)
 
bool checkdir (const char *dirname)
 
int movefile (const char *src, const char *dst)
 
int copyfile (const char *src, const char *dst)
 
int rmfile (const char *fname)
 
int chperm (const char *fname, int perm)
 
void * filemap (const STD_string &filename, LONGEST_INT nbytes, LONGEST_INT offset, bool readonly, int &fd)
 
void fileunmap (int fd, void *start, LONGEST_INT nbytes, LONGEST_INT offset)
 
STD_string tempfile ()
 
int create_empty_file (const STD_string &filename, LONGEST_INT nbytes, fopenMode mode=overwriteMode)
 
const char * lasterr ()
 
void sleep_ms (unsigned int ms)
 
double current_time_s ()
 
double secureDivision (double numerator, double denominator)
 
double secureInv (double denominator)
 
const char * getenv_nonnull (const char *variable_name)
 
bool little_endian_byte_order ()
 
unsigned int numof_cores ()
 
double sinc (double x)
 
int getCommandlineOption (int argc, char *argv[], const char *option, char *returnvalue, int maxchar, bool modify=true)
 
int isCommandlineOption (int argc, char *argv[], const char *option, bool modify=true)
 
int getLastArgument (int argc, char *argv[], char *returnvalue, int maxchar, bool modify=true)
 
int hasHelpOption (int argc, char *argv[])
 
const char * helpUsage ()
 
template<class T >
STD_vector< T > list2vector (const STD_list< T > &src)
 
fvector real (const cvector &cv)
 
fvector imag (const cvector &cv)
 
fvector amplitude (const cvector &cv)
 
fvector phase (const cvector &cv)
 
cvector real2complex (const fvector &fv)
 
dvector fvector2dvector (const fvector &fv)
 
fvector dvector2fvector (const dvector &dv)
 
svector tokens (const STD_string &tokenstring, char custom_separator=0, char escape_begin='"', char escape_end='"')
 
STD_string tokenstring (const svector &tokens, unsigned int linewidth=_DEFAULT_LINEWIDTH_)
 
svector browse_dir (const STD_string &dirname, bool only_dirs=false, bool discard_dotfiles=false)
 

Detailed Description

Basic data types, vectors and arrays used by ODIN (tjutils library)

Typedef Documentation

§ carray

typedef tjarray<cvector,STD_complex> carray

An array of complex numbers

Definition at line 390 of file tjarray.h.

§ cvector

typedef tjvector<STD_complex> cvector

A vector of complex numbers

Definition at line 462 of file tjvector.h.

§ darray

typedef tjarray<dvector,double> darray

An array of double precision floating point numbers

Definition at line 379 of file tjarray.h.

§ dvector

typedef tjvector<double> dvector

A vector of double precision floating point numbers

Definition at line 451 of file tjvector.h.

§ farray

typedef tjarray<fvector,float> farray

An array of floating point numbers

Definition at line 374 of file tjarray.h.

§ fvector

typedef tjvector<float> fvector

A vector of floating point numbers

Definition at line 446 of file tjvector.h.

§ iarray

typedef tjarray<ivector,int> iarray

An array of integer numbers

Definition at line 384 of file tjarray.h.

§ ivector

typedef tjvector<int> ivector

A vector of integer numbers

Definition at line 456 of file tjvector.h.

§ sarray

typedef tjarray<svector,STD_string> sarray

An array of strings

Definition at line 396 of file tjarray.h.

§ tracefunction

typedef void(* tracefunction) (const LogMessage &msg)

Trace function signature

Definition at line 98 of file tjlog.h.

Enumeration Type Documentation

§ expFormat

enum expFormat

Enum to flag exponential printing of floating point numbers:

  • autoExp: Automatic
  • alwaysExp: Always use exponential format
  • neverExp: Never use exponential format

Definition at line 119 of file tjstring.h.

§ fopenMode

enum fopenMode

Mode flag when reading/writing raw data to disk:

  • readMode: Read-only access
  • overwriteMode: If a file with the same name already exists, it is overwritten
  • appendMode: If a file with the same name already exists, the data is appended

Definition at line 107 of file tjtools.h.

§ logPriority

This enum is used to assign a priority to the log messages If a given logging level is selected by the user (via GUI or command line argument), all messages with an equal or lesser priority are shown.

Definition at line 48 of file tjlog.h.

§ whichOccurences

Enum to flag replacement policy:

  • allOccurences: All occurences will be replaced
  • firstOccurence: Only the first occurence is replaced

Definition at line 60 of file tjstring.h.

Function Documentation

§ amplitude()

fvector amplitude ( const cvector cv)

Returns the amplitude of a complex array

§ browse_dir()

svector browse_dir ( const STD_string &  dirname,
bool  only_dirs = false,
bool  discard_dotfiles = false 
)

Returns all entries in the given directory, if 'only_dirs' is 'true' only subdirectories will be reported. Files starting with a dot are discarded when setting 'discard_dotfiles' to 'true'. The resulting vector is sorted alphanumerically according to the file names.

§ bruteforce_minimize1d()

fvector bruteforce_minimize1d ( const MinimizationFunction f,
float  low,
float  upp 
)

one-dimensional brute-force minimizer in given interval [low,upp]. Returns coordinates of minimum.

§ checkdir()

bool checkdir ( const char *  dirname)

Returns true if directory 'dirname' exists, otherwise false

§ chperm()

int chperm ( const char *  fname,
int  perm 
)

Changes permissions of file 'fname' to 'perm'. On success, zero is returned. On error, -1 is returned.

§ chpwd()

int chpwd ( const char *  dirname)

Changes the current directory of the process to dirname. On success, zero is returned. On error, -1 is returned.

§ copyfile()

int copyfile ( const char *  src,
const char *  dst 
)

Copies a file 'src' to destination 'dst'. On success, zero is returned. On error, -1 is returned.

§ create_empty_file()

int create_empty_file ( const STD_string &  filename,
LONGEST_INT  nbytes,
fopenMode  mode = overwriteMode 
)

Create an empty file, filled with zeroes. Overwrite or append according to 'mode'. On error, -1 is returned.

§ createdir()

int createdir ( const char *  dirname)

Creates the given directory. On success, zero is returned. On error, -1 is returned.

§ ctos()

STD_string ctos ( const STD_complex &  z)

Returns the complex number 'z' as a formatted string

§ current_time_s()

double current_time_s ( )

Returns the current time in s

§ default_tracefunction()

void default_tracefunction ( const LogMessage msg)

Default trace function

§ dos2unix()

STD_string dos2unix ( const STD_string &  s)

Replaces all '0d0a' sequences by '0a' in the string

§ dvector2fvector()

fvector dvector2fvector ( const dvector dv)

Converts a vector of doubles to a vector of floats

§ extract()

STD_string extract ( const STD_string &  s,
const STD_string &  blockbegin,
const STD_string &  blockend,
bool  hierachical = false,
int  beginpos = 0 
)

returns a block of characters within s that is enclosed by 'blockbegin' and 'blockend'; the delimiters itself are not returned; If hierachical is true the nesting is considered, e.g. extract("(a(b)c)", "(", ")", true) will return "a(b)c" and not "a(b" ; beginpos is the position to start searching; If 'blockbegin' is a zero-length string, extraction will start at the beginning of the string; If 'blockend' is a zero-length string, extraction will stop at the end of the string;

§ filemap()

void* filemap ( const STD_string &  filename,
LONGEST_INT  nbytes,
LONGEST_INT  offset,
bool  readonly,
int &  fd 
)

Creates a file mapping of file 'filename' with 'nbytes' length starting at 'offset' bytes into the file, optionally in 'readonly' mode. The 'fd' will hold the file descriptor (handle) of the mapped file. Returns a pointer to the mapped memory region.

§ filesize()

LONGEST_INT filesize ( const char *  filename)

Returns file size in bytes if file exists, otherwise -1

§ fileunmap()

void fileunmap ( int  fd,
void *  start,
LONGEST_INT  nbytes,
LONGEST_INT  offset 
)

Deletes a file mapping of file descriptor 'fd' which maps a region at memory location 'start' of 'nbytes' length starting at 'offset' bytes into the file.

§ ftos()

STD_string ftos ( double  f,
unsigned int  digits = _DEFAULT_DIGITS_,
expFormat  eformat = autoExp 
)

returns a string that contains the formatted floating point number 'f' with precision 'digits' and exponential usage 'eformat'

§ fvector2dvector()

dvector fvector2dvector ( const fvector fv)

Converts a vector of floats to a vector of doubles

§ getCommandlineOption()

int getCommandlineOption ( int  argc,
char *  argv[],
const char *  option,
char *  returnvalue,
int  maxchar,
bool  modify = true 
)

Copies maximum of 'maxchar' characters from the argv[] which follows an argv[] that matches 'option' into 'returnvalue'; returns TRUE if successful; 'maxchar' should NOT be greater than the number of bytes allocated for 'returnvalue' even if the number of chars in argv[] is smaller. If 'modify' is true, remove argument from the list.

§ getenv_nonnull()

const char* getenv_nonnull ( const char *  variable_name)

Same as getenv, but returns empty string instead of NULL if variable is not found

§ getLastArgument()

int getLastArgument ( int  argc,
char *  argv[],
char *  returnvalue,
int  maxchar,
bool  modify = true 
)

Copies maximum of 'maxchar' characters from the last argv[] into 'returnvalue'; returns TRUE if successful; 'maxchar' should NOT be greater than the number of bytes allocated for 'returnvalue' even if the number of chars in argv[] is smaller

§ getpwd()

const char* getpwd ( )

Returns the current directory of the process

§ hasHelpOption()

int hasHelpOption ( int  argc,
char *  argv[] 
)

Returns whether one of the options '-h, -help, –help or –version' was given

§ helpUsage()

const char* helpUsage ( )

Returns description of the standard help, version options

§ imag()

fvector imag ( const cvector cv)

Returns the imaginary portion of a complex array

§ isCommandlineOption()

int isCommandlineOption ( int  argc,
char *  argv[],
const char *  option,
bool  modify = true 
)

Returns TRUE if 'option' is found in argv[] If 'modify' is true, remove argument from the list.

§ itos()

STD_string itos ( int  i,
unsigned int  maxabs = 0 
)

returns a string that contains the formatted integer 'i'. If 'maxabs' is non-zero, the string will be formatted to have the same number of (possibly zero-padded) digits as 'maxabs'.

§ justificate()

STD_string justificate ( const STD_string &  s,
unsigned int  indention = 0,
bool  ignore_firstline = false,
unsigned int  linewidth = _DEFAULT_LINEWIDTH_ 
)

returns a justification of s with the specified indention and linewidth

§ lasterr()

const char* lasterr ( )

Returns the last system error as a string

§ list2vector()

template<class T >
STD_vector<T> list2vector ( const STD_list< T > &  src)

Converts a list into a vector

Definition at line 500 of file tjvector.h.

§ little_endian_byte_order()

bool little_endian_byte_order ( )

Returns true if the current platform has little endian byte order, otherwise false

§ load()

int load ( STD_string &  str,
const STD_string &  filename 
)

Loads 'str' from the ASCII-file 'filename'. Returns 0 on success, -1 otherwise.

§ maxof3()

double maxof3 ( double  f1,
double  f2,
double  f3 
)

Maximum value of 3 numbers

§ modestring()

const char* modestring ( fopenMode  mode)

Returns mode string suitable for fopen according to 'mode'

§ movefile()

int movefile ( const char *  src,
const char *  dst 
)

Moves a file 'src' to destination 'dst'. On success, zero is returned. On error, -1 is returned.

§ n_times()

STD_string n_times ( const STD_string &  s,
unsigned int  n 
)

Returns n times s, e.g. n_times("3",3) —> "333"

§ noccur()

int noccur ( const STD_string &  s,
const STD_string &  searchstring 
)

searches for number of occurences of 'searchstring' in s, returns number of matches otherwise 0

§ norm()

double norm ( double  x,
double  y 
)

Norm of a double vector

§ norm3()

double norm3 ( double  x,
double  y,
double  z 
)

Norm of a triple vector

§ numof_cores()

unsigned int numof_cores ( )

Returns the number of (virtual) CPUs

§ operator<()

bool operator< ( const STD_complex &  c1,
const STD_complex &  c2 
)
inline

Comparison operator for the norm of the complex numbers c1 and c2

Definition at line 61 of file tjcomplex.h.

§ operator>()

bool operator> ( const STD_complex &  c1,
const STD_complex &  c2 
)
inline

Comparison operator for the norm of the complex numbers c1 and c2

Definition at line 66 of file tjcomplex.h.

§ parse_table()

sarray parse_table ( const STD_string &  str)

Parses the string 'str' as a table and returns result as a 2-dim array (rows x cols).

§ phase()

fvector phase ( const cvector cv)

Returns the phase of a complex array

§ print_table()

STD_string print_table ( const sarray table)

Prints the 2-dimensional array 'table' (rows x cols) with the column widths adjusted to the maximum width (string length) in each column.

§ ptos()

STD_string ptos ( const void *  p)

returns a string that contains the address of pointer 'p'

§ real()

fvector real ( const cvector cv)

Returns the real portion of a complex array

§ real2complex()

cvector real2complex ( const fvector fv)

Returns a complex array with 'fv' in the real component

§ replaceStr()

STD_string replaceStr ( const STD_string &  s,
const STD_string &  searchstring,
const STD_string &  replacement,
whichOccurences  mode = allOccurences 
)

Returns a string where occurences of 'searchstring' are replaced by 'replacement' in s. The 'mode' parameter determines whether only the first or all occurences should be replaced.

§ rmblock()

STD_string rmblock ( const STD_string &  s,
const STD_string &  blockbegin,
const STD_string &  blockend,
bool  rmbegin = true,
bool  rmend = true,
bool  rmall = true,
bool  hierachical = false 
)

Returns s whereby a block of characters that is enclosed by 'blockbegin' and 'blockend' is removed; the flags rmbegin/rmend specify whether the delimiters itself should be removed. If 'rmall' is true, the last possible end delimiter will be used, otherwise the first. If 'hierachical' is true the nesting is considered, e.g. extract("(",")",true) applied to "(a(b)c)" will return "a(b)c" and not "a(b"

§ rmfile()

int rmfile ( const char *  fname)

Removes the file or directory 'fname'. On success, zero is returned. On error, -1 is returned.

§ secureDivision()

double secureDivision ( double  numerator,
double  denominator 
)

If denominator is zero the functions returns 0, otherwise numerator/denominator

§ secureInv()

double secureInv ( double  denominator)
inline

If denominator is zero the functions returns 0, otherwise 1/denominator

Definition at line 271 of file tjtools.h.

§ sepbegin()

int sepbegin ( const STD_string &  s,
int  startpos = 0,
const char  custom_separator = 0 
)

Gives the position of the first speparator character in s. Search starts at 'startpos'. Blanks, tabs and newlines or 'custom_separator' if non-zero are considered as separators.

§ shrink()

STD_string shrink ( const STD_string &  s)

Remove all blanks, tabs and newlines from the string s

§ sinc()

double sinc ( double  x)

Returns sinc function with accurate results for small x (in contrast to using sin(x)/x directly)

§ sleep_ms()

void sleep_ms ( unsigned int  ms)

Halt process/thread for 'ms' miliseconds.

§ solve_cubic()

int solve_cubic ( double  a,
double  b,
double  c,
double *  x0,
double *  x1,
double *  x2 
)

Solve cubic equation x^3 + a x^2 + b x + c = 0 , copied from the GSL-lib

§ stoc()

STD_complex stoc ( const STD_string &  s)

Parses an returns string 's' as complex number

§ tempfile()

STD_string tempfile ( )

Return a unique name for a temporary file.

§ textbegin()

int textbegin ( const STD_string &  s,
int  startpos = 0,
const char  custom_separator = 0 
)

Gives the position of the first non-speparator character in s. Search starts at 'startpos'. Blanks, tabs and newlines or 'custom_separator' if non-zero are considered as separators.

§ tokens()

svector tokens ( const STD_string &  tokenstring,
char  custom_separator = 0,
char  escape_begin = '"',
char  escape_end = '"' 
)

Splits the string into tokens, which are substrings separated by blanks, tabs and newlines or custom_separator (if custom_separator!=0) and returns them as a vector of strings. Parts of the string enclosed by 'escape_begin' and 'escape_end' will not be decomposed into tokens.

§ tokenstring()

STD_string tokenstring ( const svector tokens,
unsigned int  linewidth = _DEFAULT_LINEWIDTH_ 
)

Produces a string with linebreaks if width exceeds 'linewidth' from a vector of single strings. A 'linewidth' of zero will produce no linebreaks.

§ tolowerstr()

STD_string tolowerstr ( const STD_string &  s)

returns s, but with all uppercase characters transformed to lowercase

§ toupperstr()

STD_string toupperstr ( const STD_string &  s)

returns s, but with all lowercase characters transformed to uppercase

§ write()

int write ( const STD_string &  str,
const STD_string &  filename,
fopenMode  mode = overwriteMode 
)

Writes 'str' to the ASCII-file 'filename', the 'mode' determines whether data will be appended/overwritten if the file already exists. Returns 0 on success, -1 otherwise.