aGrUM  0.16.0
argMaxSet_tpl.h
Go to the documentation of this file.
1 
29 #include <agrum/core/argMaxSet.h>
30 
31 
32 namespace gum {
33 
34  // ###########################################################################
35  // CNL
36  // ###########################################################################
37 
38  // ============================================================================
39  // Constructor
40  // ============================================================================
41  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
43  GUM_CONSTRUCTOR(ArgMaxSet);
44  __argMaxSeq = new Sequence< GUM_SCALAR_SEQ >();
45  }
46 
47  // ============================================================================
48  // Constructor
49  // ============================================================================
50  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
52  const GUM_SCALAR_VAL& val, const GUM_SCALAR_SEQ& elem) {
53  GUM_CONSTRUCTOR(ArgMaxSet);
54  __argMaxSeq = new Sequence< GUM_SCALAR_SEQ >();
55  __argMaxSeq->insert(elem);
56  __val = val;
57  }
58 
59  // ============================================================================
60  // Copy Constructor
61  // ============================================================================
62  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
65  GUM_CONS_CPY(ArgMaxSet);
66  __argMaxSeq = new Sequence< GUM_SCALAR_SEQ >();
67  this->operator+=(src);
68  __val = src.value();
69  }
70 
71  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
75  this->__argMaxSeq->clear();
76  this->operator+=(src);
77  __val = src.value();
78  return *this;
79  }
80 
81  // ============================================================================
82  // Destructor
83  // ============================================================================
84  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
86  GUM_DESTRUCTOR(ArgMaxSet);
87  delete __argMaxSeq;
88  }
89 
90  // ###########################################################################
91  // Operators
92  // ###########################################################################
93 
94  // ============================================================================
95  // Ajout d'un élément
96  // ============================================================================
97  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
100  operator+=(const GUM_SCALAR_SEQ& elem) {
101  __argMaxSeq->insert(elem);
102  return *this;
103  }
104 
105  // ============================================================================
106  // Use to insert the content of another set inside this one
107  // ============================================================================
108  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
112  for (auto iter = src.beginSafe(); iter != src.endSafe(); ++iter)
113  if (!__argMaxSeq->exists(*iter)) __argMaxSeq->insert(*iter);
114  return *this;
115  }
116 
117  // ============================================================================
118  // Compares two ArgMaxSet to check if they are equals
119  // ============================================================================
120  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
122  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
123  if (__val != compared.value()) return false;
124  for (auto iter = compared.beginSafe(); iter != compared.endSafe(); ++iter)
125  if (!__argMaxSeq->exists(*iter)) return false;
126  for (auto iter = this->beginSafe(); iter != this->endSafe(); ++iter)
127  if (!compared.exists(*iter)) return false;
128  return true;
129  }
130 
131 } // End of namespace gum
SequenceIteratorSafe< GUM_SCALAR_SEQ > endSafe() const
Iterator end.
Definition: argMaxSet.h:115
~ArgMaxSet()
Destructor.
Definition: argMaxSet_tpl.h:85
bool operator==(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Compares two ArgMaxSet to check if they are equals.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Class to handle efficiently argMaxSet.
Definition: argMaxSet.h:57
SequenceIteratorSafe< GUM_SCALAR_SEQ > beginSafe() const
Iterator beginning.
Definition: argMaxSet.h:108
const GUM_SCALAR_VAL & value() const
Returns the value on which comparison are made.
Definition: argMaxSet.h:185
bool exists(const GUM_SCALAR_SEQ &elem) const
Definition: argMaxSet.h:187
ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > & operator+=(const GUM_SCALAR_SEQ &elem)
Ajout d&#39;un élément.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > & operator=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &src)
Constructor.
Definition: argMaxSet_tpl.h:74
ArgMaxSet()
Constructor.
Definition: argMaxSet_tpl.h:42
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:408