Fix warnings produced with -Weffc++ in fairmq, base/MQ and Tutorial3.

Remaining warnings originate from boost::msm and boost::mpl.
Also, warnings with missing initializer list entries for DeviceOptions are false positives, since those are PODs.
This commit is contained in:
Alexey Rybalchenko 2015-01-02 14:04:33 +01:00 committed by Florian Uhlig
parent a8854d36ac
commit ce58ee2302
36 changed files with 116 additions and 50 deletions

View File

@ -17,7 +17,7 @@
#include <string>
using std::string;
using namespace std;
class FairMQConfigurable
{

View File

@ -19,9 +19,22 @@
#include "FairMQLogger.h"
FairMQDevice::FairMQDevice()
: fNumIoThreads(1)
: fId()
, fNumIoThreads(1)
, fNumInputs(0)
, fNumOutputs(0)
, fInputAddress()
, fInputMethod()
, fInputSocketType()
, fInputSndBufSize()
, fInputRcvBufSize()
, fLogInputRate()
, fOutputAddress()
, fOutputMethod()
, fOutputSocketType()
, fOutputSndBufSize()
, fOutputRcvBufSize()
, fLogOutputRate()
, fPayloadInputs(new vector<FairMQSocket*>())
, fPayloadOutputs(new vector<FairMQSocket*>())
, fLogIntervalInMs(1000)
@ -78,7 +91,7 @@ void FairMQDevice::InitInput()
fPayloadInputs->at(i)->Connect(fInputAddress.at(i));
}
}
catch (std::out_of_range& e)
catch (out_of_range& e)
{
LOG(ERROR) << e.what();
}
@ -109,7 +122,7 @@ void FairMQDevice::InitOutput()
fPayloadOutputs->at(i)->Connect(fOutputAddress.at(i));
}
}
catch (std::out_of_range& e)
catch (out_of_range& e)
{
LOG(ERROR) << e.what();
}

View File

@ -24,10 +24,7 @@
#include "FairMQTransportFactory.h"
#include "FairMQSocket.h"
using std::vector;
using std::cin;
using std::cout;
using std::endl;
using namespace std;
class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable
{
@ -92,8 +89,6 @@ class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable
vector<FairMQSocket*>* fPayloadInputs;
vector<FairMQSocket*>* fPayloadOutputs;
FairMQSocket* fCommandSocket;
int fLogIntervalInMs;
FairMQTransportFactory* fTransportFactory;
@ -106,6 +101,11 @@ class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable
virtual void InitInput();
virtual void Terminate();
private:
/// Copy Constructor
FairMQDevice(const FairMQDevice&);
FairMQDevice operator=(const FairMQDevice&);
};
#endif /* FAIRMQDEVICE_H_ */

View File

