← Documentation
ADS-IDAC Engine 5.0.0
ProcedureStepUnit.h
Go to the documentation of this file.
1#pragma once
2
3// ProcedureStepUnit.h: interface for the ProcedureStepUnit class.
4//
6
7#include <cmath>
8#include <string>
9#include <vector>
10#include <fstream>
11#include <stdexcept>
12#include <type_traits>
13#include <boost/archive/binary_oarchive.hpp>
14#include <boost/archive/binary_iarchive.hpp>
15#include <boost/serialization/split_member.hpp>
16
17#include "ProcedureActionUnit.h"
18#include "ExpectationElement.h"
19#include "ExpectationORUnit.h"
20#include "../ControlPanel/StateOfActivation.h"
21#include "ProcedureStepInfo.h"
22#include "../Crew/ShortTermMemory.h"
24#include "../Scheduler/AnalysisInfoContainer.h"
25#include "../Scheduler/AnalysisProcedureDataContainerUnit.h"
26
27// Include Boost.Serialization headers
28#include <boost/serialization/access.hpp>
29#include <boost/serialization/base_object.hpp>
30#include <boost/serialization/vector.hpp>
31#include <boost/serialization/unique_ptr.hpp>
32#include <boost/serialization/serialization.hpp>
33#include <boost/serialization/export.hpp>
34#include <memory>
35
36class Operator;
37
38
39
41{
42public:
44 virtual ~ProcedureStepUnit();
45 // Existing member functions
46 void setTypeOfAction(int);
47 int getTypeOfAction();
54 bool hasNonResponseAction() const;
56 double calculateAdjustedSkipProbability(double, double);
57 bool readInfofromFile(std::ifstream &);
58 int readInfofromFileAction(std::ifstream &);
59 void readInfofromFileExpectation(std::ifstream &, int);
60 bool readInfoFromFileNonResponseExit(std::ifstream &);
61 bool checkIfIsChangeSystemAction(std::string );
62 int checkForTypeOfExpectation(std::string );
63 void setStateOfAction(int);
65 int getStateOfAction();
68 bool executeAction(Operator &, ShortTermMemory &, int, std::string, std::string, std::string, double, double);
70 bool executeNonResponseAction(Operator &, ShortTermMemory &, int, std::string, std::string, double, double);
71 void setStateOfExpectation(int);
74 void saveProcedureStepUnitToFile(std::ofstream &);
75 void saveProcedureStepUnitActionToFile(std::ofstream &);
79 void saveProcedureStepUnitExpectationToFile(std::ofstream &);
80 void retrieveProcedureStepUnitFromFile(std::ifstream &);
81 void retrieveProcedureStepUnitActionFromFile(std::ifstream &);
86
87 // Member variables
88 std::unique_ptr<ProcedureActionUnit> action;
89 std::unique_ptr<ProcedureStepInfo> mental_procedure;
90 std::unique_ptr<ProcedureScannedParameterUnit> scanned_parameter;
91 std::vector<std::unique_ptr<ExpectationORUnit>> expectation;
92 std::unique_ptr<ProcedureActionUnit> non_response_action_unit;
93 std::unique_ptr<ProcedureStepInfo> non_response_procedure;
94 std::unique_ptr<ProcedureScannedParameterUnit> non_response_scan;
95
96private:
101
102 int serialized_expectation_count = -1; // -1 = not std::set (use expectation.size())
103
104 // State overlay: state only. type_of_* and the mental/non-response
105 // procedure references are definitions re-seeded from the master.
106 // action / non_response_action_unit / scan units carry Timer execution
107 // state and are (de)serialized IN PLACE through presence flags so their
108 // seeded definitions survive the load. The polymorphic expectation tree
109 // is walked in place as well: state only on binary archives, whole
110 // elements on text archives (see save/load below).
112 BOOST_SERIALIZATION_SPLIT_MEMBER()
113 template<class Archive>
114 void save(Archive & ar, const unsigned int) const
115 {
116 ar & boost::serialization::base_object<StateOfActivation>(*this);
117 ar & state_of_action;
120 save_inplace(ar, action);
122 // Expectation trees walk state-only through the virtual hooks; their
123 // class serializers carry every member for dynamic crew users. The
124 // hooks are concrete-binary virtuals (virtual templates don't exist);
125 // text archives keep full elements.
126 if constexpr (std::is_same_v<Archive, boost::archive::binary_oarchive>) {
127 const uint32_t n_or = static_cast<uint32_t>(expectation.size());
128 ar & n_or;
129 for (const auto& oru : expectation)
130 oru->state_save(ar);
131 } else {
132 ar & expectation;
133 }
136 }
137 template<class Archive>
138 void load(Archive & ar, const unsigned int)
139 {
140 ar & boost::serialization::base_object<StateOfActivation>(*this);
141 ar & state_of_action;
144 load_inplace(ar, action);
146 if constexpr (std::is_same_v<Archive, boost::archive::binary_iarchive>) {
147 uint32_t n_or = 0;
148 ar & n_or;
149 if (n_or != expectation.size())
150 throw std::runtime_error(
151 "ProcedureStepUnit state overlay: expectation count mismatch "
152 "against the seeded book");
153 for (auto& oru : expectation)
154 oru->state_load(ar);
155 } else {
156 ar & expectation;
157 }
160 }
161 template<class Archive, class T>
162 static void save_inplace(Archive& ar, const std::unique_ptr<T>& p)
163 {
164 const bool present = (p != nullptr);
165 ar & present;
166 if (!present) return;
167 if constexpr (std::is_same_v<Archive, boost::archive::binary_oarchive>)
168 p->state_save(ar); // Timer progress only; definitions are seeded
169 else
170 ar & *p;
171 }
172 template<class Archive, class T>
173 static void load_inplace(Archive& ar, std::unique_ptr<T>& p)
174 {
175 bool present = false;
176 ar & present;
177 if (present != (p != nullptr))
178 throw std::runtime_error(
179 "ProcedureStepUnit state overlay: sub-unit presence mismatch "
180 "against the seeded book");
181 if (!present) return;
182 if constexpr (std::is_same_v<Archive, boost::archive::binary_iarchive>)
183 p->state_load(ar);
184 else
185 ar & *p;
186 }
187};
188
189BOOST_CLASS_EXPORT_KEY(ProcedureStepUnit)
void saveProcedureStepUnitNonResponseActionToFile(std::ofstream &)
bool executeExpectation(Operator &, ShortTermMemory &, int)
void setTypeOfNonResponseAction(int)
std::vector< std::unique_ptr< ExpectationORUnit > > expectation
std::unique_ptr< ProcedureScannedParameterUnit > non_response_scan
std::unique_ptr< ProcedureStepInfo > mental_procedure
void retrieveProcedureStepUnitMentalProcedureFromFile(std::ifstream &)
void retrieveProcedureStepUnitFromFile(std::ifstream &)
void setStateOfNonResponseAction(int)
void readInfofromFileExpectation(std::ifstream &, int)
void retrieveProcedureStepUnitExpectationFromFile(std::ifstream &)
bool hasNonResponseAction() const
double calculateDynamicHEPMultiplier(int, std::string, AnalysisProcedureDataContainerUnit &)
void save(Archive &ar, const unsigned int) const
std::unique_ptr< ProcedureScannedParameterUnit > scanned_parameter
int checkForTypeOfExpectation(std::string)
bool executeAction(Operator &, ShortTermMemory &, int, std::string, std::string, std::string, double, double)
ProcedureStepInfo * getMentalProcedurePtr()
double calculateAdjustedSkipProbability(double, double)
void retrieveProcedureStepUnitNonResponseActionFromFile(std::ifstream &)
ProcedureScannedParameterUnit * getScannedParameterUnitPtr()
void load(Archive &ar, const unsigned int)
bool checkIfIsChangeSystemAction(std::string)
static void save_inplace(Archive &ar, const std::unique_ptr< T > &p)
static void load_inplace(Archive &ar, std::unique_ptr< T > &p)
ProcedureActionUnit * getActionPtr()
void saveProcedureStepUnitToFile(std::ofstream &)
bool executeNonResponseAction(Operator &, ShortTermMemory &, int, std::string, std::string, double, double)
friend class boost::serialization::access
void setActionPtr(ProcedureActionUnit *)
void saveProcedureStepUnitScannedParameterToFile(std::ofstream &)
std::unique_ptr< ProcedureStepInfo > non_response_procedure
bool readInfofromFile(std::ifstream &)
std::unique_ptr< ProcedureActionUnit > action
void saveProcedureStepUnitExpectationToFile(std::ofstream &)
void retrieveProcedureStepUnitActionFromFile(std::ifstream &)
bool readInfoFromFileNonResponseExit(std::ifstream &)
void saveProcedureStepUnitMentalProcedureToFile(std::ofstream &)
void saveProcedureStepUnitActionToFile(std::ofstream &)
void copyProcedureStepUnit(ProcedureStepUnit &)
std::unique_ptr< ProcedureActionUnit > non_response_action_unit
int readInfofromFileAction(std::ifstream &)
void retrieveProcedureStepUnitScannedParameterFromFile(std::ifstream &)