SST  14.1.0
StructuralSimulationToolkit
timeConverter.h
1 // Copyright 2009-2024 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-2024, 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/serialization/serialize_impl_fwd.h"
16 #include "sst/core/sst_types.h"
17 #include "sst/core/unitAlgebra.h"
18 
19 namespace SST {
20 
21 class TimeLord;
22 
23 /**
24  A class to convert between a component's view of time and the
25  core's view of time.
26 */
28 {
29 
30  friend class TimeLord;
31 
32 public:
33  /**
34  Converts from the component's view to the core's view of time.
35  @param time time to convert to core time
36  */
37  SimTime_t convertToCoreTime(SimTime_t time) const { return time * factor; }
38 
39  /**
40  Converts from the core's view to the components's view of time.
41  The result is truncated, not rounded.
42  @param time time to convert from core time
43  */
44  SimTime_t convertFromCoreTime(SimTime_t time) const { return time / factor; }
45 
46  /**
47  * @return The factor used for conversions with Core Time
48  */
49  SimTime_t getFactor() const { return factor; }
50 
51  /**
52  @return The period represented by this TimeConverter as a 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 template <>
71 {
72  template <class A>
73  friend class serialize;
74  // Function implemented in timeLord.cc
75  void operator()(TimeConverter*& s, SST::Core::Serialization::serializer& ser, const char* name = nullptr);
76 };
77 
78 } // namespace SST
79 
80 #endif // SST_CORE_TIMECONVERTER_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
SimTime_t getFactor() const
Definition: timeConverter.h:49
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:27
Base serialize class.
Definition: serialize.h:45
Definition: action.cc:18
Serialization "gateway" object.
Definition: serialize.h:133
SimTime_t convertFromCoreTime(SimTime_t time) const
Converts from the core&#39;s view to the components&#39;s view of time.
Definition: timeConverter.h:44
SimTime_t convertToCoreTime(SimTime_t time) const
Converts from the component&#39;s view to the core&#39;s view of time.
Definition: timeConverter.h:37
UnitAlgebra getPeriod() const
Definition: timeLord.cc:180
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:37
Performs Unit math in full precision.
Definition: unitAlgebra.h:106