21 #ifndef __ANTARES_TOOLBOX_COMPONENT_DATAGRID_MODIFIERS_HXX__
22 #define __ANTARES_TOOLBOX_COMPONENT_DATAGRID_MODIFIERS_HXX__
24 namespace Antares::Component::Datagrid
43 template<enum ModifierSet ModifierT>
44 struct ModifierOperatorsData;
46 template<enum ModifierSet ModifierT>
47 struct ModifierOperatorsData
53 struct ModifierOperatorsData<modifierValues>
66 static uint OperatorCount()
71 static const wchar_t* Name()
76 static const wchar_t* ApplyName(uint)
81 static const wchar_t* OperatorToCString(uint op)
106 static OpInputType OperatorInputType(uint op)
108 if (op == (uint)opAbs)
115 static void ApplyChanges(uint op,
const YString& value, Renderer::IRenderer*, VGridHelper* grid)
117 if (op >= (uint)opMax)
122 if ((Operator)op != opAbs && not value.to(input))
124 logs.error() <<
"The value does not seem a valid number";
127 int width = grid->GetNumberCols();
128 int height = grid->GetNumberRows();
131 switch ((Operator)op)
135 if (not Yuni::Math::Zero(input))
137 for (
int w = 0; w < width; ++w)
139 for (
int h = 0; h < height; ++h)
142 double d = grid->GetNumericValue(h, w);
143 grid->SetValue(h, w, text << (d + input));
153 for (
int w = 0; w < width; ++w)
155 for (
int h = 0; h < height; ++h)
157 grid->SetValue(h, w, text);
164 if (not Yuni::Math::Zero(input))
166 for (
int w = 0; w < width; ++w)
168 for (
int h = 0; h < height; ++h)
171 double d = grid->GetNumericValue(h, w);
172 grid->SetValue(h, w, text << (d - input));
180 if (Yuni::Math::Zero(input))
183 for (
int w = 0; w < width; ++w)
185 for (
int h = 0; h < height; ++h)
187 grid->SetValue(h, w, text);
193 if (not Yuni::Math::Equals(input, 1.))
195 for (
int w = 0; w < width; ++w)
197 for (
int h = 0; h < height; ++h)
200 double d = grid->GetNumericValue(h, w);
201 grid->SetValue(h, w, text << (d * input));
210 if (Yuni::Math::Zero(input))
212 logs.error() <<
"divide by zero. aborting.";
215 if (not Yuni::Math::Equals(input, 1.))
217 for (
int w = 0; w < width; ++w)
219 for (
int h = 0; h < height; ++h)
222 double d = grid->GetNumericValue(h, w);
223 grid->SetValue(h, w, text << (d / input));
231 for (
int w = 0; w < width; ++w)
233 for (
int h = 0; h < height; ++h)
235 double d = grid->GetNumericValue(h, w);
239 grid->SetValue(h, w, text << (-d));
252 struct ModifierOperatorsData<modifierDataset>
261 static uint OperatorCount()
266 static const wchar_t* Name()
271 static const wchar_t* ApplyName(uint)
276 static const wchar_t* OperatorToCString(uint op)
278 if (op < (uint)opMax)
280 switch ((Operator)op)
283 return L
"Shift rows until";
284 case opResizeColumns:
285 return L
"Resize columns to";
293 static OpInputType OperatorInputType(uint op)
295 if (op == (uint)opShiftRows)
302 static void ApplyChanges(uint op,
303 const YString& value,
304 Renderer::IRenderer* renderer,
307 if (op >= (uint)opMax)
312 switch ((Operator)op)
317 uint month = (uint)-1;
321 [&](AnyString& word) ->
bool
326 month = word.to<uint>();
327 if (month < 1 || month > 12)
330 <<
"invalid month: got '" << word <<
"' => " << month;
335 if (not word.to(day) || day < 1 || day > 31)
337 logs.error() <<
"invalid day";
347 if (month < 12 && day < 31)
349 auto monthname = (MonthName)month;
350 if (not renderer->circularShiftRowsUntilDate(monthname, day))
352 logs.error() <<
"impossible to perform the row shifting in this dataset";
357 case opResizeColumns:
359 uint maxwidth = (uint)renderer->maxWidthResize();
360 uint newwidth = value.to<uint>();
362 if (newwidth > 0 && newwidth <= maxwidth)
364 logs.info() <<
"Resizing the matrix to " << newwidth <<
" columns";
365 renderer->resizeMatrixToXColumns(newwidth);
374 logs.error() <<
"impossible to resize the matrix";
377 logs.error() <<
"impossible to resize the matrix to 1 column";
381 <<
"impossible to resize the matrix to " << newwidth <<
" columns";
386 logs.error() <<
"impossible to resize the matrix";
397 struct ModifierOperators
399 static uint OperatorCount(ModifierSet modifier)
404 return ModifierOperatorsData<modifierValues>::OperatorCount();
405 case modifierDataset:
406 return ModifierOperatorsData<modifierDataset>::OperatorCount();
413 static const wchar_t* Name(ModifierSet modifier)
418 return ModifierOperatorsData<modifierValues>::Name();
419 case modifierDataset:
420 return ModifierOperatorsData<modifierDataset>::Name();
427 static const wchar_t* ApplyName(ModifierSet modifier, uint op)
432 return ModifierOperatorsData<modifierValues>::ApplyName(op);
433 case modifierDataset:
434 return ModifierOperatorsData<modifierDataset>::ApplyName(op);
441 static const wchar_t* OperatorToCString(ModifierSet modifier, uint op)
446 return ModifierOperatorsData<modifierValues>::OperatorToCString(op);
447 case modifierDataset:
448 return ModifierOperatorsData<modifierDataset>::OperatorToCString(op);
455 static OpInputType OperatorInputType(ModifierSet modifier, uint op)
460 return ModifierOperatorsData<modifierValues>::OperatorInputType(op);
461 case modifierDataset:
462 return ModifierOperatorsData<modifierDataset>::OperatorInputType(op);
469 static void ApplyChanges(ModifierSet modifier,
471 const YString& value,
472 Renderer::IRenderer* renderer,
482 ModifierOperatorsData<modifierValues>::ApplyChanges(op, value, renderer, grid);
484 case modifierDataset:
485 ModifierOperatorsData<modifierDataset>::ApplyChanges(op, value, renderer, grid);