21#ifndef __ANTARES_TOOLBOX_COMPONENT_DATAGRID_MODIFIERS_HXX__
22#define __ANTARES_TOOLBOX_COMPONENT_DATAGRID_MODIFIERS_HXX__
47template<enum ModifierSet ModifierT>
48struct ModifierOperatorsData;
50template<enum ModifierSet ModifierT>
51struct ModifierOperatorsData
57struct ModifierOperatorsData<modifierValues>
70 static uint OperatorCount()
75 static const wchar_t* Name()
80 static const wchar_t* ApplyName(uint)
84 static const wchar_t* OperatorToCString(uint op)
109 static OpInputType OperatorInputType(uint op)
111 if (op == (uint)opAbs)
116 static void ApplyChanges(uint op,
const YString& value, Renderer::IRenderer*, VGridHelper* grid)
118 if (op >= (uint)opMax)
121 if ((Operator)op != opAbs && not value.to(input))
123 logs.error() <<
"The value does not seem a valid number";
126 int width = grid->GetNumberCols();
127 int height = grid->GetNumberRows();
130 switch ((Operator)op)
134 if (not Yuni::Math::Zero(input))
136 for (
int w = 0; w < width; ++w)
138 for (
int h = 0; h < height; ++h)
141 double d = grid->GetNumericValue(h, w);
142 grid->SetValue(h, w, text << (d + input));
152 for (
int w = 0; w < width; ++w)
154 for (
int h = 0; h < height; ++h)
155 grid->SetValue(h, w, text);
161 if (not Yuni::Math::Zero(input))
163 for (
int w = 0; w < width; ++w)
165 for (
int h = 0; h < height; ++h)
168 double d = grid->GetNumericValue(h, w);
169 grid->SetValue(h, w, text << (d - input));
177 if (Yuni::Math::Zero(input))
180 for (
int w = 0; w < width; ++w)
182 for (
int h = 0; h < height; ++h)
183 grid->SetValue(h, w, text);
188 if (not Yuni::Math::Equals(input, 1.))
190 for (
int w = 0; w < width; ++w)
192 for (
int h = 0; h < height; ++h)
195 double d = grid->GetNumericValue(h, w);
196 grid->SetValue(h, w, text << (d * input));
205 if (Yuni::Math::Zero(input))
207 logs.error() <<
"divide by zero. aborting.";
210 if (not Yuni::Math::Equals(input, 1.))
212 for (
int w = 0; w < width; ++w)
214 for (
int h = 0; h < height; ++h)
217 double d = grid->GetNumericValue(h, w);
218 grid->SetValue(h, w, text << (d / input));
226 for (
int w = 0; w < width; ++w)
228 for (
int h = 0; h < height; ++h)
230 double d = grid->GetNumericValue(h, w);
234 grid->SetValue(h, w, text << (-d));
247struct ModifierOperatorsData<modifierDataset>
256 static uint OperatorCount()
261 static const wchar_t* Name()
266 static const wchar_t* ApplyName(uint)
271 static const wchar_t* OperatorToCString(uint op)
273 if (op < (uint)opMax)
275 switch ((Operator)op)
278 return L
"Shift rows until";
279 case opResizeColumns:
280 return L
"Resize columns to";
288 static OpInputType OperatorInputType(uint op)
290 if (op == (uint)opShiftRows)
295 static void ApplyChanges(uint op,
296 const YString& value,
297 Renderer::IRenderer* renderer,
300 if (op >= (uint)opMax)
303 switch ((Operator)op)
308 uint month = (uint)-1;
311 value.words(
" /-.", [&](AnyString& word) ->
bool {
315 month = word.to<uint>();
316 if (month < 1 || month > 12)
318 logs.error() <<
"invalid month: got '" << word <<
"' => " << month;
323 if (not word.to(day) || day < 1 || day > 31)
325 logs.error() <<
"invalid day";
335 if (month < 12 && day < 31)
337 auto monthname = (MonthName)month;
338 if (not renderer->circularShiftRowsUntilDate(monthname, day))
339 logs.error() <<
"impossible to perform the row shifting in this dataset";
343 case opResizeColumns:
345 uint maxwidth = (uint)renderer->maxWidthResize();
346 uint newwidth = value.to<uint>();
348 if (newwidth > 0 && newwidth <= maxwidth)
350 logs.info() <<
"Resizing the matrix to " << newwidth <<
" columns";
351 renderer->resizeMatrixToXColumns(newwidth);
360 logs.error() <<
"impossible to resize the matrix";
363 logs.error() <<
"impossible to resize the matrix to 1 column";
367 <<
"impossible to resize the matrix to " << newwidth <<
" columns";
371 logs.error() <<
"impossible to resize the matrix";
381struct ModifierOperators
383 static uint OperatorCount(ModifierSet modifier)
388 return ModifierOperatorsData<modifierValues>::OperatorCount();
389 case modifierDataset:
390 return ModifierOperatorsData<modifierDataset>::OperatorCount();
397 static const wchar_t* Name(ModifierSet modifier)
402 return ModifierOperatorsData<modifierValues>::Name();
403 case modifierDataset:
404 return ModifierOperatorsData<modifierDataset>::Name();
411 static const wchar_t* ApplyName(ModifierSet modifier, uint op)
416 return ModifierOperatorsData<modifierValues>::ApplyName(op);
417 case modifierDataset:
418 return ModifierOperatorsData<modifierDataset>::ApplyName(op);
425 static const wchar_t* OperatorToCString(ModifierSet modifier, uint op)
430 return ModifierOperatorsData<modifierValues>::OperatorToCString(op);
431 case modifierDataset:
432 return ModifierOperatorsData<modifierDataset>::OperatorToCString(op);
439 static OpInputType OperatorInputType(ModifierSet modifier, uint op)
444 return ModifierOperatorsData<modifierValues>::OperatorInputType(op);
445 case modifierDataset:
446 return ModifierOperatorsData<modifierDataset>::OperatorInputType(op);
453 static void ApplyChanges(ModifierSet modifier,
455 const YString& value,
456 Renderer::IRenderer* renderer,
464 ModifierOperatorsData<modifierValues>::ApplyChanges(op, value, renderer, grid);
466 case modifierDataset:
467 ModifierOperatorsData<modifierDataset>::ApplyChanges(op, value, renderer, grid);