KiCad PCB EDA Suite
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  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __RANGED_NUM_H
22 #define __RANGED_NUM_H
23 
24 template <class T> class RANGED_NUM {
25  public:
26  RANGED_NUM( T aValue = 0, T aTolerancePlus = 0, T aToleranceMinus = 0 ) :
27  m_value( aValue ),
28  m_tolerancePlus( aTolerancePlus ),
29  m_toleranceMinus( aToleranceMinus )
30  {}
31 
32  operator T()
33  {
34  return m_value;
35  }
36 
37  RANGED_NUM& operator=( const T aValue )
38  {
39  m_value = aValue;
40  return *this;
41  }
42 
43  bool Matches( const T& aOther ) const
44  {
45  return ( aOther >= m_value - m_toleranceMinus && aOther <= m_value + m_tolerancePlus );
46  }
47 
48  private:
50 };
51 
52 #endif
T
enum T contains all this lexer's tokens.
RANGED_NUM(T aValue=0, T aTolerancePlus=0, T aToleranceMinus=0)
Definition: ranged_num.h:26
RANGED_NUM & operator=(const T aValue)
Definition: ranged_num.h:37
T m_tolerancePlus
Definition: ranged_num.h:49
T m_toleranceMinus
Definition: ranged_num.h:49
bool Matches(const T &aOther) const
Definition: ranged_num.h:43