KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ranged_num.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2015 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef __RANGED_NUM_H
23#define __RANGED_NUM_H
24
25template <class T> class RANGED_NUM {
26 public:
27 RANGED_NUM( T aValue = 0, T aTolerancePlus = 0, T aToleranceMinus = 0 ) :
28 m_value( aValue ),
29 m_tolerancePlus( aTolerancePlus ),
30 m_toleranceMinus( aToleranceMinus )
31 {}
32
33 operator T()
34 {
35 return m_value;
36 }
37
38 RANGED_NUM& operator=( const T aValue )
39 {
40 m_value = aValue;
41 return *this;
42 }
43
44 bool Matches( const T& aOther ) const
45 {
46 return ( aOther >= m_value - m_toleranceMinus && aOther <= m_value + m_tolerancePlus );
47 }
48
49 private:
51};
52
53#endif
T m_toleranceMinus
Definition: ranged_num.h:50
T m_tolerancePlus
Definition: ranged_num.h:50
RANGED_NUM(T aValue=0, T aTolerancePlus=0, T aToleranceMinus=0)
Definition: ranged_num.h:27
bool Matches(const T &aOther) const
Definition: ranged_num.h:44
RANGED_NUM & operator=(const T aValue)
Definition: ranged_num.h:38