Hex  1.0
Hydrogen-electron collision solver
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Data Structures | Macros | Functions | Variables
misc.h File Reference
#include <exception>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <limits>
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
#include <type_traits>
Include dependency graph for misc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

class  exception
 Exception class. More...
 
exception  exception::Params::p::p< Params >
 Constructor. More...
 
struct  is_complex< T >
 
struct  is_complex< std::complex< T > >
 
struct  is_scalar< T >
 
class  Timer
 Timing class. More...
 

Macros

#define restrict
 
#define NO_ALIGN
 
#define declareTypeAsScalar(T)
 

Functions

 snprintf (message, size+1, p...)
 
template<class T >
int signum (T x)
 Signum function. More...
 
template<class T >
constexpr T const & larger_of (T const &a, T const &b)
 Constant-expression max. More...
 
template<class... Params>
char const * format (Params...p)
 printf-like formatting. More...
 
template<class T >
string_to (std::string str)
 Conversion of string to a type. More...
 
template<>
int string_to (std::string str)
 Conversion of a string to integer number. More...
 
template<>
double string_to (std::string str)
 Conversion of a string to floating-point number. More...
 
template<class T >
read_next (std::ifstream &f)
 Read next entry from input stream. More...
 
template<typename T >
mmin (T x)
 Many-argument "min" function. More...
 
template<typename T , class... Params>
mmin (T x, Params...p)
 
template<typename T >
mmax (T x)
 Many-argument "max" function. More...
 
template<typename T , class... Params>
mmax (T x, Params...p)
 

Variables

int size = snprintf(nullptr, 0, p...)
 
 message = new char [size + 1]
 

Macro Definition Documentation

#define declareTypeAsScalar (   T)
Value:
\
template <> struct is_scalar<T> \
{ \
static const bool value = true; \
};
Definition: misc.h:124
static const bool value
Definition: misc.h:126
#define NO_ALIGN
#define restrict

Function Documentation

template<class... Params>
char const* format ( Params...  p)

This function takes an arbitrary number of parameters. It is expected that the first one is the formatting string (printf-like syntax). All the arguments are sent to snprintf without change. This functions returns a pointer to a static character string.

Note
The maximal size of the string is hard-coded to 1024 characters.
template<class T >
constexpr T const& larger_of ( T const &  a,
T const &  b 
)
template<typename T >
T mmax ( x)
template<typename T , class... Params>
T mmax ( x,
Params...  p 
)
template<typename T >
T mmin ( x)
template<typename T , class... Params>
T mmin ( x,
Params...  p 
)
template<class T >
T read_next ( std::ifstream &  f)

Given an input stream and a template parameter the function "read_next" will scan the stream for the next entry and try to interpret next input as the correct type. The characters between a hash symbol (#) and a newline are ignored (i.e. '#' introduces comments). If the read word is equal to asterisk, the "true" boolean value is trown. If an error occurs, exception is thrown. Otherwise the converted data is returned.

// example usage
std::ifstream inputfile("input.txt");
double x = read_next<double>(inputfile);
template<class T >
int signum ( x)
exception::snprintf ( message  ,
size 1,
p...   
)
template<class T >
T string_to ( std::string  str)

This is a generic template function that is used to convert a text entry to the specified data type. This generic form is used only if there is no specialization for the given data type. The default action is an error message, then. See the specializations of this function for different types.

template<>
int string_to ( std::string  str)
inline

This function will return an integer value of the text given as argument. The library routine "strtol" is used. If the conversion fails, the function throws an exception.

template<>
double string_to ( std::string  str)
inline

This function will return a floating-point value of the text given as argument. The library routine "strtod" is used. If the conversion fails, the function throws an exception.

Variable Documentation

message = new char [size + 1]
int size = snprintf(nullptr, 0, p...)