@@ -48,18 +48,36 @@ struct TUnwrapYsonStructIntrusivePtr<TIntrusivePtr<T>>
48
48
49
49
// //////////////////////////////////////////////////////////////////////////////
50
50
51
+ template <class TValue >
52
+ TFieldRegistrar<TValue>& TFieldRegistrar<TValue>::Validator(TCallback<void (const TValue&, const TValue&)> validator)
53
+ {
54
+ VerifyEmptyValidator ();
55
+ Validator_ = validator;
56
+ return *this ;
57
+ }
58
+
59
+ template <class TValue >
60
+ TFieldRegistrar<TValue>& TFieldRegistrar<TValue>::Validator(TCallback<void (const TValue&)> validator)
61
+ {
62
+ VerifyEmptyValidator ();
63
+ Validator_ = BIND_NO_PROPAGATE ([validator = std::move (validator)] (const TValue& /* oldValue*/ , const TValue& newValue) {
64
+ validator (std::move (newValue));
65
+ });
66
+ return *this ;
67
+ }
68
+
51
69
template <class TValue >
52
70
TFieldRegistrar<TValue>& TFieldRegistrar<TValue>::Updater(TCallback<void (const TValue&, const TValue&)> updater)
53
71
{
54
- VerifyEmpty ();
72
+ VerifyEmptyUpdater ();
55
73
Updater_ = updater;
56
74
return *this ;
57
75
}
58
76
59
77
template <class TValue >
60
78
TFieldRegistrar<TValue>& TFieldRegistrar<TValue>::Updater(TCallback<void (const TValue&)> updater)
61
79
{
62
- VerifyEmpty ();
80
+ VerifyEmptyUpdater ();
63
81
Updater_ = BIND_NO_PROPAGATE ([updater = std::move (updater)] (const TValue& /* oldValue*/ , const TValue& newValue) {
64
82
updater (std::move (newValue));
65
83
});
@@ -90,14 +108,31 @@ TFieldRegistrar<TValue>& TFieldRegistrar<TValue>::NestedUpdater(
90
108
TUnwrappedValue,
91
109
typename NDetail::TUnwrapYsonStructIntrusivePtr<TValue>::TStruct>);
92
110
93
- VerifyEmpty ();
111
+ VerifyEmptyUpdater ();
94
112
auto configurator = configureCallback ();
95
113
Updater_ = BIND_NO_PROPAGATE ([configurator = std::move (configurator)] (const TValue& oldValue, const TValue& newValue) {
96
114
configurator.Update (oldValue, newValue);
97
115
});
98
116
return *this ;
99
117
}
100
118
119
+ template <class TValue >
120
+ void TFieldRegistrar<TValue>::DoValidate(
121
+ IYsonStructParameterPtr parameter,
122
+ TYsonStructBase* oldStruct,
123
+ TYsonStructBase* newStruct) const
124
+ {
125
+ if (!Validator_) {
126
+ return ;
127
+ }
128
+
129
+ auto typedParameter = DynamicPointerCast<TYsonStructParameter<TValue>>(parameter);
130
+ YT_VERIFY (typedParameter);
131
+ Validator_ (
132
+ typedParameter->GetValue (oldStruct),
133
+ typedParameter->GetValue (newStruct));
134
+ }
135
+
101
136
template <class TValue >
102
137
void TFieldRegistrar<TValue>::DoUpdate(
103
138
IYsonStructParameterPtr parameter,
@@ -116,7 +151,13 @@ void TFieldRegistrar<TValue>::DoUpdate(
116
151
}
117
152
118
153
template <class TValue >
119
- void TFieldRegistrar<TValue>::VerifyEmpty() const
154
+ void TFieldRegistrar<TValue>::VerifyEmptyValidator() const
155
+ {
156
+ YT_VERIFY (!Validator_);
157
+ }
158
+
159
+ template <class TValue >
160
+ void TFieldRegistrar<TValue>::VerifyEmptyUpdater() const
120
161
{
121
162
YT_VERIFY (!Updater_);
122
163
}
@@ -169,17 +210,35 @@ TSealedConfigurator<TStruct> TConfigurator<TStruct>::Seal() &&
169
210
{
170
211
return std::move (*this );
171
212
}
213
+
172
214
// //////////////////////////////////////////////////////////////////////////////
173
215
174
216
template <CYsonStructDerived TStruct>
175
217
TSealedConfigurator<TStruct>::TSealedConfigurator(TConfigurator<TStruct> configurator)
176
218
: RegisteredFields_(std::move(configurator.RegisteredFields_))
177
219
{ }
178
220
221
+ template <CYsonStructDerived TStruct>
222
+ void TSealedConfigurator<TStruct>::Validate(
223
+ TIntrusivePtr<TStruct> oldStruct,
224
+ TIntrusivePtr<TStruct> newStruct) const
225
+ {
226
+ Do (oldStruct, newStruct, &NDetail::IFieldRegistrar::DoValidate);
227
+ }
228
+
179
229
template <CYsonStructDerived TStruct>
180
230
void TSealedConfigurator<TStruct>::Update(
181
231
TIntrusivePtr<TStruct> oldStruct,
182
232
TIntrusivePtr<TStruct> newStruct) const
233
+ {
234
+ Do (oldStruct, newStruct, &NDetail::IFieldRegistrar::DoUpdate);
235
+ }
236
+
237
+ template <CYsonStructDerived TStruct>
238
+ void TSealedConfigurator<TStruct>::Do(
239
+ TIntrusivePtr<TStruct> oldStruct,
240
+ TIntrusivePtr<TStruct> newStruct,
241
+ TFieldRegistrarMethod fieldMethod) const
183
242
{
184
243
const auto * meta = oldStruct->GetMeta ();
185
244
YT_VERIFY (meta == newStruct->GetMeta ());
@@ -194,7 +253,7 @@ void TSealedConfigurator<TStruct>::Update(
194
253
if (fieldDescIter == parameterToFieldRegistrar.end ()) {
195
254
THROW_ERROR_EXCEPTION (" Field %Qv is not marked as updatable, but was changed" , name);
196
255
} else {
197
- fieldDescIter->second -> DoUpdate (parameter, oldStruct.Get (), newStruct.Get ());
256
+ (*( fieldDescIter->second ).*fieldMethod) (parameter, oldStruct.Get (), newStruct.Get ());
198
257
}
199
258
}
200
259
}
0 commit comments