Milo  0.1
Milo:EquationManipulationProgram
Classes | Namespaces | Macros | Functions
util.h File Reference
#include <string>
#include <vector>
#include <array>
#include <complex>
#include <algorithm>
#include <unordered_map>
#include <boost/functional/hash.hpp>
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Rectangle< T >
 

Namespaces

 Log
 

Macros

#define LOG_TRACE_MSG(m)   Log::msg(string("") + __FILE__ + ": " + to_string(__LINE__) + ": " + (m))
 
#define LOG_TRACE_FILE   "/tmp/milo.log"
 
#define LOG_TRACE_CLEAR()   remove(LOG_TRACE_FILE)
 
#define QUOTE(arg)   #arg
 
#define STR(macro)   QUOTE(macro)
 
#define INSTALL_PATH   /usr/local/milo
 
#define INSTALL_PATH_STR   STR(INSTALL_PATH)
 

Typedefs

Global Type Declerations
using Box = Rectangle< int >
 Specialization of integer rectangle.
 
using StringMap = std::unordered_map< std::string, std::string >
 hash map for string => string
 

Functions

template<class T >
std::size_t hash_calculate (std::initializer_list< T > l)
 
void Log::msg (const std::string &m)
 
Global Utility Functions
bool isZero (double x)
 
bool isZero (std::complex< double > z)
 
bool isInteger (const std::string &n)
 
bool isInteger (double value)
 
std::string to_hexstring (unsigned long x)
 
template<class T >
auto find (const std::vector< T > &v, const T &val) -> decltype(v.cbegin())
 
template<class T >
void freeVector (std::vector< T * > &v)
 
template<class T >
void mergeVectors (std::vector< T > &a, std::vector< T > &b)
 
template<class T >
void eraseElement (std::vector< T > &v, int index)
 
template<class T >
void insertElement (std::vector< T > &v, int index, const T &e)
 
template<class T >
auto AddAfter (std::vector< T > &v, decltype(v.begin()) it, const T &elem) -> decltype(v.begin())
 
template<typename K , typename V >
const K searchMapValue (const std::unordered_map< K, V > &kv_map, V value)
 

Detailed Description

This file contains miscellaneous functions and declerations.

Function Documentation

template<class T >
auto AddAfter ( std::vector< T > &  v,
decltype(v.begin())  it,
const T &  elem 
) -> decltype(v.begin())

Insert an elememnt after the element pointed to by the given iterator.

Parameters
vVector storing type T.
itIterator pointing to insert position.
eElement of type T.
Returns
Iterator to inserted element.
template<class T >
void eraseElement ( std::vector< T > &  v,
int  index 
)
inline

Erase an element in a vector by index. Helper function to convert index to iterator to erase element.

Parameters
vVector storing type T.
indexIndex of element to be erased.
template<class T >
auto find ( const std::vector< T > &  v,
const T &  val 
) -> decltype( v.cbegin() )
inline

Find an iterator to a value in a vector. Template function will look for a value whose type is stored in the given vector. Returns an iterator to the found value or the end iterator if not found.

Parameters
vVector containing type T.
valValue of type T.
Returns
Return iterator to found value or end iterator.
template<class T >
void freeVector ( std::vector< T * > &  v)
inline

Delete all items in a vector that contains pointers Template function delete each pointer in a vector.

Parameters
vVector containing pointer type T*.
template<class T >
std::size_t hash_calculate ( std::initializer_list< T >  l)
inline

Calculate final hash from given list of values

template<class T >
void insertElement ( std::vector< T > &  v,
int  index,
const T &  e 
)
inline

Insert an element before the element pointed to by index in vector. Use vector.insert() with iterator created from index.

Parameters
vVector storing type T.
indexIndex of element where new element will be inserted.
eElement of type T.
bool isInteger ( const std::string &  n)

Check if string contains integer value.

Returns
True, if integer.
bool isInteger ( double  value)

Check if double is integer value.

Returns
True is fractional value is smaller than a limit.
bool isZero ( double  x)

Check if floating point is smaller than a limit.

Returns
If smaller than limit, return true for zero.
bool isZero ( std::complex< double >  z)

Check if complex floating point is smaller than a limit.

Returns
If smaller than limit, return true for zero.
template<class T >
void mergeVectors ( std::vector< T > &  a,
std::vector< T > &  b 
)
inline

Merge vector two vectors.

Parameters
aVector ending up items of both vectors.
bVector whose items are merged and cleared.
template<typename K , typename V >
const K searchMapValue ( const std::unordered_map< K, V > &  kv_map,
V  value 
)

Search for a value in map.

Parameters
kv_mapMap to be searched.
valueValue to look for return Key associated with value.
std::string to_hexstring ( unsigned long  x)
inline

Convert long integer to hex string no leading zeroes.

Returns
String containing converted hexidecimal string.