Program Listing for File Algorithm.h
↰ Return to documentation for file (include/gwmodelpp/Algorithm.h
)
#ifndef ALGORITHM_H
#define ALGORITHM_H
#include <cfloat>
#include <memory>
#include <sstream>
#include "Status.h"
#include "Logger.h"
namespace gwm
{
#define GWM_LOGGING(MESSAGE, LEVEL) this->mTelegram->print((MESSAGE), (LEVEL), __FUNCTION__, __FILE__);
#define GWM_LOG_DEBUG(MESSAGE) this->mTelegram->print((MESSAGE), Logger::LogLevel::LOG_DEBUG, __FUNCTION__, __FILE__);
#define GWM_LOG_INFO(MESSAGE) this->mTelegram->print((MESSAGE), Logger::LogLevel::LOG_INFO, __FUNCTION__, __FILE__);
#define GWM_LOG_WARNNING(MESSAGE) this->mTelegram->print((MESSAGE), Logger::LogLevel::LOG_WARNING, __FUNCTION__, __FILE__);
#define GWM_LOG_ERROR(MESSAGE) this->mTelegram->print((MESSAGE), Logger::LogLevel::LOG_ERR, __FUNCTION__, __FILE__);
#define GWM_LOG_STOP_BREAK(STATUS) { if (this->mTelegram->stop()) { STATUS = gwm::Status::Terminated; break;} };
#define GWM_LOG_STOP_CONTINUE(STATUS) { if (this->mTelegram->stop()) { STATUS = gwm::Status::Terminated; continue;} };
#define GWM_LOG_STOP_RETURN(STATUS, REVAL) { if (this->mTelegram->stop()) { STATUS = gwm::Status::Terminated; return (REVAL);} }
#define GWM_LOG_PROGRESS(CURRENT, TOTAL) { this->mTelegram->progress((CURRENT), (TOTAL), (__FUNCTION__), (__FILE__)); };
#define GWM_LOG_PROGRESS_PERCENT(PERCENT) { this->mTelegram->progress((PERCENT), (__FUNCTION__), (__FILE__)); };
#define GWM_LOG_TAG_STAGE "#stage "
#define GWM_LOG_STAGE(STAGE) { GWM_LOG_INFO((std::string(GWM_LOG_TAG_STAGE) + (STAGE))); }
class Algorithm
{
public:
Algorithm() : mTelegram(new Logger()) {}
virtual ~Algorithm() {}
public:
const std::unique_ptr<ITelegram>& telegram() const
{
return mTelegram;
}
void setTelegram(std::unique_ptr<ITelegram> telegram)
{
mTelegram = std::move(telegram);
}
void debug(std::string message, std::string function, std::string file)
{
mTelegram->print(message, ITelegram::LogLevel::LOG_DEBUG, function, file);
}
const Status status() const { return mStatus; }
public:
virtual bool isValid() = 0;
protected:
void setStatus(Status status) { mStatus = status; }
protected:
std::unique_ptr<ITelegram> mTelegram = nullptr;
Status mStatus = Status::Success;
};
}
#endif // ALGORITHM_H