aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::VariableNodeMap Class Reference

Container used to map discrete variables with nodes. More...

#include <variableNodeMap.h>

+ Collaboration diagram for gum::VariableNodeMap:

Public Member Functions

Constructors / Destructors
 VariableNodeMap ()
 Default constructor. More...
 
 VariableNodeMap (const VariableNodeMap &source)
 Copy constructor Proceed a deep copy: all variables are copied but keep the same node id. More...
 
 ~VariableNodeMap ()
 Destructor. More...
 
VariableNodeMapoperator= (const VariableNodeMap &source)
 Copy operator. More...
 
Getters and setters.
const DiscreteVariableget (NodeId id) const
 Returns a discrete variable given it's node id. More...
 
NodeId get (const DiscreteVariable &var) const
 Returns a node id given it's variable. More...
 
bool exists (NodeId id) const
 Return true if id matches a node. More...
 
bool exists (const DiscreteVariable &var) const
 Return true if var matches a node. More...
 
NodeId insert (NodeId id, const DiscreteVariable &var)
 Maps id with var. More...
 
void erase (NodeId id)
 Removes a var and it's id of this mapping. The pointer is deleted. More...
 
void erase (const DiscreteVariable &var)
 Removes a var and it's id of this mapping. The pointer is deleted. More...
 
void changeName (NodeId id, const std::string &new_name)
 we allow the user to change the name of a variable More...
 
void clear ()
 removes all the associations More...
 
std::string toString () const
 friendly displays the content of the VariableNodeMap More...
 
const std::string & name (NodeId id) const
 Returns the name of a variable given its id. More...
 
const std::string & name (const DiscreteVariable &var) const
 Returns the name of a variable. More...
 
Operators.
const DiscreteVariableoperator[] (NodeId id) const
 Returns a discrete variable given it's node id. More...
 
NodeId operator[] (const DiscreteVariable &var) const
 Returns a node id given it's variable. More...
 
Accessor by name
NodeId idFromName (const std::string &name) const
 
const DiscreteVariablevariableFromName (const std::string &name) const
 

Detailed Description

Container used to map discrete variables with nodes.

Warning
VariableNodeMap ensures that every name of variable is unique in the container.

Definition at line 48 of file variableNodeMap.h.

Constructor & Destructor Documentation

◆ VariableNodeMap() [1/2]

gum::VariableNodeMap::VariableNodeMap ( )

Default constructor.

◆ VariableNodeMap() [2/2]

gum::VariableNodeMap::VariableNodeMap ( const VariableNodeMap source)

Copy constructor Proceed a deep copy: all variables are copied but keep the same node id.

◆ ~VariableNodeMap()

gum::VariableNodeMap::~VariableNodeMap ( )

Destructor.

Member Function Documentation

◆ _copy_()

void gum::VariableNodeMap::_copy_ ( const VariableNodeMap source)
private

effectively do the copy (for copy constructor or operator=)

◆ changeName()

void gum::VariableNodeMap::changeName ( NodeId  id,
const std::string &  new_name 
)

we allow the user to change the name of a variable

Exceptions
DuplicateLabelif this name already exists
NotFoundRaised if no nodes matches id.

◆ clear()

void gum::VariableNodeMap::clear ( )

removes all the associations

◆ erase() [1/2]

void gum::VariableNodeMap::erase ( NodeId  id)

Removes a var and it's id of this mapping. The pointer is deleted.

Exceptions
NotFoundRaised if no nodes matches id.

◆ erase() [2/2]

void gum::VariableNodeMap::erase ( const DiscreteVariable var)

Removes a var and it's id of this mapping. The pointer is deleted.

Exceptions
NotFoundRaised if no nodes matches id.

◆ exists() [1/2]

bool gum::VariableNodeMap::exists ( NodeId  id) const

Return true if id matches a node.

◆ exists() [2/2]

bool gum::VariableNodeMap::exists ( const DiscreteVariable var) const

Return true if var matches a node.

◆ get() [1/2]

const DiscreteVariable& gum::VariableNodeMap::get ( NodeId  id) const

Returns a discrete variable given it's node id.

Exceptions
NotFoundRaised if no nodes matches id.

◆ get() [2/2]

NodeId gum::VariableNodeMap::get ( const DiscreteVariable var) const

Returns a node id given it's variable.

Exceptions
NotFoundRaised if no nodes matches var.

◆ idFromName()

NodeId gum::VariableNodeMap::idFromName ( const std::string &  name) const
Exceptions
NotFoundif no such name exists in the graph.

◆ insert()

NodeId gum::VariableNodeMap::insert ( NodeId  id,
const DiscreteVariable var 
)

Maps id with var.

Warning
Var is added by copy.
Exceptions
DuplicateLabelif this name already exists
DuplicateElementif this id already exists
Returns
Returns id (useful in some case);

◆ name() [1/2]

const std::string& gum::VariableNodeMap::name ( NodeId  id) const

Returns the name of a variable given its id.

Parameters
idThe variable's id.
Returns
id's name.
Exceptions
NotFoundRaised if no variable matches id.

◆ name() [2/2]

const std::string& gum::VariableNodeMap::name ( const DiscreteVariable var) const

Returns the name of a variable.

Parameters
varThe variable.
Returns
var's name.
Exceptions
NotFoundRaised if var is not in this VariableNodeMap.

◆ operator=()

VariableNodeMap& gum::VariableNodeMap::operator= ( const VariableNodeMap source)

Copy operator.

◆ operator[]() [1/2]

const DiscreteVariable& gum::VariableNodeMap::operator[] ( NodeId  id) const

Returns a discrete variable given it's node id.

Exceptions
NotFoundRaised if no nodes matches id.

◆ operator[]() [2/2]

NodeId gum::VariableNodeMap::operator[] ( const DiscreteVariable var) const

Returns a node id given it's variable.

Exceptions
NotFoundRaised if no nodes matches var.

◆ toString()

std::string gum::VariableNodeMap::toString ( ) const

friendly displays the content of the VariableNodeMap

◆ variableFromName()

const DiscreteVariable& gum::VariableNodeMap::variableFromName ( const std::string &  name) const
Exceptions
NotFoundif no such name exists in the graph.

Member Data Documentation

◆ _names2nodes_

Bijection< std::string, NodeId > gum::VariableNodeMap::_names2nodes_
private

HashTable for easely find an id from a name.

Definition at line 167 of file variableNodeMap.h.

◆ _nodes2vars_

Bijection< NodeId, const DiscreteVariable* > gum::VariableNodeMap::_nodes2vars_
private

Bijection between the node's NodeIds and the variables.

Definition at line 164 of file variableNodeMap.h.


The documentation for this class was generated from the following file: