Antares Simulator
Power System Simulator
selectionoperation.h
1 /*
2  * Copyright 2007-2025, RTE (https://www.rte-france.com)
3  * See AUTHORS.txt
4  * SPDX-License-Identifier: MPL-2.0
5  * This file is part of Antares-Simulator,
6  * Adequacy and Performance assessment for interconnected energy networks.
7  *
8  * Antares_Simulator is free software: you can redistribute it and/or modify
9  * it under the terms of the Mozilla Public Licence 2.0 as published by
10  * the Mozilla Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Antares_Simulator is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * Mozilla Public Licence 2.0 for more details.
17  *
18  * You should have received a copy of the Mozilla Public Licence 2.0
19  * along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20  */
21 #ifndef __ANTARES_TOOLBOX_COMPONENT_DATAGRID_SELECTION_OPERATION_H__
22 #define __ANTARES_TOOLBOX_COMPONENT_DATAGRID_SELECTION_OPERATION_H__
23 
24 #include "wx-wrapper.h"
25 #include <math.h>
26 #include <limits>
27 
28 namespace Antares::Component::Datagrid::Selection
29 {
30 class IOperator
31 {
32 public:
33  IOperator()
34  {
35  }
36 
37  virtual ~IOperator()
38  {
39  }
40 
44  virtual const wxChar* caption() const = 0;
45 
49  virtual void reset() = 0;
50 
54  virtual void appendValue(const double v) = 0;
55 
59  virtual double result() const = 0;
60 
61 }; // class IOperator
62 
63 class Average final: public IOperator
64 {
65 public:
66  Average():
67  pValue(0.),
68  pCount(0)
69  {
70  }
71 
72  virtual ~Average()
73  {
74  }
75 
76  virtual const wxChar* caption() const
77  {
78  return wxT("Average");
79  }
80 
81  virtual void reset()
82  {
83  pValue = 0.;
84  pCount = 0;
85  }
86 
87  virtual void appendValue(const double v)
88  {
89  pValue += v;
90  ++pCount;
91  }
92 
93  virtual double result() const
94  {
95  return pValue / (double)pCount;
96  }
97 
98 private:
99  double pValue;
100  uint pCount;
101 
102 }; // class Average
103 
104 class Sum final: public IOperator
105 {
106 public:
107  Sum():
108  pValue(0.)
109  {
110  }
111 
112  virtual const wxChar* caption() const
113  {
114  return wxT("Sum");
115  }
116 
117  virtual void reset()
118  {
119  pValue = 0.;
120  }
121 
122  virtual void appendValue(const double v)
123  {
124  pValue += v;
125  }
126 
127  virtual double result() const
128  {
129  return pValue;
130  }
131 
132 private:
133  double pValue;
134 
135 }; // class Sum
136 
137 class CellCount final: public IOperator
138 {
139 public:
140  CellCount():
141  pCount(0)
142  {
143  }
144 
145  virtual const wxChar* caption() const
146  {
147  return wxT("Cell Count");
148  }
149 
150  virtual void reset()
151  {
152  pCount = 0;
153  }
154 
155  virtual void appendValue(const double)
156  {
157  ++pCount;
158  }
159 
160  virtual double result() const
161  {
162  return (double)pCount;
163  }
164 
165 private:
166  uint pCount;
167 
168 }; // class Average
169 
170 class Minimum final: public IOperator
171 {
172 public:
173  Minimum():
174  pValue(std::numeric_limits<double>::infinity())
175  {
176  }
177 
178  virtual const wxChar* caption() const
179  {
180  return wxT("Minimum");
181  }
182 
183  virtual void reset()
184  {
185  pValue = std::numeric_limits<double>::infinity();
186  }
187 
188  virtual void appendValue(const double v)
189  {
190  if (v < pValue)
191  {
192  pValue = v;
193  }
194  }
195 
196  virtual double result() const
197  {
198  return pValue;
199  }
200 
201 private:
202  double pValue;
203 
204 }; // class Sum
205 
206 class Maximum final: public IOperator
207 {
208 public:
209  Maximum():
210  pValue(-std::numeric_limits<double>::infinity())
211  {
212  }
213 
214  virtual const wxChar* caption() const
215  {
216  return wxT("Maximum");
217  }
218 
219  virtual void reset()
220  {
221  pValue = -std::numeric_limits<double>::infinity();
222  }
223 
224  virtual void appendValue(const double v)
225  {
226  if (v > pValue)
227  {
228  pValue = v;
229  }
230  }
231 
232  virtual double result() const
233  {
234  return pValue;
235  }
236 
237 private:
238  double pValue;
239 
240 }; // class Sum
241 
242 } // namespace Antares::Component::Datagrid::Selection
243 
244 #endif // __ANTARES_TOOLBOX_COMPONENT_DATAGRID_SELECTION_OPERATION_H__
Definition: selectionoperation.h:64
virtual void reset()
Reset all internal values.
Definition: selectionoperation.h:81
virtual double result() const
Get the result.
Definition: selectionoperation.h:93
virtual void appendValue(const double v)
Manage a new value.
Definition: selectionoperation.h:87
virtual const wxChar * caption() const
Caption of the operator.
Definition: selectionoperation.h:76
Definition: selectionoperation.h:138
virtual void appendValue(const double)
Manage a new value.
Definition: selectionoperation.h:155
virtual void reset()
Reset all internal values.
Definition: selectionoperation.h:150
virtual double result() const
Get the result.
Definition: selectionoperation.h:160
virtual const wxChar * caption() const
Caption of the operator.
Definition: selectionoperation.h:145
Definition: selectionoperation.h:31
virtual const wxChar * caption() const =0
Caption of the operator.
virtual void reset()=0
Reset all internal values.
virtual void appendValue(const double v)=0
Manage a new value.
virtual double result() const =0
Get the result.
Definition: selectionoperation.h:207
virtual double result() const
Get the result.
Definition: selectionoperation.h:232
virtual void reset()
Reset all internal values.
Definition: selectionoperation.h:219
virtual void appendValue(const double v)
Manage a new value.
Definition: selectionoperation.h:224
virtual const wxChar * caption() const
Caption of the operator.
Definition: selectionoperation.h:214
Definition: selectionoperation.h:171
virtual void reset()
Reset all internal values.
Definition: selectionoperation.h:183
virtual void appendValue(const double v)
Manage a new value.
Definition: selectionoperation.h:188
virtual const wxChar * caption() const
Caption of the operator.
Definition: selectionoperation.h:178
virtual double result() const
Get the result.
Definition: selectionoperation.h:196
Definition: selectionoperation.h:105
virtual double result() const
Get the result.
Definition: selectionoperation.h:127
virtual void appendValue(const double v)
Manage a new value.
Definition: selectionoperation.h:122
virtual const wxChar * caption() const
Caption of the operator.
Definition: selectionoperation.h:112
virtual void reset()
Reset all internal values.
Definition: selectionoperation.h:117