IAP GITLAB

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • AirShowerPhysics/corsika
  • rulrich/corsika
  • AAAlvesJr/corsika
  • Andre/corsika
  • arrabito/corsika
  • Nikos/corsika
  • olheiser73/corsika
  • AirShowerPhysics/papers/corsika
  • pranav/corsika
9 results
Show changes
Showing
with 0 additions and 1021 deletions
namespace cascade;
void
Cascade::Step(auto& sequence, Particle& particle)
{
double nextStep = sequence.MinStepLength(particle);
Trajectory trajectory = sequence.Transport(particle, nextStep);
sequence.DoContinuous(particle, trajectory);
sequence.DoDiscrete(particle);
}
#ifndef _include_BASEVECTOR_H_
#define _include_BASEVECTOR_H_
#include <Geometry/QuantityVector.h>
#include <Geometry/CoordinateSystem.h>
/*!
* Common base class for Vector and Point. Currently it does basically nothing.
*/
template <typename dim>
class BaseVector
{
protected:
QuantityVector<dim> qVector;
CoordinateSystem const* cs;
public:
BaseVector(CoordinateSystem const& pCS, QuantityVector<dim> pQVector) :
qVector(pQVector), cs(&pCS)
{
}
};
#endif
set (GEOMETRY_SOURCES CoordinateSystem.cc)
set (GEOMETRY_HEADERS Vector.h Point.h Sphere.h CoordinateSystem.h Helix.h)
add_library (CORSIKAgeometry STATIC ${GEOMETRY_SOURCES})
set_target_properties (CORSIKAgeometry PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties (CORSIKAgeometry PROPERTIES SOVERSION 1)
set_target_properties (CORSIKAgeometry PROPERTIES PUBLIC_HEADER "${GEOMETRY_HEADERS}")
# target dependencies on other libraries (also header only)
target_link_libraries (CORSIKAgeometry CORSIKAunits)
target_include_directories (CORSIKAgeometry PRIVATE ${EIGEN3_INCLUDE_DIR})
target_include_directories (CORSIKAgeometry INTERFACE ${EIGEN3_INCLUDE_DIR})
target_include_directories (CORSIKAgeometry INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework>
$<INSTALL_INTERFACE:include/Framework>
)
install (TARGETS CORSIKAgeometry
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include/Geometry)
# code testing
add_executable (testGeometry testGeometry.cc)
target_link_libraries (testGeometry CORSIKAgeometry CORSIKAunits CORSIKAthirdparty) # for catch2
add_test (NAME testGeometry COMMAND testGeometry -o report.xml -r junit)
#include <Geometry/CoordinateSystem.h>
EigenTransform CoordinateSystem::GetTransformation(CoordinateSystem const& c1, CoordinateSystem const& c2)
{
CoordinateSystem const* a{&c1};
CoordinateSystem const* b{&c2};
CoordinateSystem const* commonBase{nullptr};
while (a != b && b != nullptr)
{
a = &c1;
while (a != b && a != nullptr)
{
a = a->GetReference();
}
if (a == b)
break;
b = b->GetReference();
}
if (a == b && a != nullptr)
{
commonBase = a;
}
else
{
throw std::string("no connection between coordinate systems found!");
}
EigenTransform t = EigenTransform::Identity();
auto* p = &c1;
while (p != commonBase)
{
t = p->GetTransform() * t;
p = p->GetReference();
}
p = &c2;
while (p != commonBase)
{
t = p->GetTransform().inverse(Eigen::TransformTraits::Isometry) * t;
p = p->GetReference();
}
return t;
}
#ifndef _include_COORDINATESYSTEM_H_
#define _include_COORDINATESYSTEM_H_
#include <Geometry/QuantityVector.h>
#include <Units/PhysicalUnits.h>
#include <Eigen/Dense>
typedef Eigen::Transform<double, 3, Eigen::Affine> EigenTransform;
typedef Eigen::Translation<double, 3> EigenTranslation;
class CoordinateSystem
{
CoordinateSystem const* reference = nullptr;
EigenTransform transf;
CoordinateSystem(CoordinateSystem const& reference, EigenTransform const& transf) :
reference(&reference),
transf(transf)
{
}
public:
static EigenTransform GetTransformation(CoordinateSystem const& c1, CoordinateSystem const& c2);
CoordinateSystem() : // for creating the root CS
transf(EigenTransform::Identity())
{
}
auto& operator=(const CoordinateSystem& pCS)
{
reference = pCS.reference;
transf = pCS.transf;
return *this;
}
auto translate(QuantityVector<phys::units::length_d> vector) const
{
EigenTransform const translation{EigenTranslation(vector.eVector)};
return CoordinateSystem(*this, translation);
}
auto rotate(QuantityVector<phys::units::length_d> axis, double angle) const
{
EigenTransform const rotation{Eigen::AngleAxisd(angle, axis.eVector.normalized())};
return CoordinateSystem(*this, rotation);
}
auto translateAndRotate(QuantityVector<phys::units::length_d> translation, QuantityVector<phys::units::length_d> axis, double angle)
{
EigenTransform const transf{Eigen::AngleAxisd(angle, axis.eVector.normalized()) * EigenTranslation(translation.eVector)};
return CoordinateSystem(*this, transf);
}
auto const* GetReference() const
{
return reference;
}
auto const& GetTransform() const
{
return transf;
}
};
#endif
#ifndef _include_HELIX_H_
#define _include_HELIX_H_
#include <Geometry/Vector.h>
#include <Geometry/Point.h>
#include <Units/PhysicalUnits.h>
#include <cmath>
class Helix // TODO: inherit from to-be-implemented "Trajectory"
{
using SpeedVec = Vector<Speed::dimension_type>;
Point const r0;
Frequency const omegaC;
SpeedVec const vPar;
SpeedVec vPerp, uPerp;
Length const radius;
public:
Helix(Point const& pR0, phys::units::quantity<phys::units::frequency_d> pOmegaC,
SpeedVec const& pvPar, SpeedVec const& pvPerp) :
r0(pR0), omegaC(pOmegaC), vPar(pvPar), vPerp(pvPerp), uPerp(vPerp.cross(vPar.normalized())),
radius(pvPar.norm() / abs(pOmegaC))
{
}
auto GetPosition(Time t) const
{
return r0 + vPar * t + (vPerp * (cos(omegaC * t) - 1) + uPerp * sin(omegaC * t)) / omegaC;
}
auto GetRadius() const
{
return radius;
}
};
#endif
#ifndef _include_LINETRAJECTORY_H
#define _include_LINETRAJECTORY_H
#include <Framework/Geometry/Point.h>
#include <Framework/Geometry/Vector.h>
#include <Units/PhysicalUnits.h>
class LineTrajectory // TODO: inherit from Trajectory
{
using SpeedVec = Vector<Speed::dimension_type>;
Point const r0;
SpeedVec const v0;
LineTrajectory(Point const& pR0, SpeedVec const& pV0) :
r0(r0), v0(pV0)
{
}
auto GetPosition(Time t) const
{
return r0 + v0 * t;
}
};
#endif
#ifndef _include_POINT_H_
#define _include_POINT_H_
#include <Geometry/BaseVector.h>
#include <Geometry/QuantityVector.h>
#include <Geometry/Vector.h>
#include <Units/PhysicalUnits.h>
/*!
* A Point represents a point in position space. It is defined by its
* coordinates with respect to some CoordinateSystem.
*/
class Point : public BaseVector<phys::units::length_d>
{
public:
Point(CoordinateSystem const& pCS, QuantityVector<phys::units::length_d> pQVector) :
BaseVector<phys::units::length_d>(pCS, pQVector)
{
}
Point(CoordinateSystem const& cs, Length x, Length y, Length z) :
BaseVector<phys::units::length_d>(cs, {x, y, z})
{
}
auto GetCoordinates() const
{
return BaseVector<phys::units::length_d>::qVector;
}
auto GetCoordinates(CoordinateSystem const& pCS) const
{
if (&pCS == BaseVector<phys::units::length_d>::cs)
{
return BaseVector<phys::units::length_d>::qVector;
}
else
{
return QuantityVector<phys::units::length_d>(CoordinateSystem::GetTransformation(*BaseVector<phys::units::length_d>::cs, pCS) * BaseVector<phys::units::length_d>::qVector.eVector);
}
}
/*!
* transforms the Point into another CoordinateSystem by changing its
* coordinates interally
*/
void rebase(CoordinateSystem const& pCS)
{
BaseVector<phys::units::length_d>::qVector = GetCoordinates(pCS);
BaseVector<phys::units::length_d>::cs = &pCS;
}
Point operator+(Vector<phys::units::length_d> const& pVec) const
{
return Point(*BaseVector<phys::units::length_d>::cs, GetCoordinates() + pVec.GetComponents(*BaseVector<phys::units::length_d>::cs));
}
/*!
* returns the distance Vector between two points
*/
Vector<phys::units::length_d> operator-(Point const& pB) const
{
auto& cs = *BaseVector<phys::units::length_d>::cs;
return Vector<phys::units::length_d>(cs, GetCoordinates() - pB.GetCoordinates(cs));
}
};
#endif
#ifndef _include_QUANTITYVECTOR_H_
#define _include_QUANTITYVECTOR_H_
#include <Units/PhysicalUnits.h>
#include <Eigen/Dense>
#include <iostream>
#include <utility>
/*!
* A QuantityVector is a three-component container based on Eigen::Vector3d
* with a phys::units::dimension. Arithmethic operators are defined that
* propagate the dimensions by dimensional analysis.
*/
template <typename dim>
class QuantityVector
{
protected:
using Quantity = phys::units::quantity<dim, double>; //< the phys::units::quantity corresponding to the dimension
public:
Eigen::Vector3d eVector; //!< the actual container where the raw numbers are stored
typedef dim dimension; //!< should be a phys::units::dimension
QuantityVector(Quantity a, Quantity b, Quantity c) :
eVector{a.magnitude(), b.magnitude(), c.magnitude()}
{
}
QuantityVector(Eigen::Vector3d pBareVector) :
eVector(pBareVector)
{
}
auto operator[](size_t index) const
{
return Quantity(phys::units::detail::magnitude_tag, eVector[index]);
}
auto norm() const
{
return Quantity(phys::units::detail::magnitude_tag, eVector.norm());
}
auto squaredNorm() const
{
using QuantitySquared = decltype(std::declval<Quantity>() * std::declval<Quantity>());
return QuantitySquared(phys::units::detail::magnitude_tag, eVector.squaredNorm());
}
auto operator+(QuantityVector<dim> const& pQVec) const
{
return QuantityVector<dim>(eVector + pQVec.eVector);
}
auto operator-(QuantityVector<dim> const& pQVec) const
{
return QuantityVector<dim>(eVector - pQVec.eVector);
}
template <typename ScalarDim>
auto operator*(phys::units::quantity<ScalarDim, double> const p) const
{
using ResQuantity = phys::units::detail::Product<ScalarDim, dim, double, double>;
if constexpr (std::is_same<ResQuantity, double>::value) // result dimensionless, not a "Quantity" anymore
{
return QuantityVector<phys::units::dimensionless_d>(eVector * p.magnitude());
}
else
{
return QuantityVector<typename ResQuantity::dimension_type>(eVector * p.magnitude());
}
}
template <typename ScalarDim>
auto operator/(phys::units::quantity<ScalarDim, double> const p) const
{
return (*this) * (1 / p);
}
auto operator*(double const p) const
{
return QuantityVector<dim>(eVector * p);
}
auto operator/(double const p) const
{
return QuantityVector<dim>(eVector / p);
}
auto& operator/=(double const p)
{
eVector /= p;
return *this;
}
auto& operator*=(double const p)
{
eVector *= p;
return *this;
}
auto& operator+=(QuantityVector<dim> const& pQVec)
{
eVector += pQVec.eVector;
return *this;
}
auto& operator-=(QuantityVector<dim> const& pQVec)
{
eVector -= pQVec.eVector;
return *this;
}
auto& operator-() const
{
return QuantityVector<dim>(-eVector);
}
auto normalized() const
{
return (*this) * (1 / norm());
}
};
template <typename dim>
auto& operator<<(std::ostream& os, QuantityVector<dim> qv)
{
using Quantity = phys::units::quantity<dim, double>;
os << '(' << qv.eVector(0) << ' ' << qv.eVector(1) << ' ' << qv.eVector(2)
<< ") " << phys::units::to_unit_symbol<dim, double>(Quantity(phys::units::detail::magnitude_tag, 1));
return os;
}
#endif
#ifndef _include_SPHERE_H_
#define _include_SPHERE_H_
#include <Geometry/Point.h>
#include <Units/PhysicalUnits.h>
class Sphere
{
Point center;
Length const radius;
public:
Sphere(Point const& pCenter, Length const pRadius) :
center(pCenter), radius(pRadius)
{
}
auto isInside(Point const& p) const
{
return radius*radius > (center - p).squaredNorm();
}
};
#endif
#ifndef _include_VECTOR_H_
#define _include_VECTOR_H_
#include <Geometry/BaseVector.h>
#include <Geometry/QuantityVector.h>
#include <Units/PhysicalUnits.h>
/*!
* A Vector represents a 3-vector in Euclidean space. It is defined by components
* given in a specific CoordinateSystem. It has a physical dimension ("unit")
* as part of its type, so you cannot mix up e.g. electric with magnetic fields
* (but you could calculate their cross-product to get an energy flux vector).
*
* When transforming coordinate systems, a Vector is subject to the rotational
* part only and invariant under translations.
*/
template <typename dim>
class Vector : public BaseVector<dim>
{
using Quantity = phys::units::quantity<dim, double>;
public:
Vector(CoordinateSystem const& pCS, QuantityVector<dim> pQVector) :
BaseVector<dim>(pCS, pQVector)
{
}
Vector(CoordinateSystem const& cs, Quantity x, Quantity y, Quantity z) :
BaseVector<dim>(cs, QuantityVector<dim>(x, y, z))
{
}
/*!
* returns a QuantityVector with the components given in the "home"
* CoordinateSystem of the Vector
*/
auto GetComponents() const
{
return BaseVector<dim>::qVector;
}
/*!
* returns a QuantityVector with the components given in an arbitrary
* CoordinateSystem
*/
auto GetComponents(CoordinateSystem const& pCS) const
{
if (&pCS == BaseVector<dim>::cs)
{
return BaseVector<dim>::qVector;
}
else
{
return QuantityVector<dim>(CoordinateSystem::GetTransformation(*BaseVector<dim>::cs, pCS).linear() * BaseVector<dim>::qVector.eVector);
}
}
/*!
* transforms the Vector into another CoordinateSystem by changing
* its components internally
*/
void rebase(CoordinateSystem const& pCS)
{
BaseVector<dim>::qVector = GetComponents(pCS);
BaseVector<dim>::cs = &pCS;
}
/*!
* returns the norm/length of the Vector. Before using this method,
* think about whether squaredNorm() might be cheaper for your computation.
*/
auto norm() const
{
return BaseVector<dim>::qVector.norm();
}
/*!
* returns the squared norm of the Vector. Before using this method,
* think about whether norm() might be cheaper for your computation.
*/
auto squaredNorm() const
{
return BaseVector<dim>::qVector.squaredNorm();
}
/*!
* returns a Vector \f$ \vec{v}_{\parallel} \f$ which is the parallel projection
* of this vector \f$ \vec{v}_1 \f$ along another Vector \f$ \vec{v}_2 \f$ given by
* \f[
* \vec{v}_{\parallel} = \frac{\vec{v}_1 \cdot \vec{v}_2}{\vec{v}_2^2} \vec{v}_2
* \f]
*/
template <typename dim2>
auto parallelProjectionOnto(Vector<dim2> const& pVec, CoordinateSystem const& pCS) const
{
auto const ourCompVec = GetComponents(pCS);
auto const otherCompVec = pVec.GetComponents(pCS);
auto const& a = ourCompVec.eVector;
auto const& b = otherCompVec.eVector;
return Vector<dim>(pCS, QuantityVector<dim>(b * ((a.dot(b)) / b.squaredNorm())));
}
template <typename dim2>
auto parallelProjectionOnto(Vector<dim2> const& pVec) const
{
return parallelProjectionOnto<dim2>(pVec, *BaseVector<dim>::cs);
}
auto operator+(Vector<dim> const& pVec) const
{
auto const components = GetComponents(*BaseVector<dim>::cs) + pVec.GetComponents(*BaseVector<dim>::cs);
return Vector<dim>(*BaseVector<dim>::cs, components);
}
auto operator-(Vector<dim> const& pVec) const
{
auto const components = GetComponents() - pVec.GetComponents(*BaseVector<dim>::cs);
return Vector<dim>(*BaseVector<dim>::cs, components);
}
auto& operator*=(double const p)
{
BaseVector<dim>::qVector *= p;
return *this;
}
template <typename ScalarDim>
auto operator*(phys::units::quantity<ScalarDim, double> const p) const
{
using ProdQuantity = phys::units::detail::Product<dim, ScalarDim, double, double>;
if constexpr (std::is_same<ProdQuantity, double>::value) // result dimensionless, not a "Quantity" anymore
{
return Vector<phys::units::dimensionless_d>(*BaseVector<dim>::cs, BaseVector<dim>::qVector * p);
}
else
{
return Vector<typename ProdQuantity::dimension_type>(*BaseVector<dim>::cs, BaseVector<dim>::qVector * p);
}
}
template <typename ScalarDim>
auto operator/(phys::units::quantity<ScalarDim, double> const p) const
{
return (*this) * (1 / p);
}
auto operator*(double const p) const
{
return Vector<dim>(*BaseVector<dim>::cs, BaseVector<dim>::qVector * p);
}
auto operator/(double const p) const
{
return Vector<dim>(*BaseVector<dim>::cs, BaseVector<dim>::qVector / p);
}
auto& operator+=(Vector<dim> const& pVec)
{
BaseVector<dim>::qVector += pVec.GetComponents(*BaseVector<dim>::cs);
return *this;
}
auto& operator-=(Vector<dim> const& pVec)
{
BaseVector<dim>::qVector -= pVec.GetComponents(*BaseVector<dim>::cs);
return *this;
}
auto& operator-() const
{
return Vector<dim>(*BaseVector<dim>::cs, - BaseVector<dim>::qVector);
}
auto normalized() const
{
return (*this) * (1 / norm());
}
template <typename dim2>
auto cross(Vector<dim2> pV) const
{
auto const c1 = GetComponents().eVector;
auto const c2 = pV.GetComponents(*BaseVector<dim>::cs).eVector;
auto const bareResult = c1.cross(c2);
using ProdQuantity = phys::units::detail::Product<dim, dim2, double, double>;
if constexpr (std::is_same<ProdQuantity, double>::value) // result dimensionless, not a "Quantity" anymore
{
return Vector<phys::units::dimensionless_d>(*BaseVector<dim>::cs, bareResult);
}
else
{
return Vector<typename ProdQuantity::dimension_type>(*BaseVector<dim>::cs, bareResult);
}
}
};
#endif
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <catch2/catch.hpp>
#include <Units/PhysicalUnits.h>
using namespace phys::units;
using namespace phys::units::literals;
TEST_CASE( "PhysicalUnits", "[Units]" )
{
SECTION( "sectionOne" )
{
REQUIRE( 1_m/1_m == 1 );
}
SECTION( "sectionTwo" )
{
REQUIRE_FALSE( 1_m/1_m == 2 );
}
SECTION( "sectionThree" )
{
REQUIRE( 1_s/1_s == 2 );
}
}
#ifndef _include_BufferedSink_h_
#define _include_BufferedSink_h_
namespace logger {
namespace sink {
/**
Output buffer template. NoBuffer does nothingk.
*/
/*
struct NoBuffer {
inline bool Test(const std::string&) const { return false; }
inline std::string GetString() const { return std::string(""); }
inline void Clear() {}
inline void Add(const std::string&) {}
};
*/
/**
Output buffer template. StdBuffer records fSize characters in
local memeory before passing it on to further output stages.
*/
struct StdBuffer {
StdBuffer(const int size) : fSize(size) {}
inline bool Test(const std::string& s) { return int(fBuffer.tellp())+s.length() < fSize; }
inline std::string GetString() const { return fBuffer.str(); }
inline void Clear() { fBuffer.str(""); }
inline void Add(const std::string& s) { fBuffer << s; }
private:
int fSize;
std::ostringstream fBuffer;
};
/**
Definition of Sink for log output.
*/
template<typename TStream, typename TBuffer=StdBuffer>
class BufferedSink {
public:
BufferedSink(TStream& out, TBuffer buffer = {} ) : fOutput(out), fBuffer(std::move(buffer)) {}
void operator<<(const std::string& msg) {
if (!fBuffer.Test(msg)) {
fOutput << fBuffer.GetString();
fBuffer.Clear();
}
if (!fBuffer.Test(msg))
fOutput << msg;
else
fBuffer.Add(msg);
}
void Close() { fOutput << fBuffer.GetString(); }
private:
TStream& fOutput;
TBuffer fBuffer;
};
typedef BufferedSink<std::ostream, StdBuffer> BufferedSinkStream;
}// end namespace
} // end namespace
#endif
add_library (CORSIKAlogging INTERFACE)
target_include_directories (CORSIKAlogging INTERFACE ${PROJECT_SOURCE_DIR}/Framework)
target_include_directories (CORSIKAlogging INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework>
$<INSTALL_INTERFACE:include/Framework>
)
install (FILES Logger.h Sink.h MessageOn.h MessageOff.h NoSink.h Sink.h BufferedSink.h
DESTINATION include/Logging)
# code testing
add_executable (testLogging testLogging.cc)
target_link_libraries (testLogging CORSIKAlogging CORSIKAthirdparty) # for catch2
add_test (NAME testLogging COMMAND testLogging -o report.xml -r junit)
#ifndef _include_logger_h_
#define _include_logger_h_
#include <iosfwd>
#include <string>
#include <sstream>
#include <typeinfo>
#include <boost/format.hpp>
#include <Logging/MessageOn.h>
#include <Logging/MessageOff.h>
#include <Logging/Sink.h>
#include <Logging/NoSink.h>
#include <Logging/BufferedSink.h>
using namespace std;
using namespace boost;
/**
Everything around logfile generation and text output.
*/
namespace logger {
/**
Defines one stream to accept messages, and to wrote those into
TSink. The helper class MessageOn will convert input at
compile-time into message strings. The helper class MessageOff,
will just do nothing and will be optimized away at compile time.
*/
template<typename MSG=MessageOn, typename TSink=sink::NoSink>
class Logger : private MSG {
using MSG::Message;
public:
// Logger() : fName("") {}
Logger(const std::string color, const std::string name, TSink& sink) : fSink(sink), fName(color+"["+name+"]\033[39m ") {}
~Logger() { fSink.Close(); }
// Logger(const Logger&) = delete;
/**
Function to add string-concatenation of all inputs to output
sink.
*/
template<typename ... Strings>
void Log(const Strings&... inputs) {
fSink << MSG::Message(inputs...);
}
const std::string& GetName() const { return fName; }
private:
TSink& fSink;
std::string fName;
};
} // end namesapce
#define LOG(__LOGGER,...) \
__LOGGER.Log(__LOGGER.GetName(), __FILE__,":", __LINE__, " (", __func__, ") -> ", ##__VA_ARGS__);
#endif
#ifndef _include_MessageOff_h_
#define _include_MessageOff_h_
namespace logger {
/**
Helper class to ignore all arguments to MessagesOn::Message and
always return empty string "".
*/
class MessageOff {
protected:
template<typename First, typename ... Strings> std::string Message(const First& arg, const Strings&... rest) {
return "";
}
};
} // end namespace
#endif
#ifndef _include_MessageOn_h_
#define _include_MessageOn_h_
namespace logger {
/**
Helper class to convert all input arguments of MessageOn::Message
into string-concatenated version and return this as string.
*/
class MessageOn {
protected:
std::string Message() { return "\n"; }
template<typename First, typename ... Strings> std::string Message(const First& arg, const Strings&... rest) {
std::ostringstream ss;
ss << arg << Message(rest...);
return ss.str();
}
template<typename ... Strings> std::string Message(const int& arg, const Strings&... rest) {
return std::to_string(arg) + Message(rest...);
}
template<typename ... Strings> std::string Message(const double& arg, const Strings&... rest) {
return std::to_string(arg) + Message(rest...);
}
template<typename ... Strings> std::string Message(char const * arg, const Strings&... rest) {
return std::string(arg) + Message(rest...);
}
template<typename ... Strings> std::string Message(const std::string& arg, const Strings&... rest) {
return arg + Message(rest...);
}
// ----------------------
// boost format
template<typename ... Strings> std::string Message(const boost::format& fmt, const Strings&... rest) {
boost::format FMT(fmt);
return bformat(FMT, rest...);
}
template<typename Arg, typename ... Strings> std::string bformat(boost::format& fmt, const Arg& arg, const Strings&... rest) {
fmt % arg;
return bformat(fmt, rest...);
}
std::string bformat(boost::format& fmt) { return fmt.str() + "\n"; }
};
}// end namesapce
#endif
#ifndef _include_NoSink_h_
#define _include_NoSink_h_
namespace logger {
namespace sink {
struct NoSink {
inline void operator<<(const std::string&) {}
inline void Close() {}
};
}// end namespace
} // end namespace
#endif
#ifndef _include_Sink_h_
#define _include_Sink_h_
namespace logger {
/**
a sink for the logger must implement the two functions
operator<<(const std::string&)
and
Close()
See example: NoSink
*/
namespace sink {
/**
Definition of Sink for log output.
*/
template<typename TStream>
class Sink {
public:
Sink(TStream& out) : fOutput(out) {}
void operator<<(const std::string& msg) {
fOutput << msg;
}
void Close() {}
private:
TStream& fOutput;
};
typedef Sink<std::ostream> SinkStream;
}// end namespace
} // end namespace
#endif
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <catch2/catch.hpp>
#include <Logging/Logger.h>
TEST_CASE( "Logging", "[Logging]" )
{
SECTION( "sectionOne" )
{
REQUIRE( 1/1 == 1 );
}
SECTION( "sectionTwo" )
{
REQUIRE_FALSE( 1/1 == 2 );
}
SECTION( "sectionThree" )
{
REQUIRE( 1/1 == 2 );
}
}