Commit a4b2314b authored by Dennis Jenkins's avatar Dennis Jenkins

Initialize class members (-Weffc++ findings).

parent 308880d2
...@@ -138,6 +138,12 @@ private: ...@@ -138,6 +138,12 @@ private:
class ConnectionPool { class ConnectionPool {
public: public:
ConnectionPool()
: connsLock()
, conns()
, maxConnectionsPerHost()
{ }
void init(size_t maxConnsPerHost); void init(size_t maxConnsPerHost);
std::shared_ptr<Connection> pickConnection(const std::string& domain); std::shared_ptr<Connection> pickConnection(const std::string& domain);
......
...@@ -118,7 +118,9 @@ class Allow : public Header { ...@@ -118,7 +118,9 @@ class Allow : public Header {
public: public:
NAME("Allow"); NAME("Allow");
Allow() { } Allow()
: methods_()
{ }
explicit Allow(const std::vector<Http::Method>& methods) explicit Allow(const std::vector<Http::Method>& methods)
: methods_(methods) : methods_(methods)
...@@ -128,6 +130,7 @@ public: ...@@ -128,6 +130,7 @@ public:
{ } { }
explicit Allow(Http::Method method) explicit Allow(Http::Method method)
: methods_()
{ {
methods_.push_back(method); methods_.push_back(method);
} }
...@@ -149,7 +152,9 @@ class Accept : public Header { ...@@ -149,7 +152,9 @@ class Accept : public Header {
public: public:
NAME("Accept") NAME("Accept")
Accept() { } Accept()
: mediaRange_()
{ }
void parseRaw(const char *str, size_t len); void parseRaw(const char *str, size_t len);
void write(std::ostream& os) const; void write(std::ostream& os) const;
...@@ -164,7 +169,9 @@ class AccessControlAllowOrigin : public Header { ...@@ -164,7 +169,9 @@ class AccessControlAllowOrigin : public Header {
public: public:
NAME("Access-Control-Allow-Origin") NAME("Access-Control-Allow-Origin")
AccessControlAllowOrigin() { } AccessControlAllowOrigin()
: uri_()
{ }
explicit AccessControlAllowOrigin(const char* uri) explicit AccessControlAllowOrigin(const char* uri)
: uri_(uri) : uri_(uri)
...@@ -190,7 +197,9 @@ class AccessControlAllowHeaders : public Header { ...@@ -190,7 +197,9 @@ class AccessControlAllowHeaders : public Header {
public: public:
NAME("Access-Control-Allow-Headers") NAME("Access-Control-Allow-Headers")
AccessControlAllowHeaders() { } AccessControlAllowHeaders()
: val_()
{ }
explicit AccessControlAllowHeaders(const char* val) explicit AccessControlAllowHeaders(const char* val)
: val_(val) : val_(val)
...@@ -216,7 +225,10 @@ class CacheControl : public Header { ...@@ -216,7 +225,10 @@ class CacheControl : public Header {
public: public:
NAME("Cache-Control") NAME("Cache-Control")
CacheControl() { } CacheControl()
: directives_()
{ }
explicit CacheControl(const std::vector<Http::CacheDirective>& directives) explicit CacheControl(const std::vector<Http::CacheDirective>& directives)
: directives_(directives) : directives_(directives)
{ } { }
...@@ -258,6 +270,10 @@ private: ...@@ -258,6 +270,10 @@ private:
class EncodingHeader : public Header { class EncodingHeader : public Header {
public: public:
EncodingHeader()
: encoding_()
{ }
void parseRaw(const char* str, size_t len); void parseRaw(const char* str, size_t len);
void write(std::ostream& os) const; void write(std::ostream& os) const;
...@@ -325,10 +341,12 @@ class ContentType : public Header { ...@@ -325,10 +341,12 @@ class ContentType : public Header {
public: public:
NAME("Content-Type") NAME("Content-Type")
ContentType() { } ContentType()
: mime_()
{ }
explicit ContentType(const Mime::MediaType& mime) : explicit ContentType(const Mime::MediaType& mime)
mime_(mime) : mime_(mime)
{ } { }
void parseRaw(const char* str, size_t len); void parseRaw(const char* str, size_t len);
...@@ -346,10 +364,12 @@ class Date : public Header { ...@@ -346,10 +364,12 @@ class Date : public Header {
public: public:
NAME("Date") NAME("Date")
Date() { } Date()
: fullDate_()
{ }
explicit Date(const FullDate& date) : explicit Date(const FullDate& date)
fullDate_(date) : fullDate_(date)
{ } { }
void parse(const std::string &str); void parse(const std::string &str);
...@@ -365,10 +385,12 @@ class Expect : public Header { ...@@ -365,10 +385,12 @@ class Expect : public Header {
public: public:
NAME("Expect") NAME("Expect")
Expect() { } Expect()
: expectation_()
{ }
explicit Expect(Http::Expectation expectation) : explicit Expect(Http::Expectation expectation)
expectation_(expectation) : expectation_(expectation)
{ } { }
void parseRaw(const char* str, size_t len); void parseRaw(const char* str, size_t len);
...@@ -385,6 +407,8 @@ public: ...@@ -385,6 +407,8 @@ public:
NAME("Host"); NAME("Host");
Host() Host()
: host_()
, port_(0)
{ } { }
explicit Host(const std::string& host); explicit Host(const std::string& host);
...@@ -408,7 +432,9 @@ class Location : public Header { ...@@ -408,7 +432,9 @@ class Location : public Header {
public: public:
NAME("Location") NAME("Location")
Location() { } Location()
: location_()
{ }
explicit Location(const std::string& location); explicit Location(const std::string& location);
...@@ -425,7 +451,9 @@ class Server : public Header { ...@@ -425,7 +451,9 @@ class Server : public Header {
public: public:
NAME("Server") NAME("Server")
Server() { } Server()
: tokens_()
{ }
explicit Server(const std::vector<std::string>& tokens); explicit Server(const std::vector<std::string>& tokens);
explicit Server(const std::string& token); explicit Server(const std::string& token);
...@@ -443,7 +471,10 @@ class UserAgent : public Header { ...@@ -443,7 +471,10 @@ class UserAgent : public Header {
public: public:
NAME("User-Agent") NAME("User-Agent")
UserAgent() { } UserAgent()
: ua_()
{ }
explicit UserAgent(const char* ua) explicit UserAgent(const char* ua)
: ua_(ua) : ua_(ua)
{ } { }
......
...@@ -341,7 +341,11 @@ public: ...@@ -341,7 +341,11 @@ public:
dequeueIndex.store(other.enqueueIndex.load(), std::memory_order_relaxed); dequeueIndex.store(other.enqueueIndex.load(), std::memory_order_relaxed);
} }
MPMCQueue() { MPMCQueue()
: cells_()
, enqueueIndex()
, dequeueIndex()
{
for (size_t i = 0; i < Size; ++i) { for (size_t i = 0; i < Size; ++i) {
cells_[i].sequence.store(i, std::memory_order_relaxed); cells_[i].sequence.store(i, std::memory_order_relaxed);
} }
...@@ -400,6 +404,10 @@ public: ...@@ -400,6 +404,10 @@ public:
private: private:
struct Cell { struct Cell {
Cell()
: sequence()
, data()
{ }
std::atomic<size_t> sequence; std::atomic<size_t> sequence;
T data; T data;
}; };
......
...@@ -89,6 +89,7 @@ public: ...@@ -89,6 +89,7 @@ public:
typedef uint16_t Type; typedef uint16_t Type;
explicit Q(Type val) explicit Q(Type val)
: val_()
{ {
if (val > 100) { if (val > 100) {
throw std::runtime_error("Invalid quality value, must be in the [0; 100] range"); throw std::runtime_error("Invalid quality value, must be in the [0; 100] range");
...@@ -123,12 +124,22 @@ public: ...@@ -123,12 +124,22 @@ public:
: top_(Type::None) : top_(Type::None)
, sub_(Subtype::None) , sub_(Subtype::None)
, suffix_(Suffix::None) , suffix_(Suffix::None)
, raw_()
, rawSubIndex()
, rawSuffixIndex()
, params()
, q_()
{ } { }
MediaType(std::string raw, Parse parse = DontParse) MediaType(std::string raw, Parse parse = DontParse)
: top_(Type::None) : top_(Type::None)
, sub_(Subtype::None) , sub_(Subtype::None)
, suffix_(Suffix::None) , suffix_(Suffix::None)
, raw_()
, rawSubIndex()
, rawSuffixIndex()
, params()
, q_()
{ {
if (parse == DoParse) { if (parse == DoParse) {
parseRaw(raw.c_str(), raw.length()); parseRaw(raw.c_str(), raw.length());
...@@ -142,12 +153,22 @@ public: ...@@ -142,12 +153,22 @@ public:
: top_(top) : top_(top)
, sub_(sub) , sub_(sub)
, suffix_(Suffix::None) , suffix_(Suffix::None)
, raw_()
, rawSubIndex()
, rawSuffixIndex()
, params()
, q_()
{ } { }
MediaType(Mime::Type top, Mime::Subtype sub, Mime::Suffix suffix) MediaType(Mime::Type top, Mime::Subtype sub, Mime::Suffix suffix)
: top_(top) : top_(top)
, sub_(sub) , sub_(sub)
, suffix_(suffix) , suffix_(suffix)
, raw_()
, rawSubIndex()
, rawSuffixIndex()
, params()
, q_()
{ } { }
......
...@@ -29,6 +29,7 @@ namespace Aio { ...@@ -29,6 +29,7 @@ namespace Aio {
class FdSet { class FdSet {
public: public:
FdSet(std::vector<Polling::Event>&& events) FdSet(std::vector<Polling::Event>&& events)
: events_()
{ {
events_.reserve(events.size()); events_.reserve(events.size());
for (auto &&event: events) { for (auto &&event: events) {
...@@ -163,11 +164,13 @@ private: ...@@ -163,11 +164,13 @@ private:
class ExecutionContext { class ExecutionContext {
public: public:
virtual ~ExecutionContext() {}
virtual Reactor::Impl* makeImpl(Reactor* reactor) const = 0; virtual Reactor::Impl* makeImpl(Reactor* reactor) const = 0;
}; };
class SyncContext : public ExecutionContext { class SyncContext : public ExecutionContext {
public: public:
virtual ~SyncContext() {}
Reactor::Impl* makeImpl(Reactor* reactor) const override; Reactor::Impl* makeImpl(Reactor* reactor) const override;
}; };
...@@ -177,6 +180,8 @@ public: ...@@ -177,6 +180,8 @@ public:
: threads_(threads) : threads_(threads)
{ } { }
virtual ~AsyncContext() {}
Reactor::Impl* makeImpl(Reactor* reactor) const override; Reactor::Impl* makeImpl(Reactor* reactor) const override;
static AsyncContext singleThreaded(); static AsyncContext singleThreaded();
...@@ -200,6 +205,10 @@ public: ...@@ -200,6 +205,10 @@ public:
struct Context { struct Context {
friend class SyncImpl; friend class SyncImpl;
Context()
: tid()
{ }
std::thread::id thread() const { return tid; } std::thread::id thread() const { return tid; }
private: private:
......
...@@ -758,9 +758,13 @@ Client::Options::maxConnectionsPerHost(int val) { ...@@ -758,9 +758,13 @@ Client::Options::maxConnectionsPerHost(int val) {
Client::Client() Client::Client()
: reactor_(Aio::Reactor::create()) : reactor_(Aio::Reactor::create())
, pool()
, transport_()
, transportKey()
, ioIndex(0) , ioIndex(0)
{ , queuesLock()
} , requestsQueues()
{ }
Client::~Client() { Client::~Client() {
} }
......
...@@ -41,11 +41,15 @@ namespace { ...@@ -41,11 +41,15 @@ namespace {
} // anonymous namespace } // anonymous namespace
CacheDirective::CacheDirective(Directive directive) CacheDirective::CacheDirective(Directive directive)
: directive_()
, data()
{ {
init(directive, std::chrono::seconds(0)); init(directive, std::chrono::seconds(0));
} }
CacheDirective::CacheDirective(Directive directive, std::chrono::seconds delta) CacheDirective::CacheDirective(Directive directive, std::chrono::seconds delta)
: directive_()
, data()
{ {
init(directive, delta); init(directive, delta);
} }
......
...@@ -331,7 +331,10 @@ Expect::write(std::ostream& os) const { ...@@ -331,7 +331,10 @@ Expect::write(std::ostream& os) const {
} }
} }
Host::Host(const std::string& data) { Host::Host(const std::string& data)
: host_()
, port_(0)
{
parse(data); parse(data);
} }
...@@ -474,11 +477,13 @@ Server::Server(const std::vector<std::string>& tokens) ...@@ -474,11 +477,13 @@ Server::Server(const std::vector<std::string>& tokens)
{ } { }
Server::Server(const std::string& token) Server::Server(const std::string& token)
: tokens_()
{ {
tokens_.push_back(token); tokens_.push_back(token);
} }
Server::Server(const char* token) Server::Server(const char* token)
: tokens_()
{ {
tokens_.emplace_back(token); tokens_.emplace_back(token);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment