Skip to content

Commit 255ccf2

Browse files
yschimkelehecka
authored andcommitted
NoopStats non copyable (#105)
* NoopStats non copyable * movable constructors etc
1 parent a0b2707 commit 255ccf2

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Stats.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,24 @@ class NoopStats : public Stats {
1919
void bytesRead(size_t bytes) override{};
2020
void frameWritten(const std::string& frameType) override{};
2121
void frameRead(const std::string& frameType) override{};
22+
23+
static NoopStats& instance(void) {
24+
static NoopStats singleton;
25+
return singleton;
26+
}
27+
28+
protected:
29+
NoopStats() = default;
30+
~NoopStats() = default;
31+
32+
private:
33+
NoopStats(const NoopStats& other) = delete; // non construction-copyable
34+
NoopStats& operator=(const NoopStats&) = delete; // non copyable
35+
NoopStats& operator=(const NoopStats&&) = delete; // non movable
36+
NoopStats(const NoopStats&&) = delete; // non construction-movable
2237
};
2338

2439
Stats& Stats::noop() {
25-
static NoopStats noop_;
26-
return noop_;
40+
return NoopStats::instance();
2741
};
2842
}

test/InlineConnection.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ InlineConnection::InlineConnection()
2020

2121
InlineConnection::~InlineConnection() {}
2222

23-
void InlineConnection::connectTo(
24-
InlineConnection& other) {
23+
void InlineConnection::connectTo(InlineConnection& other) {
2524
ASSERT_FALSE(other_);
2625
ASSERT_FALSE(other.other_);
2726
other.other_ = this;

0 commit comments

Comments
 (0)