From c69019a0d676ca11308770cb36a625f88b7dde4a Mon Sep 17 00:00:00 2001 From: Thomas Moulard <thomas.moulard@gmail.com> Date: Sat, 1 Jan 2011 18:50:40 +0100 Subject: [PATCH] Fix warnings detected by clang. --- include/dynamic-graph/contiifstream.h | 10 +- include/dynamic-graph/signal-time-dependent.h | 2 +- include/dynamic-graph/signal.t.cpp | 2 +- include/dynamic-graph/tracer-real-time.h | 6 +- src/debug/contiifstream.cpp | 143 +++++++++--------- src/plugins/shell-procedure.cpp | 21 ++- src/shell/functions.cpp | 9 +- src/traces/tracer-real-time.cpp | 24 +-- src/traces/tracer.cpp | 4 +- tests/signal-cast-registerer.cpp | 2 +- 10 files changed, 114 insertions(+), 109 deletions(-) diff --git a/include/dynamic-graph/contiifstream.h b/include/dynamic-graph/contiifstream.h index 6e91d41..013b8fd 100644 --- a/include/dynamic-graph/contiifstream.h +++ b/include/dynamic-graph/contiifstream.h @@ -33,16 +33,20 @@ namespace dynamicgraph { + /// \ingroup debug + /// + /// \brief TODO + /// class DG_CONTIIFSTREAM_DLLAPI Contiifstream { public: - explicit Contiifstream (const std::string& n=""); + explicit Contiifstream (const std::string& n = ""); ~Contiifstream (); inline void open (const std::string& n) { - filename=n; - cursor=0; + filename = n; + cursor = 0; } bool loop (); diff --git a/include/dynamic-graph/signal-time-dependent.h b/include/dynamic-graph/signal-time-dependent.h index ad71f81..f9f4b1d 100644 --- a/include/dynamic-graph/signal-time-dependent.h +++ b/include/dynamic-graph/signal-time-dependent.h @@ -96,7 +96,7 @@ namespace dynamicgraph ,std::string name ) :Signal<T,Time>(name) ,TimeDependency<Time>(this,sig) - { setFunction(t); } + { this->setFunction(t); } template< class T,class Time> const T& SignalTimeDependent<T,Time>:: diff --git a/include/dynamic-graph/signal.t.cpp b/include/dynamic-graph/signal.t.cpp index 1b9f067..6aa555e 100644 --- a/include/dynamic-graph/signal.t.cpp +++ b/include/dynamic-graph/signal.t.cpp @@ -252,7 +252,7 @@ namespace dynamicgraph if( this->getReady () ) { setReady(false); - setTime(t); + this->setTime(t); } return accessCopy (); }; diff --git a/include/dynamic-graph/tracer-real-time.h b/include/dynamic-graph/tracer-real-time.h index 4fb91bb..64f553f 100644 --- a/include/dynamic-graph/tracer-real-time.h +++ b/include/dynamic-graph/tracer-real-time.h @@ -29,8 +29,8 @@ namespace dynamicgraph { public: char* buffer; - size_t index; - size_t bufferSize; + std::streamsize index; + std::streamsize bufferSize; bool full; std::string givenname; @@ -38,7 +38,7 @@ namespace dynamicgraph OutStringStream (); ~OutStringStream (); - void resize (const unsigned int & size); + void resize (const std::streamsize& size); bool addData (const char * data, const std::streamoff& size); void dump (std::ostream& os); void empty (); diff --git a/src/debug/contiifstream.cpp b/src/debug/contiifstream.cpp index b4cd34c..ec73c71 100644 --- a/src/debug/contiifstream.cpp +++ b/src/debug/contiifstream.cpp @@ -1,80 +1,73 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. #include <dynamic-graph/contiifstream.h> #include <dynamic-graph/debug.h> -using namespace dynamicgraph; - -Contiifstream:: -Contiifstream( const std::string& n ) - :filename(n),cursor(0),first(true) {} - - -Contiifstream:: -~Contiifstream () +namespace dynamicgraph { - dgDEBUGINOUT(5); -} - - -bool Contiifstream:: -loop () -{ - dgDEBUGIN(25); - bool res=false; - - std::fstream file( filename.c_str () ); - - file.seekg(cursor); - file.sync (); - - while(1) - { - file.get(buffer,BUFFER_SIZE); - if( file.gcount () ) - { - res=true; - std::string line(buffer); - if(! first) reader.push_back(line); - cursor=file.tellg (); cursor++; - file.get(*buffer); // get the last char ( = '\n') - dgDEBUG(15) << "line: "<< line<<std::endl; - } - else { break; } - } - - first=false; - dgDEBUGOUT(25); - return res; -} - -std::string -Contiifstream::next () -{ - std::string res = *reader.begin (); - reader.pop_front (); - return res; -} - - - - - + Contiifstream::Contiifstream (const std::string& n) + : filename (n), + cursor (0), + first (true) + {} + + Contiifstream::~Contiifstream () + { + dgDEBUGINOUT(5); + } + + bool + Contiifstream::loop () + { + dgDEBUGIN(25); + + bool res = false; + std::fstream file (filename.c_str ()); + file.seekg (cursor); + file.sync (); + + while(1) + { + file.get (buffer,BUFFER_SIZE); + if (file.gcount ()) + { + res = true; + std::string line (buffer); + if (! first) + reader.push_back (line); + cursor=file.tellg (); + ++cursor; + file.get (*buffer); // get the last char ( = '\n') + dgDEBUG(15) << "line: "<< line<<std::endl; + } + else + break; + } + + first = false; + dgDEBUGOUT(25); + return res; + } + + std::string + Contiifstream::next () + { + std::string res = *reader.begin (); + reader.pop_front (); + return res; + } +} // end of namespace dynamicgraph. diff --git a/src/plugins/shell-procedure.cpp b/src/plugins/shell-procedure.cpp index 5c9a47c..38f00a1 100644 --- a/src/plugins/shell-procedure.cpp +++ b/src/plugins/shell-procedure.cpp @@ -69,12 +69,19 @@ cmdContinueProcedure( const std::string& cmdLine,std::istringstream& args,std::o args >> ws; while( args.good () ) { - std::string next; int param=-1; - args>>next>>ws; - for( unsigned int i=0;i<currentProc.params.size ();++i ) - { if( next==currentProc.params[i] ) { param=i; break; } } - ins.args.push_back(next); - ins.params.push_back( param ); + std::string next; + int param = -1; + args >> next >> ws; + for (unsigned int i = 0; i < currentProc.params.size (); ++i) + { + if (next == currentProc.params[i]) + { + param = (int) i; + break; + } + } + ins.args.push_back (next); + ins.params.push_back (param); } currentProc.instructions.push_back( ins ); @@ -198,7 +205,7 @@ cmdProcedure( const std::string& procname, { int paramArg = ins->params[i]; if( paramArg==-1 ) oss << ins->args[i] << " "; - else oss << paramValue[paramArg] << " "; + else oss << paramValue[(size_t) paramArg] << " "; } dgDEBUG(15) << " Args = " << oss.str () << endl; diff --git a/src/shell/functions.cpp b/src/shell/functions.cpp index 4bd20d2..308cfa7 100644 --- a/src/shell/functions.cpp +++ b/src/shell/functions.cpp @@ -38,7 +38,8 @@ using namespace dynamicgraph; static const char* NO_PLUGINLOADER_ERROR_MSG = "!! Dynamic loading functionalities not accessible through the shell."; -static void sleep (int secs) +static void sleep_ (unsigned int secs); +static void sleep_ (unsigned int secs) { #ifndef WIN32 usleep(secs * 1000000); @@ -541,11 +542,11 @@ ShellFunctions::cmdSleep (const std::string cmdLine, double secs = 0.; cmdArg >> secs; - typedef boost::numeric::converter<int, double> Double2Int; - int secs_ = Double2Int::convert (secs); + typedef boost::numeric::converter<unsigned int, double> Double2Int; + unsigned int secs_ = Double2Int::convert (secs); if (secs_ > 0) - sleep (secs_); + sleep_ (secs_); } void diff --git a/src/traces/tracer-real-time.cpp b/src/traces/tracer-real-time.cpp index 94beb98..a71ed46 100644 --- a/src/traces/tracer-real-time.cpp +++ b/src/traces/tracer-real-time.cpp @@ -57,7 +57,7 @@ OutStringStream:: } void OutStringStream:: -resize( const unsigned int & size ) +resize (const std::streamsize& size) { dgDEBUGIN(15); @@ -66,27 +66,27 @@ resize( const unsigned int & size ) full=false; delete[] buffer; - buffer = new char [size]; + buffer = new char[static_cast<size_t> (size)]; dgDEBUGOUT(15); } bool OutStringStream:: -addData( const char * data, const std::streamoff& size ) +addData (const char * data, const std::streamoff& size) { dgDEBUGIN(15); - size_t towrite = static_cast<size_t> (size); - if( index+towrite>bufferSize ) + std::streamsize towrite = static_cast<std::streamsize> (size); + if (index + towrite > bufferSize) { dgDEBUGOUT(15); - full=true; + full = true; return false; - }//towrite=bufferSize-index; - memcpy( buffer+index,data,towrite ); - index+=towrite; + } + memcpy (buffer + index, data, static_cast<size_t> (towrite)); + index += towrite; dgDEBUGOUT(15); return true; - } +} void OutStringStream:: dump( std::ostream& os ) @@ -321,8 +321,8 @@ display( std::ostream& os ) const if( file ) { const std::streamsize PRECISION = os.precision (); - const unsigned int SIZE = file->index; - const unsigned int MSIZE = file->bufferSize; + const std::streamsize SIZE = file->index; + const std::streamsize MSIZE = file->bufferSize; unsigned int dec=0; std::string unit =""; if( (SIZE>>30)||(MSIZE>>30) ) { dec = 30; unit="Go"; } else if( (SIZE>>20)||(MSIZE>>20) ) { dec = 20; unit="Mo"; } diff --git a/src/traces/tracer.cpp b/src/traces/tracer.cpp index dc01df8..c755759 100644 --- a/src/traces/tracer.cpp +++ b/src/traces/tracer.cpp @@ -98,8 +98,8 @@ openFiles( const std::string& rootdir_, const std::string& basename_, const std::string& suffix_ ) { dgDEBUGIN(15); - int n = rootdir_.length (); - rootdir=rootdir_; + unsigned int n = rootdir_.length (); + rootdir = rootdir_; if( (0<n)&('/'!=rootdir[n-1]) ) rootdir+='/'; basename=basename_; diff --git a/tests/signal-cast-registerer.cpp b/tests/signal-cast-registerer.cpp index eda97b1..f171ed2 100644 --- a/tests/signal-cast-registerer.cpp +++ b/tests/signal-cast-registerer.cpp @@ -142,7 +142,7 @@ BOOST_AUTO_TEST_CASE (custom_vector_registerer) BOOST_CHECK (output.is_equal ("Sig:vector (Type Cst)")); } - for (int i = 0; i < 5; ++i) + for (unsigned int i = 0; i < 5; ++i) { ublas::unit_vector<double> v (5, i); std::ostringstream os; -- GitLab