From: g0dil Date: Wed, 28 Apr 2010 16:01:46 +0000 (+0000) Subject: Implement senf::IGNORE and replace all casts-to-void with senf::IGNORE() calls X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=b9bc7df8121501f84f5a48e854ebaa4984a44932;p=senf.git Implement senf::IGNORE and replace all casts-to-void with senf::IGNORE() calls git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1608 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/PPI/Connectors.test.cc b/senf/PPI/Connectors.test.cc index 521f476..fe386d8 100644 --- a/senf/PPI/Connectors.test.cc +++ b/senf/PPI/Connectors.test.cc @@ -301,8 +301,8 @@ namespace { } void request() { - (void) input(); - (void) input.read(); + senf::IGNORE( input() ); + senf::IGNORE( input.read() ); } }; @@ -384,7 +384,7 @@ SENF_AUTO_UNIT_TEST(tyepdOutput) ppi::connect(source,target); ppi::init(); - (void) target.request(); + senf::IGNORE( target.request() ); BOOST_CHECK( true ); } diff --git a/senf/PPI/DiscardSink.cc b/senf/PPI/DiscardSink.cc index c7a6298..a5fc154 100644 --- a/senf/PPI/DiscardSink.cc +++ b/senf/PPI/DiscardSink.cc @@ -40,7 +40,7 @@ prefix_ senf::ppi::module::DiscardSink::DiscardSink() prefix_ void senf::ppi::module::DiscardSink::request() { - (void) input(); + senf::IGNORE( input() ); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/senf/Packets/Packet.test.cc b/senf/Packets/Packet.test.cc index 119baa7..21362e7 100644 --- a/senf/Packets/Packet.test.cc +++ b/senf/Packets/Packet.test.cc @@ -326,7 +326,7 @@ COMPILE_FAIL(invalidAnnotation) # ifdef BOOST_HAS_TYPE_TRAITS_INTRINSICS senf::Packet packet (FooPacket::create()); - (void) packet.annotation(); + senf::IGNORE( packet.annotation() ); # else # endif diff --git a/senf/Packets/bundledump.cc b/senf/Packets/bundledump.cc index e05a46d..c90f9a5 100644 --- a/senf/Packets/bundledump.cc +++ b/senf/Packets/bundledump.cc @@ -36,7 +36,7 @@ int main(int argc, char const ** argv) { // Link in logger library ... - (void) senf::log::StreamRegistry::instance(); + senf::IGNORE( senf::log::StreamRegistry::instance() ); for (int i (1); i #include #include +#include "senf/Utils/IgnoreValue.hh" //#include "FIFORunner.mpp" #define prefix_ @@ -252,32 +253,32 @@ prefix_ void senf::scheduler::detail::FIFORunner::watchdogError() static void * entries[SENF_DEBUG_BACKTRACE_NUMCALLERS]; // We don't care if the write commands below fail, we just give our best to inform the user - (void) write(1, "\n\n*** Scheduler task hanging (pid ",34); + senf::IGNORE( write(1, "\n\n*** Scheduler task hanging (pid ",34) ); static char pid[7]; ::snprintf(pid, 7, "%6d", ::getpid()); pid[6] = 0; - (void) write(1, pid, 6); - (void) write(1, "): ", 3); - (void) write(1, runningName_.c_str(), runningName_.size()); - (void) write(1, " at\n ", 3); + senf::IGNORE( write(1, pid, 6) ); + senf::IGNORE( write(1, "): ", 3) ); + senf::IGNORE( write(1, runningName_.c_str(), runningName_.size()) ); + senf::IGNORE( write(1, " at\n ", 3) ); #ifdef SENF_DEBUG unsigned nEntries( ::backtrace(entries, SENF_DEBUG_BACKTRACE_NUMCALLERS) ); for (unsigned i (0); i < nEntries; ++i) { - write(1, " 0x", 3); + senf::IGNORE( write(1, " 0x", 3) ); for (unsigned j (sizeof(void*)); j > 0; --j) { uintptr_t v ( reinterpret_cast(entries[i]) >> (8*(j-1)) ); - (void) write(1, &(hex[ (v >> 4) & 0x0f ]), 1); - (void) write(1, &(hex[ (v ) & 0x0f ]), 1); + senf::IGNORE( write(1, &(hex[ (v >> 4) & 0x0f ]), 1) ); + senf::IGNORE( write(1, &(hex[ (v ) & 0x0f ]), 1) ); } } #endif - (void) write(1, "\n", 1); + senf::IGNORE( write(1, "\n", 1) ); #ifdef SENF_DEBUG - (void) write(1, "Task was initialized at\n", 24); - (void) write(1, runningBacktrace_.c_str(), runningBacktrace_.size()); + senf::IGNORE( write(1, "Task was initialized at\n", 24) ); + senf::IGNORE( write(1, runningBacktrace_.c_str(), runningBacktrace_.size()) ); #endif - (void) write(1, "\n", 1); + senf::IGNORE( write(1, "\n", 1) ); if (watchdogAbort_) assert(false); } diff --git a/senf/Scheduler/SignalEvent.cc b/senf/Scheduler/SignalEvent.cc index 93b9bb0..140344b 100644 --- a/senf/Scheduler/SignalEvent.cc +++ b/senf/Scheduler/SignalEvent.cc @@ -29,6 +29,7 @@ // Custom includes #include #include +#include "senf/Utils/IgnoreValue.hh" //#include "SignalEvent.mpp" #define prefix_ @@ -116,7 +117,7 @@ prefix_ void senf::scheduler::detail::SignalDispatcher::sigHandler(int signal, : // The manpage says, si_signo is unused in linux so we set it here siginfo->si_signo = signal; // We can't do much on error anyway so we ignore errors here - (void) write(instance().sigPipe_[1], siginfo, sizeof(*siginfo)); + senf::IGNORE( write(instance().sigPipe_[1], siginfo, sizeof(*siginfo)) ); } prefix_ void senf::scheduler::SignalEvent::v_run() diff --git a/senf/Scheduler/TimerSource.cc b/senf/Scheduler/TimerSource.cc index 34f34c3..55d6216 100644 --- a/senf/Scheduler/TimerSource.cc +++ b/senf/Scheduler/TimerSource.cc @@ -31,6 +31,7 @@ #ifdef HAVE_TIMERFD #include #endif +#include "senf/Utils/IgnoreValue.hh" //#include "TimerSource.mpp" #define prefix_ @@ -127,8 +128,8 @@ prefix_ void senf::scheduler::detail::POSIXTimerSource::sigHandler(int, return; static char data = '\xD0'; // If the write fails there's not much we can do anyways ... - (void) write(static_cast(siginfo->si_value.sival_ptr)->timerPipe_[1], - &data, sizeof(data)); + senf::IGNORE( write(static_cast(siginfo->si_value.sival_ptr)->timerPipe_[1], + &data, sizeof(data)) ); } prefix_ void senf::scheduler::detail::POSIXTimerSource::signal(int events) @@ -136,7 +137,7 @@ prefix_ void senf::scheduler::detail::POSIXTimerSource::signal(int events) char data; // This should never fail since we are reading a single character from a signaled // filedescriptor - (void) read(timerPipe_[0], &data, sizeof(data)); + senf::IGNORE( read(timerPipe_[0], &data, sizeof(data)) ); timeoutEnabled_ = false; } @@ -253,7 +254,7 @@ prefix_ void senf::scheduler::detail::TimerFDTimerSource::signal(int events) { uint64_t expirations (0); // We ignore the return value since we ignore the value read anyways - (void) read(timerfd_, &expirations, sizeof(expirations)); + senf::IGNORE( read(timerfd_, &expirations, sizeof(expirations)) ); } prefix_ void senf::scheduler::detail::TimerFDTimerSource::reschedule() diff --git a/senf/Socket/Protocols/INet/TCPSocketHandle.test.cc b/senf/Socket/Protocols/INet/TCPSocketHandle.test.cc index ce26756..2c4f09f 100644 --- a/senf/Socket/Protocols/INet/TCPSocketHandle.test.cc +++ b/senf/Socket/Protocols/INet/TCPSocketHandle.test.cc @@ -69,7 +69,7 @@ namespace { int n = read(sock,buffer,1024); if (n == 4 && strncmp(buffer,"QUIT",4) == 0) break; - (void) write(sock,buffer,n); + senf::IGNORE( write(sock,buffer,n) ); } if (shutdown(sock, SHUT_RDWR) < 0) fail("server_v4","shutdown()"); @@ -99,7 +99,7 @@ namespace { int n = read(sock,buffer,1024); if (n == 4 && strncmp(buffer,"QUIT",4) == 0) break; - (void) write(sock,buffer,n); + senf::IGNORE( write(sock,buffer,n) ); } if (shutdown(sock, SHUT_RDWR) < 0) fail("server_v6","shutdown()"); @@ -260,7 +260,7 @@ namespace { int n = read(sock,buffer,1024); if (n == 4 && strncmp(buffer,"QUIT",4) == 0) break; - (void) write(sock,buffer,n); + senf::IGNORE( write(sock,buffer,n) ); } if (shutdown(sock, SHUT_RDWR) < 0) fail("client_v4","shutdown()"); @@ -284,7 +284,7 @@ namespace { int n = read(sock,buffer,1024); if (n == 4 && strncmp(buffer,"QUIT",4) == 0) break; - (void) write(sock,buffer,n); + senf::IGNORE( write(sock,buffer,n) ); } if (shutdown(sock, SHUT_RDWR) < 0) fail("client_v6","shutdown()"); diff --git a/senf/Socket/SocketPolicy.ct b/senf/Socket/SocketPolicy.ct index 5072d64..3abbe54 100644 --- a/senf/Socket/SocketPolicy.ct +++ b/senf/Socket/SocketPolicy.ct @@ -28,6 +28,7 @@ // Custom includes #include +#include "senf/Utils/IgnoreValue.hh" #define prefix_ ///////////////////////////////ct.p//////////////////////////////////////// @@ -43,9 +44,9 @@ checkBaseOf(SocketPolicyBase const & other) // to the corresponding (static) policy of this class. Throws // std::bad_cast on failure -# define SP_CheckPolicy(x1,x2,SomePolicy) \ - (void) dynamic_cast( \ - other.BOOST_PP_CAT(the,SomePolicy)()); +# define SP_CheckPolicy(x1,x2,SomePolicy) \ + senf::IGNORE( dynamic_cast( \ + other.BOOST_PP_CAT(the,SomePolicy)()) ); try { BOOST_PP_SEQ_FOR_EACH( SP_CheckPolicy, , SENF_SOCKET_POLICIES ) diff --git a/senf/Utils/Buffer.test.cc b/senf/Utils/Buffer.test.cc index 3a66891..196a469 100644 --- a/senf/Utils/Buffer.test.cc +++ b/senf/Utils/Buffer.test.cc @@ -28,9 +28,11 @@ // Custom includes #include "Buffer.hh" +#include "IgnoreValue.hh" #include #include +#include "senf/Utils/IgnoreValue.hh" #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// @@ -41,8 +43,8 @@ SENF_AUTO_UNIT_TEST(buffer) // Just check for compile errors, the rest can't be checked SENF_SCOPED_BUFFER(char, buf, size); - (void) buf; - + senf::IGNORE( buf ); + BOOST_CHECK( true ); } diff --git a/senf/Utils/Console/Executor.cc b/senf/Utils/Console/Executor.cc index ce2376f..e9649c4 100644 --- a/senf/Utils/Console/Executor.cc +++ b/senf/Utils/Console/Executor.cc @@ -35,6 +35,7 @@ #include #include #include "Server.hh" +#include "senf/Utils/IgnoreValue.hh" //#include "Executor.mpp" #define prefix_ @@ -68,7 +69,7 @@ prefix_ std::string senf::console::Executor::cwdPath() { if (skipping()) return ""; - (void) cwd(); // ensure, cwd is live. + senf::IGNORE( cwd() ); // ensure, cwd is live. return "/" + senf::stringJoin( senf::make_transform_range( boost::make_iterator_range(boost::next(cwd_.begin()), cwd_.end()), @@ -82,7 +83,7 @@ prefix_ void senf::console::Executor::execute(std::ostream & output, SENF_LOG(( "Executing: " << command )); if (! skipping()) - (void) cwd(); // Prune the cwd path of expired entries + senf::IGNORE( cwd() ); // Prune the cwd path of expired entries try { switch(command.builtin()) { @@ -231,7 +232,7 @@ prefix_ void senf::console::Executor::cd(ParseCommandInfo::TokensRange dir) { if (dir.size() == 1 && *dir.begin() == WordToken("-")) { cwd_.swap(oldCwd_); - (void) cwd(); // Prune any expired items + senf::IGNORE( cwd() ); // Prune any expired items } else { // We need to use a temporary so an error somewhere while traversing the dir does not cause diff --git a/senf/Utils/Console/ParsedCommand.mpp b/senf/Utils/Console/ParsedCommand.mpp index ab3caa6..a501d4a 100644 --- a/senf/Utils/Console/ParsedCommand.mpp +++ b/senf/Utils/Console/ParsedCommand.mpp @@ -40,6 +40,7 @@ #include #include #include +#include "senf/Utils/IgnoreValue.hh" // ///////////////////////////mpp.p//////////////////////////////////////// #elif BOOST_PP_IS_ITERATING // //////////////////////////////////////////// @@ -260,7 +261,7 @@ v_execute(boost::any & rv, std::ostream & os, ParseCommandInfo const & command) if ( nArgs > BOOST_PP_ITERATION() ) throw SyntaxErrorException("invalid number of arguments"); int nDefaults ( BOOST_PP_ITERATION() - nArgs ); - (void) nDefaults; + senf::IGNORE( nDefaults ); typedef typename boost::range_reverse_iterator::type riterator; @@ -302,7 +303,7 @@ v_execute(boost::any & rv, std::ostream & os, ParseCommandInfo const & command) if ( nArgs > BOOST_PP_ITERATION() ) throw SyntaxErrorException("invalid number of arguments"); int nDefaults ( BOOST_PP_ITERATION() - nArgs ); - (void) nDefaults; + senf::IGNORE( nDefaults ); typedef typename boost::range_reverse_iterator::type riterator; diff --git a/senf/Utils/Console/ParsedCommand.test.cc b/senf/Utils/Console/ParsedCommand.test.cc index 197b0ab..023ea31 100644 --- a/senf/Utils/Console/ParsedCommand.test.cc +++ b/senf/Utils/Console/ParsedCommand.test.cc @@ -193,7 +193,7 @@ SENF_AUTO_UNIT_TEST(parsedCommand) .arg( "text", default_value = "" ) ) ); - (void) cbNode; + senf::IGNORE( cbNode ); SENF_CHECK_NO_THROW( parser.parse("test/cb 111 222.4", diff --git a/senf/Utils/Console/Variables.test.cc b/senf/Utils/Console/Variables.test.cc index c93ba20..7b3c160 100644 --- a/senf/Utils/Console/Variables.test.cc +++ b/senf/Utils/Console/Variables.test.cc @@ -89,7 +89,7 @@ SENF_AUTO_UNIT_TEST(variables) .typeName("number") )); - (void) refvar; + senf::IGNORE( refvar ); dir.add("crefvar", fty::Variable(boost::cref(var)) .doc("Current blorg limit") diff --git a/senf/Utils/IgnoreValue.cti b/senf/Utils/IgnoreValue.cti new file mode 100644 index 0000000..1af4336 --- /dev/null +++ b/senf/Utils/IgnoreValue.cti @@ -0,0 +1,53 @@ +// $Id$ +// +// Copyright (C) 2010 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program 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 Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief IgnoreValue inline template implementation */ + +//#include "IgnoreValue.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +template +prefix_ void senf::IGNORE(T const &) +{} + +template +prefix_ void senf::IGNORE(T const *) +{} + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/senf/Utils/IgnoreValue.hh b/senf/Utils/IgnoreValue.hh new file mode 100644 index 0000000..8db6a75 --- /dev/null +++ b/senf/Utils/IgnoreValue.hh @@ -0,0 +1,64 @@ +// $Id$ +// +// Copyright (C) 2010 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program 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 Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief IgnoreValue public header */ + +#ifndef HH_SENF_senf_Utils_IgnoreValue_ +#define HH_SENF_senf_Utils_IgnoreValue_ 1 + +// Custom includes + +//#include "IgnoreValue.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { + + /** \brief Explicitly ignore a value + + To explicitly ingore a value (e.g. the return value of a function), pass that value to + senf::IGNORE(). This has the added benefit of silencing \em any warnings about ignored + values by g++. + */ + template + void IGNORE(T const &); + template + void IGNORE(T const *); + +} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "IgnoreValue.cci" +//#include "IgnoreValue.ct" +#include "IgnoreValue.cti" +#endif + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/senf/Utils/TypeIdValue.test.cc b/senf/Utils/TypeIdValue.test.cc index 94c5c34..94aad5d 100644 --- a/senf/Utils/TypeIdValue.test.cc +++ b/senf/Utils/TypeIdValue.test.cc @@ -28,6 +28,7 @@ // Custom includes #include "TypeIdValue.hh" +#include "IgnoreValue.hh" #include #include @@ -38,7 +39,7 @@ SENF_AUTO_UNIT_TEST(typeIdValue) { // We don't care for the ordering, just that the following compiles - (void) ( senf::typeIdValue() < senf::typeIdValue() ); + senf::IGNORE( senf::typeIdValue() < senf::typeIdValue() ); BOOST_CHECK ( senf::typeIdValue() != senf::typeIdValue() ); BOOST_CHECK ( senf::typeIdValue() == senf::typeIdValue() ); } diff --git a/senf/Utils/singleton.test.cc b/senf/Utils/singleton.test.cc index fa0dd9f..a28a5ef 100644 --- a/senf/Utils/singleton.test.cc +++ b/senf/Utils/singleton.test.cc @@ -29,6 +29,7 @@ // Custom includes #include #include "singleton.hh" +#include "IgnoreValue.hh" #include #include @@ -118,8 +119,8 @@ namespace { SENF_AUTO_UNIT_TEST(singletonAlive) { - (void) AliveTest1::instance(); - (void) AliveTest2::instance(); + senf::IGNORE( AliveTest1::instance() ); + senf::IGNORE( AliveTest2::instance() ); BOOST_CHECK( (test1Alive && !test2Alive) || (!test1Alive && test2Alive) ); BOOST_CHECK( AliveTest1::alive() );