Skip to content
Snippets Groups Projects
Commit f78f027f authored by Savici, Andrei T.'s avatar Savici, Andrei T. Committed by GitHub
Browse files

Merge pull request #19902 from mantidproject/algorithm_headers2

Algorithm headers
parents 59357f1a ff8f5355
No related branches found
No related tags found
No related merge requests found
......@@ -92,52 +92,40 @@ class MANTID_API_DLL Algorithm : public IAlgorithm,
public Kernel::PropertyManagerOwner {
public:
/// Base class for algorithm notifications
class AlgorithmNotification : public Poco::Notification {
class MANTID_API_DLL AlgorithmNotification : public Poco::Notification {
public:
AlgorithmNotification(const Algorithm *const alg)
: Poco::Notification(), m_algorithm(alg) {} ///< Constructor
const IAlgorithm *algorithm() const {
return m_algorithm;
} ///< The algorithm
AlgorithmNotification(const Algorithm *const alg);
const IAlgorithm *algorithm() const;
private:
const IAlgorithm *const m_algorithm; ///< The algorithm
};
/// StartedNotification is sent when the algorithm begins execution.
class StartedNotification : public AlgorithmNotification {
class MANTID_API_DLL StartedNotification : public AlgorithmNotification {
public:
StartedNotification(const Algorithm *const alg)
: AlgorithmNotification(alg) {} ///< Constructor
std::string name() const override {
return "StartedNotification";
} ///< class name
StartedNotification(const Algorithm *const alg);
std::string name() const override;
};
/// FinishedNotification is sent after the algorithm finishes its execution
class FinishedNotification : public AlgorithmNotification {
class MANTID_API_DLL FinishedNotification : public AlgorithmNotification {
public:
FinishedNotification(const Algorithm *const alg, bool res)
: AlgorithmNotification(alg), success(res) {} ///< Constructor
std::string name() const override {
return "FinishedNotification";
} ///< class name
FinishedNotification(const Algorithm *const alg, bool res);
std::string name() const override;
bool success; ///< true if the finished algorithm was successful or false if
/// it failed.
};
/// An algorithm can report its progress by sending ProgressNotification. Use
/// Algorithm::progress(double) function to send a progress notification.
class ProgressNotification : public AlgorithmNotification {
class MANTID_API_DLL ProgressNotification : public AlgorithmNotification {
public:
/// Constructor
ProgressNotification(const Algorithm *const alg, double p,
const std::string &msg, double estimatedTime,
int progressPrecision)
: AlgorithmNotification(alg), progress(p), message(msg),
estimatedTime(estimatedTime), progressPrecision(progressPrecision) {}
std::string name() const override {
return "ProgressNotification";
} ///< class name
int progressPrecision);
std::string name() const override;
double progress; ///< Current progress. Value must be between 0 and 1.
std::string message; ///< Message sent with notification
double estimatedTime; ///<Estimated time to completion
......@@ -147,14 +135,11 @@ public:
/// ErrorNotification is sent when an exception is caught during execution of
/// the algorithm.
class ErrorNotification : public AlgorithmNotification {
class MANTID_API_DLL ErrorNotification : public AlgorithmNotification {
public:
/// Constructor
ErrorNotification(const Algorithm *const alg, const std::string &str)
: AlgorithmNotification(alg), what(str) {}
std::string name() const override {
return "ErrorNotification";
} ///< class name
ErrorNotification(const Algorithm *const alg, const std::string &str);
std::string name() const override;
std::string what; ///< message string
};
......@@ -165,14 +150,10 @@ public:
/// periodically Algorithm::interuption_point() which checks if
/// Algorithm::cancel() has been called
/// and throws CancelException if needed.
class CancelException : public std::exception {
class MANTID_API_DLL CancelException : public std::exception {
public:
/// Returns the message string.
const char *what() const noexcept override { return outMessage.c_str(); }
private:
/// The message returned by what()
std::string outMessage{"Algorithm terminated"};
const char *what() const noexcept override;
};
//============================================================================
......
......@@ -1769,6 +1769,53 @@ void Algorithm::setCommunicator(const Parallel::Communicator &communicator) {
m_communicator = Kernel::make_unique<Parallel::Communicator>(communicator);
}
//---------------------------------------------------------------------------
// Algorithm's inner classes
//---------------------------------------------------------------------------
Algorithm::AlgorithmNotification::AlgorithmNotification(
const Algorithm *const alg)
: Poco::Notification(), m_algorithm(alg) {}
const IAlgorithm *Algorithm::AlgorithmNotification::algorithm() const {
return m_algorithm;
}
Algorithm::StartedNotification::StartedNotification(const Algorithm *const alg)
: AlgorithmNotification(alg) {}
std::string Algorithm::StartedNotification::name() const {
return "StartedNotification";
} ///< class name
Algorithm::FinishedNotification::FinishedNotification(
const Algorithm *const alg, bool res)
: AlgorithmNotification(alg), success(res) {}
std::string Algorithm::FinishedNotification::name() const {
return "FinishedNotification";
}
Algorithm::ProgressNotification::ProgressNotification(
const Algorithm *const alg, double p, const std::string &msg,
double estimatedTime, int progressPrecision)
: AlgorithmNotification(alg), progress(p), message(msg),
estimatedTime(estimatedTime), progressPrecision(progressPrecision) {}
std::string Algorithm::ProgressNotification::name() const {
return "ProgressNotification";
}
Algorithm::ErrorNotification::ErrorNotification(const Algorithm *const alg,
const std::string &str)
: AlgorithmNotification(alg), what(str) {}
std::string Algorithm::ErrorNotification::name() const {
return "ErrorNotification";
}
const char *Algorithm::CancelException::what() const noexcept {
return "Algorithm terminated";
}
} // namespace API
//---------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment