-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJRangeFilter.h
80 lines (63 loc) · 3.13 KB
/
JRangeFilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//HEAD_DSCODES
/*
<DUALSPHYSICS> Copyright (c) 2020 by Dr Jose M. Dominguez et al. (see http://dual.sphysics.org/index.php/developers/).
EPHYSLAB Environmental Physics Laboratory, Universidade de Vigo, Ourense, Spain.
School of Mechanical, Aerospace and Civil Engineering, University of Manchester, Manchester, U.K.
This file is part of DualSPHysics.
DualSPHysics is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
DualSPHysics is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with DualSPHysics. If not, see <http://www.gnu.org/licenses/>.
*/
//:#############################################################################
//:# Cambios:
//:# =========
//:# - Clase creada para facilitar el filtrado de valores entre una serie de
//:# rangos. (17-12-2010)
//:# - Cambio de nombre de JFilterValues a JRangeFilter. (27-12-2013)
//:# - Los metodos GetNextValue() y GetFirstValue devuelven UINT_MAX en caso de
//:# no tener otro valor para devolver. (27-12-2013)
//:# - Permite rangos con incremento configurable Ej:(1,4-10:2,99). (02-01-2017)
//:# - Error corregido en Config(). (23-01-2017)
//:# - Nueva funcion GetValues(). (30-07-2018)
//:#############################################################################
/// \file JRangeFilter.h \brief Declares the class \ref JRangeFilter.
#ifndef _JRangeFilter_
#define _JRangeFilter_
#include "TypesDef.h"
#include "JObject.h"
#include <string>
#include <vector>
//##############################################################################
//# JRangeFilter
//##############################################################################
/// \brief Facilitates filtering values within a list.
class JRangeFilter : protected JObject
{
private:
unsigned* Ranges; ///<Stores intervals
unsigned Count; ///<Number of intervals stored in \ref Ranges.
unsigned Size; ///<Number of intervals allocated in \ref Ranges.
unsigned ValueMin,ValueMax;
byte *FastValue; ///<Array to optimise the values search.
void ResizeRanges(unsigned size);
void AddValue(unsigned v);
void AddRange(unsigned v,unsigned v2);
void AddRangeStep(unsigned v,unsigned v2,unsigned step);
void SortRanges();
void JoinRanges();
bool CheckNewValue(unsigned v)const;
public:
JRangeFilter(std::string filter="");
~JRangeFilter(){ DestructorActive=true; Reset(); }
void Reset();
void Config(std::string filter);
bool CheckValue(unsigned v)const;
unsigned GetFirstValue()const;
unsigned GetNextValue(unsigned v)const;
bool Empty()const{ return(!Count); }
std::string ToString()const;
void GetValues(std::vector<unsigned> &values)const;
};
#endif