Skip to content

Commit

Permalink
Improved log library using smart pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
randaz81 committed Nov 16, 2023
1 parent b3ea632 commit 3714e48
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/libYARP_os/src/yarp/os/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ yarp::os::Log::Log(const char* file,
const char* func,
const Predicate pred,
const LogComponent& comp) :
mPriv(new yarp::os::impl::LogPrivate(file, line, func, "", 0.0, pred, comp))
mPriv(std::make_unique<yarp::os::impl::LogPrivate>(file, line, func, "", 0.0, pred, comp))
{
}

Expand All @@ -939,7 +939,7 @@ yarp::os::Log::Log(const char* file,
std::string_view id,
const Predicate pred,
const LogComponent& comp) :
mPriv(new yarp::os::impl::LogPrivate(file, line, func, id.data(), 0.0, pred, comp))
mPriv(std::make_unique<yarp::os::impl::LogPrivate>(file, line, func, id.data(), 0.0, pred, comp))
{
}

Expand All @@ -950,7 +950,7 @@ yarp::os::Log::Log(const char* file,
const double externaltime,
const Predicate pred,
const LogComponent& comp) :
mPriv(new yarp::os::impl::LogPrivate(file, line, func, "", externaltime, pred, comp))
mPriv(std::make_unique<yarp::os::impl::LogPrivate>(file, line, func, "", externaltime, pred, comp))
{
}

Expand All @@ -963,18 +963,17 @@ yarp::os::Log::Log(const char* file,
const double externaltime,
const Predicate pred,
const LogComponent& comp) :
mPriv(new yarp::os::impl::LogPrivate(file, line, func, id.data(), externaltime, pred, comp))
mPriv(std::make_unique<yarp::os::impl::LogPrivate>(file, line, func, id.data(), externaltime, pred, comp))
{
}

yarp::os::Log::Log() :
mPriv(new yarp::os::impl::LogPrivate(nullptr, 0, nullptr, nullptr, 0.0, nullptr, nullptr))
mPriv(std::make_unique<yarp::os::impl::LogPrivate>(nullptr, 0, nullptr, nullptr, 0.0, nullptr, nullptr))
{
}

yarp::os::Log::~Log()
{
delete mPriv;
}

void yarp::os::Log::do_log(yarp::os::Log::LogType type,
Expand Down
2 changes: 1 addition & 1 deletion src/libYARP_os/src/yarp/os/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class YARP_os_API Log
static NoLog nolog() { return NoLog(); }

private:
yarp::os::impl::LogPrivate* const mPriv;
std::unique_ptr<yarp::os::impl::LogPrivate> const mPriv;

friend class yarp::os::LogStream;

Expand Down

0 comments on commit 3714e48

Please sign in to comment.