Skip to content

Commit

Permalink
cpplint
Browse files Browse the repository at this point in the history
  • Loading branch information
fchn289 committed Jul 30, 2024
1 parent 9ed4237 commit caf2d9e
Show file tree
Hide file tree
Showing 54 changed files with 101 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/domino/DataDomino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "DataStore.hpp"
#include "UniLog.hpp"

namespace RLib
namespace rlib
{
// ***********************************************************************************************
template<typename aDominoType>
Expand Down
4 changes: 2 additions & 2 deletions src/domino/Domino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

using namespace std;

namespace RLib
namespace rlib
{
static const Domino::Events defaultEVs; // internal use only

Expand Down Expand Up @@ -144,7 +144,7 @@ void Domino::pureSetPrev_(const Event& aValidEv, const SimuEvents& aSimuPrevEven
// ***********************************************************************************************
bool Domino::pureSetStateOK_(const Event& aValidEv, const bool aNewState)
{
if (states_[aValidEv] != aNewState) // do need change
if (states_[aValidEv] != aNewState) // do need change
{
states_[aValidEv] = aNewState;
HID("(Domino) Succeed, EvName=" << ev_en_[aValidEv] << " newState=" << aNewState);
Expand Down
2 changes: 1 addition & 1 deletion src/domino/Domino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

#include "UniLog.hpp"

namespace RLib
namespace rlib
{
const char DOM_RESERVED_EVNAME[] = "[Dom Reserved EvName]";

Expand Down
2 changes: 1 addition & 1 deletion src/domino/FreeHdlrDomino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <vector>

namespace RLib
namespace rlib
{
// ***********************************************************************************************
template<class aDominoType>
Expand Down
3 changes: 2 additions & 1 deletion src/domino/HdlrDomino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
#pragma once

#include <functional>
#include <memory>
#include <unordered_map>

#include "MsgSelf.hpp"
#include "ObjAnywhere.hpp"
#include "SafePtr.hpp"
#include "UniLog.hpp"

namespace RLib
namespace rlib
{
// ***********************************************************************************************
template<class aDominoType>
Expand Down
5 changes: 3 additions & 2 deletions src/domino/MultiHdlrDomino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
#pragma once

#include <map>
#include <memory>
#include <string>
#include <unordered_map>

#include "UniLog.hpp"

namespace RLib
namespace rlib
{
// ***********************************************************************************************
template<class aDominoType>
Expand Down Expand Up @@ -175,7 +176,7 @@ bool MultiHdlrDomino<aDominoType>::rmOneHdlrOK_(const Domino::Event& aValidEv, c

// rm
auto&& ev_hdlrs = ev_hdlrs_S_.find(aValidEv);
//if (ev_hdlrs == ev_hdlrs_S_.end()) return false; // impossible if valid aValidHdlr
// if (ev_hdlrs == ev_hdlrs_S_.end()) return false; // impossible if valid aValidHdlr
for (auto&& name_hdlr = ev_hdlrs->second.begin(); name_hdlr != ev_hdlrs->second.end(); ++name_hdlr)
{
if (name_hdlr->second != aValidHdlr)
Expand Down
2 changes: 1 addition & 1 deletion src/domino/PriDomino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <unordered_map>
#include "UniLog.hpp"

namespace RLib
namespace rlib
{
// ***********************************************************************************************
template<class aDominoType>
Expand Down
2 changes: 1 addition & 1 deletion src/domino/RmEvDom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include <unordered_set>

namespace RLib
namespace rlib
{
// ***********************************************************************************************
template<typename aDominoType>
Expand Down
3 changes: 2 additions & 1 deletion src/domino/WbasicDatDom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
// ***********************************************************************************************
#pragma once

#include <vector>
#include "UniLog.hpp"

namespace RLib
namespace rlib
{
// ***********************************************************************************************
template<typename aDominoType>
Expand Down
4 changes: 2 additions & 2 deletions src/log/BaseSL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// ***********************************************************************************************
#pragma once

namespace RLib
namespace rlib
{
// ***********************************************************************************************
class BaseSL // SL = Smart Log
Expand All @@ -27,7 +27,7 @@ class BaseSL // SL = Smart Log

//------------------------------------------------------------------------------------------------
protected: // derive use only
virtual ~BaseSL() = default;
virtual ~BaseSL() = default;

//------------------------------------------------------------------------------------------------
private:
Expand Down
6 changes: 3 additions & 3 deletions src/log/StrCoutFSL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#pragma once

#include <iostream>
#include <sstream> //stringstream
#include <sstream> // stringstream

#include "BaseSL.hpp"

namespace RLib
namespace rlib
{
// ***********************************************************************************************
class StrCoutFSL // FSL = Formatted Smart Log
Expand All @@ -44,7 +44,7 @@ public :
inline
StrCoutFSL::~StrCoutFSL()
{
if( canDelLog() )
if (canDelLog())
return;

forceSave();
Expand Down
5 changes: 3 additions & 2 deletions src/log/UniBaseLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using LogName = std::string;

#define GTEST_LOG_FAIL { if (Test::HasFailure()) needLog(); } // UT only

namespace RLib
namespace rlib
{
// ***********************************************************************************************
// - MT safe : yes
Expand All @@ -48,7 +48,8 @@ inline const char* timestamp()

auto now_tp = std::chrono::system_clock::now();
auto now_tt = std::chrono::system_clock::to_time_t(now_tp);
strftime(buf, sizeof(buf), "%j/%T.", localtime(&now_tt));
struct tm now_tm;
strftime(buf, sizeof(buf), "%j/%T.", localtime_r(&now_tt, &now_tm)); // cpplint asks localtime_r (MT safe)
snprintf(buf + sizeof(buf) - 7, 7, "%06u", // snprintf is safer than sprintf
unsigned(std::chrono::duration_cast<std::chrono::microseconds>(now_tp.time_since_epoch()).count()
% 1'000'000));
Expand Down
2 changes: 1 addition & 1 deletion src/log/UniCoutLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace std;

namespace RLib
namespace rlib
{
// ***********************************************************************************************
ostream& UniCoutLog::oneLog()
Expand Down
2 changes: 1 addition & 1 deletion src/log/UniCoutLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "UniBaseLog.hpp"

namespace RLib
namespace rlib
{
// ***********************************************************************************************
class UniCoutLog
Expand Down
2 changes: 1 addition & 1 deletion src/log/UniLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// : : : :
// : : : :
// UniSmartLogTest.cpp UniCoutLogTest.cpp
//
//
// - REQ:
// * uni-interface (INF/...) for all users (eg DomLib, swm, rfsw)
// * easily support INF/etc macros
Expand Down
4 changes: 2 additions & 2 deletions src/log/UniSmartLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

using namespace std;

namespace RLib
namespace rlib
{
// ***********************************************************************************************
UniSmartLog::UniSmartLog(const LogName& aUniLogName) : uniLogName_(aUniLogName)
{
//for(auto&& name_log : name_log_S_) cout << name_log.first<<", p=" << name_log.second.get() << endl;
// for(auto&& name_log : name_log_S_) cout << name_log.first<<", p=" << name_log.second.get() << endl;
auto&& name_log = name_log_S_.find(aUniLogName);
if (name_log == name_log_S_.end())
{
Expand Down
2 changes: 1 addition & 1 deletion src/log/UniSmartLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "StrCoutFSL.hpp"
#include "UniBaseLog.hpp"

namespace RLib
namespace rlib
{
// ***********************************************************************************************
using SmartLog = StrCoutFSL;
Expand Down
2 changes: 1 addition & 1 deletion src/msg_self/MsgSelf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "MsgSelf.hpp"
#include "MT_PingMainTH.hpp"

namespace RLib
namespace rlib
{
// ***********************************************************************************************
// - performance optimization need 5 lines code, with a little benfit in most cases
Expand Down
5 changes: 3 additions & 2 deletions src/msg_self/MsgSelf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@
// ***********************************************************************************************
#pragma once

#include <functional>
#include <deque>
#include <functional>
#include <memory>

#include "UniLog.hpp"

#define MSG_SELF (ObjAnywhere::getObj<MsgSelf>())

namespace RLib
namespace rlib
{
// ***********************************************************************************************
enum EMsgPriority : unsigned char
Expand Down
2 changes: 1 addition & 1 deletion src/obj_anywhere/DataStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "SafePtr.hpp" // can't UniPtr.hpp since ut(=req) build-err
#include "UniLog.hpp" // debug

namespace RLib
namespace rlib
{
// ***********************************************************************************************
template<typename aDataKey>
Expand Down
3 changes: 2 additions & 1 deletion src/obj_anywhere/ObjAnywhere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
* Licensed under the BSD 3 Clause license
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <memory>
#include "ObjAnywhere.hpp"

using namespace std;

namespace RLib
namespace rlib
{
shared_ptr<DataStore<ObjName>> ObjAnywhere::name_obj_S_;

Expand Down
3 changes: 2 additions & 1 deletion src/obj_anywhere/ObjAnywhere.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
// ***********************************************************************************************
#pragma once

#include <memory>
#include <string>

#include "DataStore.hpp"
#include "UniLog.hpp"

namespace RLib
namespace rlib
{
using ObjName = std::string;

Expand Down
31 changes: 16 additions & 15 deletions src/safe_mem/SafePtr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
#include <memory>
#include <type_traits>
#include <typeindex>
#include <utility>

#include "UniLog.hpp"

namespace RLib
namespace rlib
{
// ***********************************************************************************************
template<typename T = void>
Expand Down Expand Up @@ -103,17 +104,17 @@ std::shared_ptr<To> SafePtr<T>::cast() const noexcept
{
if constexpr(std::is_base_of_v<To, T>) // safer than is_convertible()
{
//HID("(SafePtr) cast to base/self"); // ERR() not MT safe
// HID("(SafePtr) cast to base/self"); // ERR() not MT safe
return std::dynamic_pointer_cast<To>(pT_); // private/protected inherit will compile err(rare & no easy fix)
}
else if constexpr(std::is_base_of_v<T, To>) // else if for constexpr
else if constexpr(std::is_base_of_v<T, To>) // else if for constexpr
{
//HID("(SafePtr) cast to derived");
// HID("(SafePtr) cast to derived");
return std::dynamic_pointer_cast<To>(pT_);
}
else if constexpr(std::is_void_v<To>)
{
//HID("(SafePtr) cast to void (for container to store diff types)");
// HID("(SafePtr) cast to void (for container to store diff types)");
return pT_;
}
else if constexpr(!std::is_void_v<T>)
Expand All @@ -124,12 +125,12 @@ std::shared_ptr<To> SafePtr<T>::cast() const noexcept

else if (realType_ == typeid(To))
{
//HID("(SafePtr) cast void->origin");
// HID("(SafePtr) cast void->origin");
return std::static_pointer_cast<To>(pT_);
}
else if (lastType_ == typeid(To))
{
//HID("(SafePtr) cast void to last-type-except-void");
// HID("(SafePtr) cast void to last-type-except-void");
return std::static_pointer_cast<To>(pT_);
}
HID("(SafePtr) can't cast from=void/" << typeid(T).name() << " to=" << typeid(To).name());
Expand All @@ -155,9 +156,9 @@ void SafePtr<T>::init_(const SafePtr<From>& aSafeFrom) noexcept
else
lastType_ = aSafeFrom.lastType();

/*HID("cp from=" << typeid(From).name() << " to=" << typeid(T).name()
/* HID("cp from=" << typeid(From).name() << " to=" << typeid(T).name()
<< ", diff=" << (lastType_ == nullptr ? "null" : lastType_->name())
<< ", real=" << (realType_ == nullptr ? "null" : realType_->name()));*/
<< ", real=" << (realType_ == nullptr ? "null" : realType_->name())); */
}


Expand All @@ -168,7 +169,7 @@ SafePtr<U> make_safe(ConstructArgs&&... aArgs)
{
SafePtr<U> safeU;
safeU.pT_ = std::make_shared<U>(std::forward<ConstructArgs>(aArgs)...); // std::~, or ambiguous with boost::~
//HID("new ptr=" << (void*)(safeU.pT_.get())); // too many print; void* print addr rather than content(dangeous)
// HID("new ptr=" << (void*)(safeU.pT_.get())); // too many print; void* print addr rather than content(dangeous)
return safeU;
}

Expand All @@ -194,26 +195,26 @@ bool operator<(SafePtr<T> lhs, SafePtr<U> rhs)

// ***********************************************************************************************
template<typename To, typename From>
RLib::SafePtr<To> std::dynamic_pointer_cast(const RLib::SafePtr<From>& aSafeFrom) noexcept
rlib::SafePtr<To> std::dynamic_pointer_cast(const rlib::SafePtr<From>& aSafeFrom) noexcept
{
RLib::SafePtr<To> safeTo;
rlib::SafePtr<To> safeTo;
safeTo.pT_ = aSafeFrom.template cast<To>();
safeTo.init_(aSafeFrom);
return safeTo;
}

// ***********************************************************************************************
template<typename To, typename From>
RLib::SafePtr<To> std::static_pointer_cast(const RLib::SafePtr<From>& aSafeFrom) noexcept
rlib::SafePtr<To> std::static_pointer_cast(const rlib::SafePtr<From>& aSafeFrom) noexcept
{
return std::dynamic_pointer_cast<To>(aSafeFrom);
}

// ***********************************************************************************************
template<typename T>
struct std::hash<RLib::SafePtr<T>>
struct std::hash<rlib::SafePtr<T>>
{
auto operator()(const RLib::SafePtr<T>& aSafePtr) const { return hash<shared_ptr<T>>()(aSafePtr.get()); }
auto operator()(const rlib::SafePtr<T>& aSafePtr) const { return hash<shared_ptr<T>>()(aSafePtr.get()); }
};

// ***********************************************************************************************
Expand Down
Loading

0 comments on commit caf2d9e

Please sign in to comment.