n2p2 - A neural network potential package
utility.h File Reference
#include <cstdio>
#include <fstream>
#include <map>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
Include dependency graph for utility.h:

Go to the source code of this file.

Namespaces

namespace  nnp
 

Functions

vector< string > nnp::split (std::string const &input, char delimiter=' ')
 Split string at each delimiter. More...
 
string nnp::trim (std::string const &line, std::string const &whitespace=" \t")
 Remove leading and trailing whitespaces from string. More...
 
string nnp::reduce (std::string const &line, std::string const &whitespace=" \t", std::string const &fill=" ")
 Replace multiple whitespaces with fill. More...
 
std::string nnp::pad (std::string const &input, std::size_t num, char fill=' ', bool right=true)
 Pad string to given length with fill character. More...
 
string nnp::strpr (const char *format,...)
 String version of printf function. More...
 
string nnp::cap (std::string word)
 Capitalize first letter of word. More...
 
std::vector< std::string > nnp::createFileHeader (std::vector< std::string > const &title, std::vector< std::size_t > const &colLength, std::vector< std::string > const &colName, std::vector< std::string > const &colInfo, char const &commentChar='#')
 Generate output file header with info section and column labels. More...
 
void nnp::appendLinesToFile (std::ofstream &file, std::vector< std::string > const lines)
 Append multiple lines of strings to open file stream. More...
 
void nnp::appendLinesToFile (FILE *const &file, std::vector< std::string > const lines)
 Append multiple lines of strings to open file pointer. More...
 
std::map< std::size_t, std::vector< double > > nnp::readColumnsFromFile (std::string fileName, std::vector< std::size_t > columns, char comment='#')
 Read multiple columns of data from file. More...
 
template<typename K , typename V >
V const & nnp::safeFind (std::map< K, V > const &stdMap, typename std::map< K, V >::key_type const &key)
 Safely access map entry. More...
 
template<typename T >
bool nnp::vectorContains (std::vector< T > const &stdVec, T value)
 Test if vector contains specified value. More...
 
template<typename T , typename U >
bool nnp::unorderedMapContainsKey (std::unordered_map< T, U > const &stdMap, T key)
 Test if unordered map contains specified key. More...
 
template<typename T >
bool nnp::comparePointerTargets (T *lhs, T *rhs)
 Compare pointer targets. More...
 
double nnp::pow_int (double x, int n)
 Integer version of power function, "fast exponentiation algorithm". More...