All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Algorithm.h
Go to the documentation of this file.
1 #ifndef ALGORITHM_H
2 #define ALGORITHM_H
3 
4 #include <string>
5 #include <stdexcept>
6 
7 namespace NetworKit {
8 
9 class Algorithm {
10 protected:
14  bool hasRun;
15 public:
19  Algorithm();
20 
24  virtual ~Algorithm() = default;
25 
29  virtual void run() = 0;
30 
35  bool hasFinished() const {
36  return hasRun;
37  };
38 
42  void assureFinished() const {
43  if (!hasRun) throw std::runtime_error("Error, run must be called first");
44  };
45 
50  virtual std::string toString() const;
51 
55  virtual bool isParallel() const;
56 };
57 
58 } /* NetworKit */
59 
60 #endif /* ALGORITHM_H */
virtual bool isParallel() const
Definition: Algorithm.cpp:15
bool hasRun
A boolean variable indicating whether an algorithm has finished its computation or not...
Definition: Algorithm.h:14
virtual void run()=0
The generic run method which calls runImpl() and takes care of setting to the appropriate value...
virtual std::string toString() const
Returns a string with the algorithm's name and its parameters, if there are any.
Definition: Algorithm.cpp:11
void assureFinished() const
Assure that the algorithm has been run, throws a std::runtime_error otherwise.
Definition: Algorithm.h:42
Definition: Algorithm.h:9
Algorithm()
Constructor to the algorithm base class.
Definition: Algorithm.cpp:7
bool hasFinished() const
Indicates whether an algorithm has completed computation or not.
Definition: Algorithm.h:35
virtual ~Algorithm()=default
Virtual default destructor.