Common.h File Reference
#include <iostream>
#include <sstream>
#include <string>
#include <typeinfo>
#include <stdexcept>
#include <vector>
#include <boost/filesystem.hpp>
#include <boost/config.hpp>
#include <nuklei/Definitions.h>
#include <nuklei/Log.h>
#include <nuklei/LoggingMacros.h>
#include <nuklei/LinearAlgebraTypes.h>

Go to the source code of this file.

Classes

class  nuklei::Error
 Nuklei-related errors. More...
 
class  nuklei::VerificationFailure
 
class  nuklei::BadStrNumConversion
 

Namespaces

 nuklei
 Public namespace.
 

Macros

#define NUKLEI_UNIQUE_PTR_IMPL   2
 
#define NUKLEI_UNIQUE_PTR   std::unique_ptr
 
#define NUKLEI_MOVE(PTR)   std::move(PTR)
 
#define NUKLEI_RELEASE(PTR)   (PTR).release()
 
#define NUKLEI_NVP(x)   #x << "=" << x
 Name-value pair. More...
 
#define NUKLEI_HERE()
 String file:line. More...
 
#define NUKLEI_THROW(x)
 Throws an Error. More...
 
#define NUKLEI_ASSERT(expression)
 Throws an Error if expression is not true. More...
 
#define NUKLEI_DEBUG_ASSERT   NUKLEI_ASSERT
 
#define NUKLEI_FAST_ASSERT(expression)   assert(expression)
 
#define NUKLEI_FAST_DEBUG_ASSERT   NUKLEI_FAST_ASSERT
 
#define NUKLEI_ASSERT_AFE(e1, e2)
 
#define NUKLEI_ASSERT_AFE_TOL(e1, e2, tol)
 
#define NUKLEI_TRACE_BEGIN()   try {
 
#define NUKLEI_TRACE_END()
 
#define NUKLEI_LBLACK   "\033[0;30m"
 
#define NUKLEI_LRED   "\033[0;31m"
 
#define NUKLEI_LGREEN   "\033[0;32m"
 
#define NUKLEI_LBROWN   "\033[0;33m"
 
#define NUKLEI_LBLUE   "\033[0;34m"
 
#define NUKLEI_LPURPLE   "\033[0;35m"
 
#define NUKLEI_LCYAN   "\033[0;36m"
 
#define NUKLEI_LWHITE   "\033[0;37m"
 
#define NUKLEI_DBLACK   "\033[1;30m"
 
#define NUKLEI_DRED   "\033[1;31m"
 
#define NUKLEI_DGREEN   "\033[1;32m"
 
#define NUKLEI_DBROWN   "\033[1;33m"
 
#define NUKLEI_DBLUE   "\033[1;34m"
 
#define NUKLEI_DPURPLE   "\033[1;35m"
 
#define NUKLEI_DCYAN   "\033[1;36m"
 
#define NUKLEI_DWHITE   "\033[1;37m"
 
#define NUKLEI_NOCOLOR   "\033[0m"
 

Functions

template<class T >
T const & nuklei::as_const (T const &t)
 Provides a const reference to an object.

 
template<typename T >
std::string nuklei::stringify (const T &x, int precision=-1, int width=0)
 Converts an object to a std::string using operator<<.
 
std::istream & nuklei::operator>> (std::istream &in, Vector3 &l)
 
std::istream & nuklei::operator>> (std::istream &in, Quaternion &q)
 
std::ostream & nuklei::operator<< (std::ostream &out, const Quaternion &q)
 
std::ostream & nuklei::operator<< (std::ostream &out, const Matrix3 &m)
 
std::istream & nuklei::operator>> (std::istream &in, Matrix3 &m)
 
template<typename ForwardIterator >
std::string nuklei::stringifyRange (ForwardIterator first, ForwardIterator last, int precision=-1, int width=0)
 Converts a range to a std::string using operator<< on elements.
 
template<typename T >
nuklei::numify (const std::string &s, bool failIfLeftoverChars=true)
 Converts a string to an object using operator>>.
 
std::string & nuklei::cleanLine (std::string &line)
 
void nuklei::copy_file (const std::string &input, const std::string &output)
 

Macro Definition Documentation

◆ NUKLEI_ASSERT

#define NUKLEI_ASSERT (   expression)
Value:
{ \
if (!(expression)) \
": failed to assert `" + #expression + "'"); \
}

Throws an Error if expression is not true.

Example usage: NUKLEI_ASSERT(i != 0);

Note that if a function throws, calling it is slow. Do not throw from functions that are supposed to execute fast.

For functions that have to go fast, use NUKLEI_FAST_ASSERT instead.

Do not use from within a destructor!

Definition at line 113 of file Common.h.

◆ NUKLEI_ASSERT_AFE

#define NUKLEI_ASSERT_AFE (   e1,
  e2 
)
Value:
{ \
double tol = 1e-6; \
if (!(nuklei::afe(e1, e2, tol))) \
NUKLEI_THROW(nuklei::stringify(e1, 20, 0) << " != " << nuklei::stringify(e2, 20, 0) << " (TOL=" << tol << ")"); \
}

Definition at line 137 of file Common.h.

◆ NUKLEI_ASSERT_AFE_TOL

#define NUKLEI_ASSERT_AFE_TOL (   e1,
  e2,
  tol 
)
Value:
{ \
if (!(nuklei::afe(e1, e2, tol))) \
NUKLEI_THROW(nuklei::stringify(e1, 20, 0) << " != " << nuklei::stringify(e2, 20, 0) << " (TOL=" << tol << ")"); \
}

Definition at line 144 of file Common.h.

◆ NUKLEI_HERE

#define NUKLEI_HERE ( )
Value:
((boost::filesystem::path(__FILE__).parent_path().filename().string() + "/" + \
boost::filesystem::path(__FILE__).filename().string() + ":" + \
nuklei::stringify(__LINE__)))

String file:line.

Definition at line 79 of file Common.h.

◆ NUKLEI_NVP

#define NUKLEI_NVP (   x)    #x << "=" << x

Name-value pair.

Example usage: NUKLEI_THROW( NUKLEI_NVP(variable) );

Definition at line 76 of file Common.h.

◆ NUKLEI_THROW

#define NUKLEI_THROW (   x)
Value:
{ \
std::ostringstream oss; \
oss << x; \
throw nuklei::Error(oss.str()); \
}

Throws an Error.

Example usage: NUKLEI_THROW("int i is equal to " << i);

Note that if a function throws, calling it is slow. Do not throw from functions that are supposed to execute fast.

Do not use from within a destructor!

Definition at line 94 of file Common.h.

◆ NUKLEI_TRACE_END

#define NUKLEI_TRACE_END ( )
Value:
} catch (nuklei::Error &e) { \
e.addTrace(__PRETTY_FUNCTION__, NUKLEI_HERE()); \
throw; \
} \
catch (std::exception &e) { \
throw nuklei::Error(e, __PRETTY_FUNCTION__, NUKLEI_HERE()); \
}

Definition at line 155 of file Common.h.

std::string stringify(const T &x, int precision=-1, int width=0)
Converts an object to a std::string using operator<<.
Definition: Common.h:333
Nuklei-related errors.
Definition: Common.h:205
#define NUKLEI_HERE()
String file:line.
Definition: Common.h:79
© Copyright 2007-2013 Renaud Detry.
Distributed under the terms of the GNU General Public License (GPL).
(See accompanying file LICENSE.txt or copy at http://www.gnu.org/copyleft/gpl.html.)
Revised Sun Sep 13 2020 19:10:06.