@@ -131,16 +131,14 @@ class FGDistributor : public FGFCSComponent
131
131
that represents this distributor component */
132
132
FGDistributor (FGFCS* fcs, Element* element);
133
133
134
- // / Destructor
135
- ~FGDistributor ();
136
-
137
134
/* * Executes the distributor logic.
138
135
@return true - always*/
139
136
bool Run (void ) override ;
140
137
141
138
private:
142
139
143
140
enum eType {eInclusive=0 , eExclusive} Type;
141
+ template <typename T> using vector_of_unique_ptr = std::vector<std::unique_ptr<T>>;
144
142
145
143
class PropValPair {
146
144
public:
@@ -154,15 +152,14 @@ class FGDistributor : public FGFCSComponent
154
152
Prop->SetValue (Val->GetValue ());
155
153
}
156
154
catch (...) {
157
- throw (Prop->GetName ()+" in distributor component is not known" );
155
+ throw BaseException (Prop->GetName ()+" in distributor component is not known" );
158
156
}
159
157
}
160
158
161
- std::string GetPropName () { return Prop->GetName (); }
162
- std::string GetValString () { return Val->GetName (); }
163
- bool GetLateBoundProp () { return Prop->IsLateBound (); }
164
- bool GetLateBoundValue () {return Val->IsLateBound ();
165
- }
159
+ std::string GetPropName () const { return Prop->GetName (); }
160
+ std::string GetValString () const { return Val->GetName (); }
161
+ bool GetLateBoundProp () const { return Prop->IsLateBound (); }
162
+ bool GetLateBoundValue () const { return Val->IsLateBound (); }
166
163
private:
167
164
FGPropertyValue_ptr Prop;
168
165
FGParameterValue_ptr Val;
@@ -172,30 +169,30 @@ class FGDistributor : public FGFCSComponent
172
169
public:
173
170
Case () : Test(nullptr ) {}
174
171
175
- ~Case () {
176
- for (auto pair: PropValPairs) delete pair;
177
- delete Test;
172
+ void SetTest (Element* test_element, std::shared_ptr<FGPropertyManager> propMan) {
173
+ Test = std::make_unique<FGCondition>(test_element, propMan);
174
+ }
175
+ const FGCondition& GetTest (void ) const noexcept { return *Test; }
176
+ void AddPropValPair (const std::string& property, const std::string& value,
177
+ std::shared_ptr<FGPropertyManager> propManager, Element* prop_val_el) {
178
+ PropValPairs.push_back (std::make_unique<PropValPair>(property, value, propManager, prop_val_el));
178
179
}
179
-
180
- void SetTest (FGCondition* test) {Test = test;}
181
- FGCondition* GetTest (void ) {return Test;}
182
- void AddPropValPair (PropValPair* pvPair) {PropValPairs.push_back (pvPair);}
183
180
void SetPropValPairs () {
184
- for (auto pair: PropValPairs) pair->SetPropToValue ();
181
+ for (auto & pair: PropValPairs) pair->SetPropToValue ();
185
182
}
186
- std::vector <PropValPair* >::const_iterator IterPropValPairs (void ) const
183
+ vector_of_unique_ptr <PropValPair>::const_iterator begin (void ) const
187
184
{ return PropValPairs.cbegin (); }
188
- std::vector <PropValPair* >::const_iterator EndPropValPairs (void ) const
185
+ vector_of_unique_ptr <PropValPair>::const_iterator end (void ) const
189
186
{ return PropValPairs.cend (); }
190
- bool HasTest () { return Test != nullptr ;}
191
- bool GetTestResult () { return Test->Evaluate (); }
187
+ bool HasTest () const noexcept { return Test != nullptr ; }
188
+ bool GetTestResult () const { return Test->Evaluate (); }
192
189
193
190
private:
194
- FGCondition* Test;
195
- std::vector <PropValPair* > PropValPairs;
191
+ std::unique_ptr< FGCondition> Test;
192
+ vector_of_unique_ptr <PropValPair> PropValPairs;
196
193
};
197
194
198
- std::vector <Case* > Cases;
195
+ vector_of_unique_ptr <Case> Cases;
199
196
200
197
void Debug (int from) override ;
201
198
};
0 commit comments