// $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/tiptilt_ctrl/bcu/util/Assertions.cpp 960 2018-10-30 11:14:14Z depa $
#include "Assertions.h"

#include <boost/format.hpp>
#include <iostream>
#include <string>

using namespace std;
using boost::format;

namespace Sharknir {

void Condition::check(const std::string& conditionTypeName, bool condition,
        const std::string& literalCondition, const std::string& message,
        const char *filename, int lineNr)
{
    if (! condition)
    {
        printErrorMessage(conditionTypeName, literalCondition, message,
                filename, lineNr);
        ::abort();
    }
}

void Condition::printErrorMessage(const std::string conditionTypeName,
        const std::string literalCondition, const std::string& message,
        const char *filename, int lineNr)
{
    string errorMessage= (format("Error: %s '%s' (%s) failed in %s:%d")
            % conditionTypeName
            % message
            % literalCondition
            % filename
            % lineNr).str();

    cerr << errorMessage << endl;
}

}
