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-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef HASH_EDA_H_
28 #define HASH_EDA_H_
29 
34 #include <cstdlib>
35 #include <functional>
36 
37 class EDA_ITEM;
38 
42 {
43  HASH_POS = 0x01,
44 
46  REL_COORD = 0x02,
47  HASH_ROT = 0x04,
48  HASH_LAYER = 0x08,
49  HASH_NET = 0x10,
50  HASH_REF = 0x20,
51  HASH_VALUE = 0x40,
52  HASH_ALL = 0xff
53 };
54 
61 std::size_t hash_fp_item( const EDA_ITEM* aItem, int aFlags = HASH_FLAGS::HASH_ALL );
62 
67 static inline void hash_combine( std::size_t &seed ) {}
68 
76 template< typename T, typename ... Types >
77 static inline void hash_combine( std::size_t &seed, const T &val, const Types &... args )
78 {
79  seed ^= std::hash<T>()( val ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
80  hash_combine( seed, args... );
81 }
82 
83 template <typename... Types>
84 static inline std::size_t hash_val( const Types &... args )
85 {
86  std::size_t seed = 0xa82de1c0;
87  hash_combine( seed, args... );
88  return seed;
89 }
90 
91 #endif
static std::size_t hash_val(const Types &... args)
Definition: hash_eda.h:84
use coordinates relative to the parent object
Definition: hash_eda.h:43
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:67
std::size_t hash_fp_item(const EDA_ITEM *aItem, int aFlags=HASH_FLAGS::HASH_ALL)
Calculate hash of an EDA_ITEM.
Definition: hash_eda.cpp:49
HASH_FLAGS
Enables/disables properties that will be used for calculating the hash.
Definition: hash_eda.h:41
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149