aGrUM  0.14.2
internalNode.cpp
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  ***************************************************************************/
20 
30 
31 #define ALLOCATE(x) SmallObjectAllocator::instance().allocate(x)
32 #define DEALLOCATE(x, y) SmallObjectAllocator::instance().deallocate(x, y)
33 
34 namespace gum {
35 
36  // ============================================================================
37  // Constructors
38  // ============================================================================
40  GUM_CONSTRUCTOR(InternalNode);
41  __nodeVar = nullptr;
42  }
43 
45  GUM_CONSTRUCTOR(InternalNode);
46  __setNodeVar(v);
47  }
48 
50  GUM_CONSTRUCTOR(InternalNode);
51  __nodeVar = v;
52  __nodeSons = sons;
53  }
54 
55  // ============================================================================
56  // Destructors
57  // ============================================================================
59  GUM_DESTRUCTOR(InternalNode);
61  }
62 
63  // ============================================================================
64  // Allocates a table of nodeid of the size given in parameter
65  // ============================================================================
67  NodeId* sons =
68  static_cast< NodeId* >(ALLOCATE(sizeof(NodeId) * v->domainSize()));
69  for (gum::Idx i = 0; i < v->domainSize(); ++i)
70  sons[i] = 0;
71  return sons;
72  }
73 
74  // ============================================================================
75  // Deallocates a NodeSons table
76  // ============================================================================
78  DEALLOCATE(s, sizeof(NodeId) * v->domainSize());
79  }
80 
81  // ============================================================================
82  // Node handlers
83  // ============================================================================
86  __nodeVar = v;
87  __nodeSons = sons;
88  }
89 
90  // ============================================================================
91  // Var handlers
92  // ============================================================================
95  __setNodeVar(v);
96  }
97 
99  __nodeVar = v;
101  }
102 
103  // ============================================================================
104  // Parent handlers
105  // ============================================================================
106  void InternalNode::addParent(NodeId parent, Idx modality) {
107  __nodeParents.addLink(Parent(parent, modality));
108  }
109 
110  void InternalNode::removeParent(NodeId parent, Idx modality) {
111  __nodeParents.searchAndRemoveLink(Parent(parent, modality));
112  }
113 
114 } // namespace gum
115 
116 #ifdef GUM_NO_INLINE
118 #endif /* GUM_NO_INLINE */
void addParent(NodeId parent, Idx modality)
Adds a parent.
void setNode(const DiscreteVariable *v, NodeId *sons)
Allows you to respecify the node, changing its attached variable as well as its son map...
void __setNodeVar(const DiscreteVariable *v)
Set the node variable.
void removeParent(NodeId parent, Idx modality)
Removes a parent.
LinkedList< Parent > __nodeParents
The list of the node&#39;s parent.
Definition: internalNode.h:123
static NodeId * allocateNodeSons(const DiscreteVariable *v)
Allocates a table of nodeid of the size given in parameter.
Headers of the InternalNode class.
Inline implementation of the InternalNode class.
~InternalNode()
Class destructors.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
#define DEALLOCATE(x, y)
static void deallocateNodeSons(const DiscreteVariable *v, NodeId *s)
Deallocates a NodeSons table.
void setNodeVar(const DiscreteVariable *v)
Set the node variable.
#define ALLOCATE(x)
virtual Size domainSize() const =0
NodeId * __nodeSons
Table of sons of the node.
Definition: internalNode.h:120
Structure used to represent a node internal structure.
Definition: internalNode.h:100
const DiscreteVariable * __nodeVar
Variable associated to such node.
Definition: internalNode.h:103
Represent a node&#39;s parent.
Definition: internalNode.h:48
Size Idx
Type for indexes.
Definition: types.h:50
Size NodeId
Type for node ids.
Definition: graphElements.h:97
InternalNode()
Default Constructor Creates an empty node with no variable attached.