aGrUM  0.14.2
argMaxSet_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 #include <agrum/core/argMaxSet.h>
27 
28 
29 namespace gum {
30 
31  // ###########################################################################
32  // CNL
33  // ###########################################################################
34 
35  // ============================================================================
36  // Constructor
37  // ============================================================================
38  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
40  GUM_CONSTRUCTOR(ArgMaxSet);
41  __argMaxSeq = new Sequence< GUM_SCALAR_SEQ >();
42  }
43 
44  // ============================================================================
45  // Constructor
46  // ============================================================================
47  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
49  const GUM_SCALAR_VAL& val, const GUM_SCALAR_SEQ& elem) {
50  GUM_CONSTRUCTOR(ArgMaxSet);
51  __argMaxSeq = new Sequence< GUM_SCALAR_SEQ >();
52  __argMaxSeq->insert(elem);
53  __val = val;
54  }
55 
56  // ============================================================================
57  // Copy Constructor
58  // ============================================================================
59  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
62  GUM_CONS_CPY(ArgMaxSet);
63  __argMaxSeq = new Sequence< GUM_SCALAR_SEQ >();
64  this->operator+=(src);
65  __val = src.value();
66  }
67 
68  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
72  this->__argMaxSeq->clear();
73  this->operator+=(src);
74  __val = src.value();
75  return *this;
76  }
77 
78  // ============================================================================
79  // Destructor
80  // ============================================================================
81  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
83  GUM_DESTRUCTOR(ArgMaxSet);
84  delete __argMaxSeq;
85  }
86 
87  // ###########################################################################
88  // Operators
89  // ###########################################################################
90 
91  // ============================================================================
92  // Ajout d'un élément
93  // ============================================================================
94  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
97  operator+=(const GUM_SCALAR_SEQ& elem) {
98  __argMaxSeq->insert(elem);
99  return *this;
100  }
101 
102  // ============================================================================
103  // Use to insert the content of another set inside this one
104  // ============================================================================
105  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
109  for (auto iter = src.beginSafe(); iter != src.endSafe(); ++iter)
110  if (!__argMaxSeq->exists(*iter)) __argMaxSeq->insert(*iter);
111  return *this;
112  }
113 
114  // ============================================================================
115  // Compares two ArgMaxSet to check if they are equals
116  // ============================================================================
117  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
119  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
120  if (__val != compared.value()) return false;
121  for (auto iter = compared.beginSafe(); iter != compared.endSafe(); ++iter)
122  if (!__argMaxSeq->exists(*iter)) return false;
123  for (auto iter = this->beginSafe(); iter != this->endSafe(); ++iter)
124  if (!compared.exists(*iter)) return false;
125  return true;
126  }
127 
128 } // End of namespace gum
SequenceIteratorSafe< GUM_SCALAR_SEQ > endSafe() const
Iterator end.
Definition: argMaxSet.h:113
~ArgMaxSet()
Destructor.
Definition: argMaxSet_tpl.h:82
bool operator==(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Compares two ArgMaxSet to check if they are equals.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Class to handle efficiently argMaxSet.
Definition: argMaxSet.h:55
SequenceIteratorSafe< GUM_SCALAR_SEQ > beginSafe() const
Iterator beginning.
Definition: argMaxSet.h:106
const GUM_SCALAR_VAL & value() const
Returns the value on which comparison are made.
Definition: argMaxSet.h:183
bool exists(const GUM_SCALAR_SEQ &elem) const
Definition: argMaxSet.h:185
ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > & operator+=(const GUM_SCALAR_SEQ &elem)
Ajout d&#39;un élément.
Definition: argMaxSet_tpl.h:97
This files contains several function objects that are not (yet) defined in the STL.
ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > & operator=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &src)
Constructor.
Definition: argMaxSet_tpl.h:71
ArgMaxSet()
Constructor.
Definition: argMaxSet_tpl.h:39
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:405