aGrUM  0.14.2
utils_misc.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it udnder 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  ***************************************************************************/
27 #ifndef GUM_UTILS_H
28 #define GUM_UTILS_H
29 
30 #include <cstdlib>
31 #include <iostream>
32 #include <numeric>
33 #include <utility>
34 #include <vector>
35 #include <tuple>
36 #include <string>
37 #include <type_traits>
38 
39 
40 #ifdef GUM_DEBUG_MODE
41 # define GUM_CAST dynamic_cast
42 #else
43 # define GUM_CAST static_cast
44 #endif // GUM_DEBUG_MODE
45 
46 #include <agrum/agrum.h>
47 
48 #include <agrum/core/utils_dir.h>
51 
52 namespace std {
53 
56 
65  template < typename T1, typename T2 >
66  ostream& operator<<(ostream& stream, const pair< T1, T2 >& val);
67 
75  template < typename T0, typename... T >
76  std::ostream& operator<<(std::ostream& os, const std::tuple< T0, T... >& t);
77 
78 
86  template < typename T >
87  ostream& operator<<(ostream& stream, const vector< T >& val);
88 
97  template < typename T >
98  bool hasUniqueElts(std::vector< T > const& x);
99 
101 
102 } /* namespace std */
103 
104 namespace gum {
105 
108 
122  template < typename T1, typename T2 >
123  using forbidden_type =
124  typename std::enable_if< !std::is_same< T1, T2 >::value, int >::type;
125 
129  struct NullStream : std::ostream {
130  NullStream() : std::ios(0), std::ostream(0) {}
131  };
132 
140  bool Memcmp(const void* const _in, const void* const _out, unsigned long size);
141 
145  void __atexit();
146 
151  template < typename T >
153  bool operator()(const T& t1, const T& t2) {
154  if (t1 == t2)
155  return false;
156  else if (t1 == 0)
157  return (std::abs(t2) > 1e-5);
158  else
159  return (std::abs(t2 - t1) / t1 > 1e-5);
160  }
161  };
162 
167  template < typename T >
168  struct AlmostDifferent< T* > {
169  bool operator()(const T* t1, const T* t2) { return (t1 != t2); }
170  };
171 
173 
174 } /* namespace gum */
175 
176 // Always include the template implementations
178 
179 #endif /* GUM_UTILS_H */
Template implementation for utilities for aGrUM.
bool hasUniqueElts(std::vector< T > const &x)
STL namespace.
void __atexit()
Used for debug purpose.
Definition: utils_misc.cpp:47
bool Memcmp(const void *const _in, const void *const _out, unsigned long size)
Cross-platform replacement for memcmp.
Definition: utils_misc.cpp:37
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Indicate whether two elements are (almost) different or not.
Definition: utils_misc.h:152
bool operator()(const T *t1, const T *t2)
Definition: utils_misc.h:169
ostream & operator<<(ostream &stream, const vector< T > &val)
&#39;std::cout<<&#39; operator for vectors.
typename std::enable_if< !std::is_same< T1, T2 >::value, int >::type forbidden_type
Forbidden_type<T1,T2> return the "int" type if T1 and T2 are of the same type, else nothing...
Definition: utils_misc.h:124
bool operator()(const T &t1, const T &t2)
Definition: utils_misc.h:153
Contains usefull methods to work with files and directories.
Utilities for manipulating strings.
Contains usefull methods for random stuff.
Implements a stream with the same behaviour as /dev/null.
Definition: utils_misc.h:129