SST  12.0.1
StructuralSimulationToolkit
timeConverter.h
1 // Copyright 2009-2022 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-2022, 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_TIMECONVERTER_H
13 #define SST_CORE_TIMECONVERTER_H
14 
15 #include "sst/core/sst_types.h"
16 #include "sst/core/unitAlgebra.h"
17 
18 namespace SST {
19 
20 class TimeLord;
21 
22 /**
23  A class to convert between a component's view of time and the
24  core's view of time.
25 */
27 {
28 
29  friend class TimeLord;
30 
31 public:
32  /**
33  Converts from the component's view to the core's view of time.
34  \param time time to convert to core time
35  */
36  SimTime_t convertToCoreTime(SimTime_t time) const { return time * factor; }
37 
38  /**
39  Converts from the core's view to the components's view of time.
40  The result is truncated, not rounded.
41  \param time time to convert from core time
42  */
43  SimTime_t convertFromCoreTime(SimTime_t time) const { return time / factor; }
44 
45  /**
46  * Return the factor used for conversions with Core Time
47  */
48  SimTime_t getFactor() const { return factor; }
49 
50  /**
51  Return the period represented by this TimeConverter as a
52  UnitAlgebra
53  */
54  UnitAlgebra getPeriod() const; // Implemented in timeLord.cc
55 
56 private:
57  /**
58  Factor for converting between core and component time
59  */
60  SimTime_t factor;
61 
62  TimeConverter(SimTime_t fact) { factor = fact; }
63 
64  ~TimeConverter() {}
65 
66  TimeConverter() {} // Only needed to simplify serialization
67 };
68 
69 } // namespace SST
70 
71 #endif // SST_CORE_TIMECONVERTER_H
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:26
SimTime_t getFactor() const
Return the factor used for conversions with Core Time.
Definition: timeConverter.h:48
SimTime_t convertToCoreTime(SimTime_t time) const
Converts from the component's view to the core's view of time.
Definition: timeConverter.h:36
SimTime_t convertFromCoreTime(SimTime_t time) const
Converts from the core's view to the components's view of time.
Definition: timeConverter.h:43
UnitAlgebra getPeriod() const
Return the period represented by this TimeConverter as a UnitAlgebra.
Definition: timeLord.cc:178
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:37
Performs Unit math in full precision.
Definition: unitAlgebra.h:106