aGrUM  0.14.2
nodeGraphPart_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 #ifndef DOXYGEN_SHOULD_SKIP_THIS
27 
28 // to ease parsing by IDE
30 
31 namespace gum {
32 
33  template < typename VAL >
34  INLINE NodeProperty< VAL > NodeGraphPart::nodesProperty(VAL (*f)(const NodeId&),
35  Size size) const {
36  return asNodeSet().hashMap(f, size);
37  }
38 
39  template < typename VAL >
40  INLINE NodeProperty< VAL > NodeGraphPart::nodesProperty(const VAL& val,
41  Size size) const {
42  return asNodeSet().hashMap(val, size);
43  }
44 
45  template < typename VAL >
46  INLINE List< VAL > NodeGraphPart::listMapNodes(VAL (*f)(const NodeId&)) const {
47  return asNodeSet().listMap(f);
48  }
49 
50  template < typename T >
51  void NodeGraphPart::populateNodesFromProperty(const NodeProperty< T >& h) {
52  clear();
53 
54  for (const auto iter = h.begin(); iter != h.end(); ++iter) {
55  NodeId new_one = iter.key();
56 
57  if (existsNode(new_one)) {
58  GUM_ERROR(DuplicateElement, new_one << " already exists in the graph");
59  }
60 
61  addNodeWithId(new_one);
62  }
63  }
64 
65 } /* namespace gum */
66 
67 #endif // DOXYGEN_SHOULD_SKIP_THIS
Base node set class for graphs.
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
List< VAL > listMapNodes(VAL(*f)(const NodeId &)) const
a method to create a list of VAL from a set of nodes (using for every nodee, say x, the VAL f(x))
NodeProperty< VAL > nodesProperty(VAL(*f)(const NodeId &), Size size=0) const
a method to create a HashTable with key:NodeId and value:VAL
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
HashTable< Key, NewKey, NewAlloc > hashMap(NewKey(*f)(const Key &), Size capacity=0) const
Creates a hashtable of NewKey from the set.
Definition: set_tpl.h:835
NodeSet asNodeSet() const
returns a copy of the set of nodes represented by the NodeGraphPart
void populateNodesFromProperty(const NodeProperty< T > &h)
populateNodesFromProperty clears *this and fills it with the keys of "h"
virtual void clear()
alias for clearNodes
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
List< NewKey, NewAlloc > listMap(NewKey(*f)(const Key &)) const
A method to create a List of NewKey from the set.
Definition: set_tpl.h:881
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52