jspace/jspace/vector_util.cpp

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 #include "vector_util.hpp"
00027 #include <iostream>
00028 #include <string.h>
00029 #include <stdio.h>
00030 
00031 
00032 namespace std {
00033   
00034   ostream & operator << (ostream & os, vector<double> const & rhs)
00035   {
00036     if ( ! rhs.empty()) {    
00037       static int const buflen(32);
00038       char buf[buflen];
00039       memset(buf, 0, sizeof(buf));
00040       for (vector<double>::const_iterator ii(rhs.begin()); ii != rhs.end(); ++ii) {
00041 
00042 #ifndef WIN32
00043 
00044   if (isinf(*ii)) {
00045     snprintf(buf, buflen-1, " inf    ");
00046   }
00047   else if (isnan(*ii)) {
00048     snprintf(buf, buflen-1, " nan    ");
00049   }
00050   else if (fabs(fmod(*ii, 1)) < 1e-6) {
00051     snprintf(buf, buflen-1, "%- 7d  ", static_cast<int>(rint(*ii)));
00052   }
00053   else {
00054     snprintf(buf, buflen-1, "% 6.4f  ", *ii);
00055   }
00056 
00057 #else
00058 
00059   sprintf_s(buf, buflen-1, "% 6.4f  ", *ii);
00060 
00061 #endif // WIN32
00062 
00063   os << buf;
00064       }
00065     }
00066     return os;
00067   }
00068   
00069 }

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