jspace/jspace/vector_util.hpp

Go to the documentation of this file.
00001 /*
00002  * Stanford Whole-Body Control Framework http://stanford-wbc.sourceforge.net/
00003  *
00004  * Copyright (C) 2010 The Board of Trustees of The Leland Stanford Junior University. All rights reserved.
00005  *
00006  * This program is free software: you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public License
00008  * as published by the Free Software Foundation, either version 3 of
00009  * the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this program.  If not, see
00018  * <http://www.gnu.org/licenses/>
00019  */
00020 
00026 #ifndef JSPACE_VECTOR_UTIL_HPP
00027 #define JSPACE_VECTOR_UTIL_HPP
00028 
00029 #include <vector>
00030 #include <iosfwd>
00031 #include <math.h>
00032 
00033 
00034 namespace jspace {
00035   
00036   
00037   template<typename container_t>
00038   bool compare(container_t const & lhs, container_t const & rhs, typename container_t::value_type precision)
00039   {
00040     if (&lhs == &rhs) {
00041       return true;
00042     }
00043     if (lhs.size() != rhs.size()) {
00044       return false;
00045     }
00046     typename container_t::const_iterator il(lhs.begin());
00047     typename container_t::const_iterator ir(rhs.begin());
00048     typename container_t::const_iterator il_end(lhs.end());
00049     for (; il != il_end; ++il, ++ir) {
00050       if (fabs(*il - *ir) > precision) {
00051   return false;
00052       }
00053     }
00054     return true;
00055   }
00056   
00057   
00058   template<typename container_t>
00059   void zero(container_t & vv)
00060   {
00061     std::fill(vv.begin(), vv.end(), 0);
00062   }
00063   
00064 }
00065 
00066 namespace std {
00067   
00068   ostream & operator << (ostream & os, vector<double> const & rhs);
00069   
00070 }
00071 
00072 #endif // JSPACE_VECTOR_UTIL_HPP

Generated on Fri Aug 26 01:31:16 2011 for Stanford Whole-Body Control Framework by  doxygen 1.5.4