SCL  1.0
Standard Control Library : Control, dynamics, physics, and simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
vector_util.hpp
Go to the documentation of this file.
1 /*
2  * Stanford Whole-Body Control Framework http://stanford-scl.sourceforge.net/
3  *
4  * Copyright (c) 2010 Stanford University. All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program. If not, see
18  * <http://www.gnu.org/licenses/>
19  */
20 
26 #ifndef JSPACE_VECTOR_UTIL_HPP
27 #define JSPACE_VECTOR_UTIL_HPP
28 
29 #include <vector>
30 #include <iosfwd>
31 #include <math.h>
32 
33 
34 namespace jspace {
35 
36 
37  template<typename container_t>
38  bool compare(container_t const & lhs, container_t const & rhs, typename container_t::value_type precision)
39  {
40  if (&lhs == &rhs) {
41  return true;
42  }
43  if (lhs.size() != rhs.size()) {
44  return false;
45  }
46  typename container_t::const_iterator il(lhs.begin());
47  typename container_t::const_iterator ir(rhs.begin());
48  typename container_t::const_iterator il_end(lhs.end());
49  for (; il != il_end; ++il, ++ir) {
50  if (fabs(*il - *ir) > precision) {
51  return false;
52  }
53  }
54  return true;
55  }
56 
57 
58  template<typename container_t>
59  void zero(container_t & vv)
60  {
61  std::fill(vv.begin(), vv.end(), 0);
62  }
63 
64 }
65 
66 namespace std {
67 
68  ostream & operator << (ostream & os, vector<double> const & rhs);
69 
70 }
71 
72 #endif // JSPACE_VECTOR_UTIL_HPP