Skip to content

Commit

Permalink
bnet: cleanup scope of functions and constructors
Browse files Browse the repository at this point in the history
- BnetDump(const std::string&) is private because it should only by
  used by the static Create function
- deleted not used functions
  • Loading branch information
franku committed Jul 4, 2019
1 parent 09d55ed commit 6d72b2a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
18 changes: 5 additions & 13 deletions core/src/lib/bnet_network_dump.cc
Expand Up @@ -30,18 +30,16 @@ std::unique_ptr<BnetDump> BnetDump::Create(std::string own_qualified_name)
std::unique_ptr<BnetDump> p;
return p;
} else {
std::unique_ptr<BnetDump> p(std::make_unique<BnetDump>(own_qualified_name));
// BnetDump constructor should be private
std::unique_ptr<BnetDump> p(new BnetDump(own_qualified_name));
return p;
}
}

BnetDump::BnetDump(const std::string& own_qualified_name) : BnetDump()
BnetDump::BnetDump(const std::string& own_qualified_name)
: impl_(std::make_unique<BnetDumpPrivate>())
{
impl_->own_qualified_name_ = own_qualified_name;
}

BnetDump::BnetDump() : impl_(std::make_unique<BnetDumpPrivate>())
{
impl_->OpenFile();
}

Expand All @@ -51,12 +49,6 @@ BnetDump::~BnetDump()
impl_->CloseFile();
}

bool BnetDump::IsInitialized() const { return impl_->output_file_.is_open(); }

void BnetDump::DisableLogging() { impl_->logging_disabled_ = true; }

void BnetDump::EnableLogging() { impl_->logging_disabled_ = false; }

void BnetDump::SetDestinationQualifiedName(
std::string destination_qualified_name)
{
Expand All @@ -83,7 +75,7 @@ bool BnetDump::EvaluateCommandLineArgs(const char* cmdline_optarg)

void BnetDump::DumpMessageAndStacktraceToFile(const char* ptr, int nbytes) const
{
if (!IsInitialized() || impl_->logging_disabled_) { return; }
if (!impl_->output_file_.is_open()) { return; }

impl_->SaveAndSendMessageIfNoDestinationDefined(ptr, nbytes);
impl_->DumpToFile(ptr, nbytes);
Expand Down
12 changes: 5 additions & 7 deletions core/src/lib/bnet_network_dump.h
Expand Up @@ -30,23 +30,21 @@ class BnetDump {
public:
static std::unique_ptr<BnetDump> Create(std::string own_qualified_name);
static bool EvaluateCommandLineArgs(const char* cmdline_optarg);
void SetDestinationQualifiedName(std::string destination_qualified_name);

void SetDestinationQualifiedName(std::string destination_qualified_name);
void DumpMessageAndStacktraceToFile(const char* ptr, int nbytes) const;
bool IsInitialized() const;
void DisableLogging();
void EnableLogging();

public:
BnetDump(const std::string& own_qualified_name);
~BnetDump();

BnetDump(const BnetDump& other) = delete;
BnetDump(const BnetDump&& other) = delete;
BnetDump& operator=(const BnetDump& rhs) = delete;
BnetDump& operator=(const BnetDump&& rhs) = delete;
~BnetDump();
BnetDump() = delete;

private:
BnetDump();
BnetDump(const std::string& own_qualified_name);
std::unique_ptr<BnetDumpPrivate> impl_;
};

Expand Down
1 change: 0 additions & 1 deletion core/src/lib/bnet_network_dump_private.h
Expand Up @@ -52,7 +52,6 @@ class BnetDumpPrivate {
std::string destination_qualified_name_;

std::ofstream output_file_;
bool logging_disabled_ = false;

private:
void CreateAndWriteStacktraceToBuffer();
Expand Down

0 comments on commit 6d72b2a

Please sign in to comment.