KiCad PCB EDA Suite
hash_eda.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2017 CERN
5  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program 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  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef HASH_EDA_H_
27 #define HASH_EDA_H_
28 
32 #include <cstdlib>
33 #include <functional>
34 
35 class EDA_ITEM;
36 
40 {
41  HASH_POS = 0x01,
42 
44  REL_COORD = 0x02,
45  HASH_ROT = 0x04,
46  HASH_LAYER = 0x08,
47  HASH_NET = 0x10,
48  HASH_REF = 0x20,
49  HASH_VALUE = 0x40,
50  HASH_ALL = 0xff
51 };
52 
58 std::size_t hash_eda( const EDA_ITEM* aItem, int aFlags = HASH_FLAGS::HASH_ALL );
59 
64 static inline void hash_combine( std::size_t &seed ) {}
65 
72 template< typename T, typename ... Types >
73 static inline void hash_combine( std::size_t &seed, const T &val, const Types &... args )
74 {
75  seed ^= std::hash<T>()( val ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
76  hash_combine( seed, args... );
77 }
78 
79 template <typename... Types>
80 static inline std::size_t hash_val( const Types &... args )
81 {
82  std::size_t seed = 0xa82de1c0;
83  hash_combine( seed, args... );
84  return seed;
85 }
86 
87 #endif
use coordinates relative to the parent object
Definition: hash_eda.h:44
static std::size_t hash_val(const Types &... args)
Definition: hash_eda.h:80
T
enum T contains all this lexer's tokens.
std::size_t hash_eda(const EDA_ITEM *aItem, int aFlags=HASH_FLAGS::HASH_ALL)
Calculates hash of an EDA_ITEM.
Definition: hash_eda.cpp:49
static void hash_combine(std::size_t &seed)
This is a dummy function to take the final case of hash_combine below.
Definition: hash_eda.h:64
HASH_FLAGS
Enables/disables properties that will be used for calculating the hash.
Definition: hash_eda.h:39
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159