@ -17,11 +17,8 @@
#include "FairMQLogger.h"
using std::string;
using std::cout;
using std::endl;
FairMQLogger::FairMQLogger()
: os()
{
}
@ -30,7 +27,7 @@ FairMQLogger::~FairMQLogger()
cout << os.str() << endl;
}
std::ostringstream& FairMQLogger::Log(int type)
ostringstream& FairMQLogger::Log(int type)
{
string type_str;
switch (type)
@ -56,10 +53,10 @@ std::ostringstream& FairMQLogger::Log(int type)
timestamp_t tm = get_timestamp();
timestamp_t ms = tm / 1000.0L;
timestamp_t s = ms / 1000.0L;
std::time_t t = s;
// std::size_t fractional_seconds = ms % 1000;
time_t t = s;
// size_t fractional_seconds = ms % 1000;
char mbstr[100];
std::strftime(mbstr, 100, "%H:%M:%S", std::localtime(&t));
strftime(mbstr, 100, "%H:%M:%S", localtime(&t));
os << "[\033[01;36m" << mbstr << "\033[0m]"
<< "[" << type_str << "]"

View File

@ -21,7 +21,7 @@
#include <iomanip>
#include <ctime>
using std::ostringstream;
using namespace std;
class FairMQLogger
{

View File

@ -18,8 +18,7 @@
#include <string>
#include "FairMQMessage.h"
using std::string;
using std::stringstream;
using namespace std;
class FairMQSocket
{

View File

@ -17,6 +17,8 @@
FairMQStateMachine::FairMQStateMachine()
: fRunningFinished(false)
, fRunningCondition()
, fRunningMutex()
{
start();
}
@ -59,6 +61,4 @@ void FairMQStateMachine::ChangeState(int event)
{
LOG(ERROR) << e.what();
}
}
}

View File

@ -47,6 +47,14 @@ namespace FairMQFSM
// defining the boost MSM state machine
struct FairMQFSM_ : public msm::front::state_machine_def<FairMQFSM_>
{
FairMQFSM_()
: fState()
, fRunningStateThread()
{}
// Destructor
virtual ~FairMQFSM_() {};
template <class Event, class FSM>
void on_entry(Event const&, FSM&)
{
@ -109,7 +117,7 @@ namespace FairMQFSM
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
{
fsm.fState = RUNNING;
fsm.running_state = boost::thread(boost::bind(&FairMQFSM_::Run, &fsm));
fsm.fRunningStateThread = boost::thread(boost::bind(&FairMQFSM_::Run, &fsm));
}
};
struct StopFct
@ -119,7 +127,7 @@ namespace FairMQFSM
{
fsm.fState = IDLE;
fsm.Terminate();
fsm.running_state.join();
fsm.fRunningStateThread.join();
}
};
struct PauseFct
@ -128,7 +136,7 @@ namespace FairMQFSM
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
{
fsm.fState = WAITING;
fsm.running_state.join();
fsm.fRunningStateThread.join();
fsm.Pause();
}
};
@ -160,10 +168,10 @@ namespace FairMQFSM
template <class FSM, class Event>
void no_transition(Event const& e, FSM&, int state)
{
LOG(STATE) << "no transition from state " << state << " on event " << typeid(e).name() << std::endl;
LOG(STATE) << "no transition from state " << state << " on event " << typeid(e).name();
}
// this is to run certain functions (e.g. Run()) as separate task
boost::thread running_state;
boost::thread fRunningStateThread;
// backward compatibility to FairMQStateMachine
enum State
{

View File

@ -22,7 +22,7 @@
#include "FairMQPoller.h"
#include "FairMQLogger.h"
using std::vector;
using namespace std;
class FairMQTransportFactory
{

View File

@ -46,6 +46,7 @@ class FairMQBenchmarkSampler : public FairMQDevice
int fEventSize;
int fEventRate;
int fEventCounter;
virtual void Init();
virtual void Run();
};

View File

@ -19,6 +19,7 @@
#include "FairMQLogger.h"
FairMQExampleClient::FairMQExampleClient()
: fText()
{
}

View File

@ -59,7 +59,7 @@ typedef struct DeviceOptions
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
{
if (_options == NULL)
throw std::runtime_error("Internal error: options' container is empty.");
throw runtime_error("Internal error: options' container is empty.");
namespace bpo = boost::program_options;
bpo::options_description desc("Options");

View File

@ -20,14 +20,19 @@
#include "FairMQMessageNN.h"
#include "FairMQLogger.h"
using namespace std;
FairMQMessageNN::FairMQMessageNN()
: fSize(0)
, fMessage(NULL)
: fMessage(NULL)
, fSize(0)
, fReceiving(false)
{
}
FairMQMessageNN::FairMQMessageNN(size_t size)
: fMessage(NULL)
, fSize(0)
, fReceiving(false)
{
fMessage = nn_allocmsg(size, 0);
if (!fMessage)
@ -45,6 +50,9 @@ FairMQMessageNN::FairMQMessageNN(size_t size)
* possible TODO: make this zero copy (will should then be as efficient as ZeroMQ).
*/
FairMQMessageNN::FairMQMessageNN(void* data, size_t size, fairmq_free_fn *ffn, void* hint)
: fMessage(NULL)
, fSize(0)
, fReceiving(false)
{
fMessage = nn_allocmsg(size, 0);
if (!fMessage)
@ -146,7 +154,7 @@ void FairMQMessageNN::Copy(FairMQMessage* msg)
{
LOG(ERROR) << "failed allocating message, reason: " << nn_strerror(errno);
}
std::memcpy(fMessage, msg->GetMessage(), size);
memcpy(fMessage, msg->GetMessage(), size);
fSize = size;
}

View File

@ -49,6 +49,10 @@ class FairMQMessageNN : public FairMQMessage
bool fReceiving;
void Clear();
/// Copy Constructor
FairMQMessageNN(const FairMQMessageNN&);
FairMQMessageNN operator=(const FairMQMessageNN&);
};
#endif /* FAIRMQMESSAGENN_H_ */

View File

@ -17,6 +17,8 @@
#include "FairMQPollerNN.h"
FairMQPollerNN::FairMQPollerNN(const vector<FairMQSocket*>& inputs)
: items()
, fNumItems()
{
fNumItems = inputs.size();
items = new nn_pollfd[fNumItems];

View File

@ -20,7 +20,7 @@
#include "FairMQPoller.h"
#include "FairMQSocket.h"
using std::vector;
using namespace std;
class FairMQPollerNN : public FairMQPoller
{
@ -36,6 +36,10 @@ class FairMQPollerNN : public FairMQPoller
private:
nn_pollfd* items;
int fNumItems;
/// Copy Constructor
FairMQPollerNN(const FairMQPollerNN&);
FairMQPollerNN operator=(const FairMQPollerNN&);
};
#endif /* FAIRMQPOLLERNN_H_ */

View File

@ -19,7 +19,9 @@
#include "FairMQLogger.h"
FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
: fBytesTx(0)
: fSocket()
, fId()
, fBytesTx(0)
, fBytesRx(0)
, fMessagesTx(0)
, fMessagesRx(0)

View File

@ -65,7 +65,7 @@ void FairMQProtoSampler::Run()
// LOG(INFO) << content->x() << " " << content->y() << " " << content->z() << " " << content->a() << " " << content->b();
}
std::string str;
string str;
p.SerializeToString(&str);
size_t size = str.length();

View File

@ -19,6 +19,8 @@
#include "FairMQDevice.h"
using namespace std;
class FairMQProtoSampler : public FairMQDevice
{
public:

View File

@ -66,7 +66,7 @@ typedef struct DeviceOptions
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
{
if (_options == NULL)
throw std::runtime_error("Internal error: options' container is empty.");
throw runtime_error("Internal error: options' container is empty.");
namespace bpo = boost::program_options;
bpo::options_description desc("Options");

View File

@ -66,7 +66,7 @@ typedef struct DeviceOptions
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
{
if (_options == NULL)
throw std::runtime_error("Internal error: options' container is empty.");
throw runtime_error("Internal error: options' container is empty.");
namespace bpo = boost::program_options;
bpo::options_description desc("Options");

View File

@ -64,7 +64,7 @@ typedef struct DeviceOptions
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
{
if (_options == NULL)
throw std::runtime_error("Internal error: options' container is empty.");
throw runtime_error("Internal error: options' container is empty.");
namespace bpo = boost::program_options;
bpo::options_description desc("Options");

View File

@ -68,7 +68,7 @@ typedef struct DeviceOptions
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
{
if (_options == NULL)
throw std::runtime_error("Internal error: options' container is empty.");
throw runtime_error("Internal error: options' container is empty.");
namespace bpo = boost::program_options;
bpo::options_description desc("Options");

View File

@ -69,7 +69,7 @@ typedef struct DeviceOptions
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
{
if (_options == NULL)
throw std::runtime_error("Internal error: options' container is empty.");
throw runtime_error("Internal error: options' container is empty.");
namespace bpo = boost::program_options;
bpo::options_description desc("Options");

View File

@ -66,7 +66,7 @@ typedef struct DeviceOptions
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
{
if (_options == NULL)
throw std::runtime_error("Internal error: options' container is empty.");
throw runtime_error("Internal error: options' container is empty.");
namespace bpo = boost::program_options;
bpo::options_description desc("Options");

View File

@ -64,7 +64,7 @@ typedef struct DeviceOptions
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
{
if (_options == NULL)
throw std::runtime_error("Internal error: options' container is empty.");
throw runtime_error("Internal error: options' container is empty.");
namespace bpo = boost::program_options;
bpo::options_description desc("Options");

View File

@ -68,7 +68,7 @@ typedef struct DeviceOptions
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
{
if (_options == NULL)
throw std::runtime_error("Internal error: options' container is empty.");
throw runtime_error("Internal error: options' container is empty.");
namespace bpo = boost::program_options;
bpo::options_description desc("Options");

View File

@ -64,7 +64,7 @@ typedef struct DeviceOptions
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
{
if (_options == NULL)
throw std::runtime_error("Internal error: options' container is empty.");
throw runtime_error("Internal error: options' container is empty.");
namespace bpo = boost::program_options;
bpo::options_description desc("Options");

View File

@ -69,7 +69,7 @@ typedef struct DeviceOptions
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
{
if (_options == NULL)
throw std::runtime_error("Internal error: options' container is empty.");
throw runtime_error("Internal error: options' container is empty.");
namespace bpo = boost::program_options;
bpo::options_description desc("Options");

View File

@ -17,6 +17,7 @@
#include <sstream>
FairMQContextZMQ::FairMQContextZMQ(int numIoThreads)
: fContext()
{
fContext = zmq_ctx_new();
if (fContext == NULL)

View File

@ -20,13 +20,20 @@
class FairMQContextZMQ
{
public:
/// Constructor
FairMQContextZMQ(int numIoThreads);
virtual ~FairMQContextZMQ();
void* GetContext();
void Close();
private:
void* fContext;
/// Copy Constructor
FairMQContextZMQ(const FairMQContextZMQ&);
FairMQContextZMQ operator=(const FairMQContextZMQ&);
};
#endif /* FAIRMQCONTEXTZMQ_H_ */

View File

@ -18,7 +18,10 @@
#include "FairMQMessageZMQ.h"
#include "FairMQLogger.h"
using namespace std;
FairMQMessageZMQ::FairMQMessageZMQ()
: fMessage()
{
int rc = zmq_msg_init(&fMessage);
if (rc != 0)
@ -28,6 +31,7 @@ FairMQMessageZMQ::FairMQMessageZMQ()
}
FairMQMessageZMQ::FairMQMessageZMQ(size_t size)
: fMessage()
{
int rc = zmq_msg_init_size(&fMessage, size);
if (rc != 0)
@ -37,6 +41,7 @@ FairMQMessageZMQ::FairMQMessageZMQ(size_t size)
}
FairMQMessageZMQ::FairMQMessageZMQ(void* data, size_t size, fairmq_free_fn *ffn, void* hint)
: fMessage()
{
int rc = zmq_msg_init_data(&fMessage, data, size, ffn ? ffn : &CleanUp, hint);
if (rc != 0)
@ -109,7 +114,7 @@ void FairMQMessageZMQ::Copy(FairMQMessage* msg)
// CloseMessage();
// size_t size = msg->GetSize();
// zmq_msg_init_size(&fMessage, size);
// std::memcpy(zmq_msg_data(&fMessage), msg->GetData(), size);
// memcpy(zmq_msg_data(&fMessage), msg->GetData(), size);
}
inline void FairMQMessageZMQ::CloseMessage()

View File

@ -18,6 +18,8 @@
#include "FairMQLogger.h"
FairMQPollerZMQ::FairMQPollerZMQ(const vector<FairMQSocket*>& inputs)
: items()
, fNumItems()
{
fNumItems = inputs.size();
items = new zmq_pollitem_t[fNumItems];

View File

@ -20,7 +20,7 @@
#include "FairMQPoller.h"
#include "FairMQSocket.h"
using std::vector;
using namespace std;
class FairMQPollerZMQ : public FairMQPoller
{
@ -36,6 +36,10 @@ class FairMQPollerZMQ : public FairMQPoller
private:
zmq_pollitem_t* items;
int fNumItems;
/// Copy Constructor
FairMQPollerZMQ(const FairMQPollerZMQ&);
FairMQPollerZMQ operator=(const FairMQPollerZMQ&);
};
#endif /* FAIRMQPOLLERZMQ_H_ */

View File

@ -20,7 +20,9 @@
boost::shared_ptr<FairMQContextZMQ> FairMQSocketZMQ::fContext = boost::shared_ptr<FairMQContextZMQ>(new FairMQContextZMQ(1));
FairMQSocketZMQ::FairMQSocketZMQ(const string& type, int num, int numIoThreads)
: fBytesTx(0)
: fSocket(NULL)
, fId()
, fBytesTx(0)
, fBytesRx(0)
, fMessagesTx(0)
, fMessagesRx(0)

View File

@ -61,6 +61,10 @@ class FairMQSocketZMQ : public FairMQSocket
unsigned long fMessagesRx;
static boost::shared_ptr<FairMQContextZMQ> fContext;
/// Copy Constructor
FairMQSocketZMQ(const FairMQSocketZMQ&);
FairMQSocketZMQ operator=(const FairMQSocketZMQ&);
};
#endif /* FAIRMQSOCKETZMQ_H_ */