SST  8.0.0
StructuralSimulationToolkit
stopAction.h
1 // Copyright 2009-2018 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2018, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_STOPACTION_H
13 #define SST_CORE_STOPACTION_H
14 
15 #include <iostream>
16 #include <cinttypes>
17 
18 #include <sst/core/action.h>
19 #include <sst/core/output.h>
20 
21 namespace SST {
22 
23 /**
24  * Action which causes the Simulation to end
25  */
26 class StopAction : public Action
27 {
28 private:
29 
30  std::string message;
31  bool print_message;
32 
33 public:
34  StopAction() {
35  setPriority(STOPACTIONPRIORITY);
36  print_message = false;
37  }
38 
39  /** Create a new StopAction which includes a message to be printed when it fires
40  */
41  StopAction(std::string msg) {
42  setPriority(STOPACTIONPRIORITY);
43  print_message = true;
44  message = msg;
45  }
46 
47  void execute() override {
48  if ( print_message ) {
49  Output::getDefaultObject().output("%s\n", message.c_str());
50  }
51  endSimulation();
52  }
53 
54  void print(const std::string &header, Output &out) const override {
55  out.output("%s StopAction to be delivered at %" PRIu64 "\n", header.c_str(), getDeliveryTime());
56  }
57 
58 };
59 
60 } // namespace SST
61 
62 #endif //SST_CORE_STOPACTION_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:54
An Action is a schedulable Activity which is not an Event.
Definition: action.h:30
Action which causes the Simulation to end.
Definition: stopAction.h:26
void setPriority(int priority)
Set the priority of the Activity.
Definition: activity.h:340
SimTime_t getDeliveryTime() const
Return the time at which this Activity will be delivered.
Definition: activity.h:207
StopAction(std::string msg)
Create a new StopAction which includes a message to be printed when it fires.
Definition: stopAction.h:41
void output(uint32_t line, const char *file, const char *func, const char *format,...) const
Output the message with formatting as specified by the format parameter.
Definition: output.h:184
void execute() override
Function which will be called when the time for this Activity comes to pass.
Definition: stopAction.h:47
void endSimulation()
Called to signal to the Simulation object to end the simulation.
Definition: action.cc:19
void print(const std::string &header, Output &out) const override
Generic print-print function for this Activity.
Definition: stopAction.h:54