Skip to content

Commit

Permalink
using std: not hpp but cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
fchn289 committed Jul 30, 2024
1 parent f6720dd commit 02f1971
Show file tree
Hide file tree
Showing 36 changed files with 126 additions and 137 deletions.
4 changes: 1 addition & 3 deletions src/domino/DataDomino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include "DataStore.hpp"
#include "UniLog.hpp"

using namespace std;

namespace RLib
{
// ***********************************************************************************************
Expand Down Expand Up @@ -82,7 +80,7 @@ void DataDomino<aDominoType>::rmEv_(const Domino::Event& aValidEv)
template<typename aDataDominoType, typename aDataType>
auto getData(aDataDominoType& aDom, const Domino::EvName& aEvName)
{
return static_pointer_cast<aDataType>(aDom.getData(aEvName));
return std::static_pointer_cast<aDataType>(aDom.getData(aEvName));
}

// ***********************************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions src/domino/Domino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "Domino.hpp"

using namespace std;

namespace RLib
{
static const Domino::Events defaultEVs; // internal use only
Expand Down
22 changes: 11 additions & 11 deletions src/domino/Domino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class Domino : public UniLog
{
public:
using Event = size_t; // smaller size can save mem; larger size can support more events
using Events = set<Event>;
using EvName = string;
using SimuEvents = map<EvName, bool>; // not unordered-map since most traversal
using EvNames = unordered_map<Event, EvName>; // map is less mem than vector<EvName>
using EvLinks = map<Event, Events>;
using Events = std::set<Event>;
using EvName = std::string;
using SimuEvents = std::map<EvName, bool>; // not unordered-map since most traversal
using EvNames = std::unordered_map<Event, EvName>; // map is less mem than vector<EvName>
using EvLinks = std::map<Event, Events>;

enum : Event
{
Expand Down Expand Up @@ -122,13 +122,13 @@ class Domino : public UniLog
static const Events& findPeerEVs(const Event&, const EvLinks&);

// -------------------------------------------------------------------------------------------
vector<bool> states_; // bitmap & dyn expand, [event]=t/f
std::vector<bool> states_; // bitmap & dyn expand, [event]=t/f

EvLinks prev_[N_EVENT_STATE]; // not unordered-map since most traversal
EvLinks next_[N_EVENT_STATE]; // not unordered-map since most traversal
unordered_map<EvName, Event> en_ev_; // [evName]=event
EvNames ev_en_; // [event]=evName for easy debug
unordered_set<Event> effectEVs_;
EvLinks prev_[N_EVENT_STATE]; // not unordered-map since most traversal
EvLinks next_[N_EVENT_STATE]; // not unordered-map since most traversal
std::unordered_map<EvName, Event> en_ev_; // [evName]=event
EvNames ev_en_; // [event]=evName for easy debug
std::unordered_set<Event> effectEVs_;
};

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion src/domino/FreeHdlrDomino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class FreeHdlrDomino : public aDominoType
private:
// - bitmap & dyn expand, [event]=t/f
// - don't know if repeated hdlrs are much less than non-repeated, so bitmap is simpler than set<Event>
vector<bool> isRepeatHdlr_;
std::vector<bool> isRepeatHdlr_;
public:
using aDominoType::oneLog;
};
Expand Down
4 changes: 2 additions & 2 deletions src/domino/HdlrDomino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class HdlrDomino : public aDominoType

// -------------------------------------------------------------------------------------------
private:
unordered_map<Domino::Event, SharedMsgCB> ev_hdlr_S_;
std::unordered_map<Domino::Event, SharedMsgCB> ev_hdlr_S_;
protected:
SafePtr<MsgSelf> msgSelf_ = ObjAnywhere::getObj<MsgSelf>();
public:
Expand Down Expand Up @@ -166,7 +166,7 @@ Domino::Event HdlrDomino<aDominoType>::setHdlr(const Domino::EvName& aEvName, co
}

// set
auto newHdlr = make_shared<MsgCB>(aHdlr);
auto newHdlr = std::make_shared<MsgCB>(aHdlr);
ev_hdlr_S_.emplace(newEv, newHdlr);
HID("(HdlrDom) Succeed for EvName=" << aEvName);

Expand Down
8 changes: 4 additions & 4 deletions src/domino/MultiHdlrDomino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ template<class aDominoType>
class MultiHdlrDomino : public aDominoType
{
public:
using HdlrName = string;
using HName_Hdlr_S = map<HdlrName, SharedMsgCB>;
using HdlrName = std::string;
using HName_Hdlr_S = std::map<HdlrName, SharedMsgCB>;

explicit MultiHdlrDomino(const LogName& aUniLogName = ULN_DEFAULT) : aDominoType(aUniLogName) {}

Expand All @@ -56,7 +56,7 @@ class MultiHdlrDomino : public aDominoType

private:
// -------------------------------------------------------------------------------------------
unordered_map<Domino::Event, HName_Hdlr_S> ev_hdlrs_S_;
std::unordered_map<Domino::Event, HName_Hdlr_S> ev_hdlrs_S_;
public:
using aDominoType::oneLog;
};
Expand Down Expand Up @@ -96,7 +96,7 @@ Domino::Event MultiHdlrDomino<aDominoType>::multiHdlrOnSameEv(const Domino::EvNa
}

// set hdlr
auto&& newHdlr = make_shared<MsgCB>(aHdlr);
auto&& newHdlr = std::make_shared<MsgCB>(aHdlr);
auto&& ev = this->getEventBy(aEvName);
auto&& ev_hdlrs = ev_hdlrs_S_.find(ev);
if (ev_hdlrs == ev_hdlrs_S_.end())
Expand Down
2 changes: 1 addition & 1 deletion src/domino/PriDomino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PriDomino : public aDominoType

private:
// -------------------------------------------------------------------------------------------
unordered_map<Domino::Event, EMsgPriority> ev_pri_S_; // [event]=priority
std::unordered_map<Domino::Event, EMsgPriority> ev_pri_S_; // [event]=priority
public:
using aDominoType::oneLog;
};
Expand Down
4 changes: 1 addition & 3 deletions src/domino/RmEvDom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

#include <unordered_set>

using namespace std;

namespace RLib
{
// ***********************************************************************************************
Expand All @@ -53,7 +51,7 @@ class RmEvDom : public aDominoType
// - REQ: min mem (so set<Event> is better than vector<bool> when almost empty
// - REQ: fast (eg isRemoved(), insert, del)
// - req: better FIFO
unordered_set<Domino::Event> isRemovedEv_;
std::unordered_set<Domino::Event> isRemovedEv_;

public:
using aDominoType::oneLog;
Expand Down
6 changes: 2 additions & 4 deletions src/domino/WbasicDatDom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

#include "UniLog.hpp"

using namespace std;

namespace RLib
{
// ***********************************************************************************************
Expand All @@ -41,7 +39,7 @@ class WbasicDatDom : public aDominoType
using aDominoType::getData;
using aDominoType::replaceData;
// -------------------------------------------------------------------------------------------
vector<bool> wrCtrl_;
std::vector<bool> wrCtrl_;

public:
using aDominoType::oneLog;
Expand Down Expand Up @@ -135,7 +133,7 @@ bool WbasicDatDom<aDominoType>::wrCtrlOk(const Domino::EvName& aEvName, const bo
template<typename aDataDominoType, typename aDataType>
SafePtr<aDataType> wbasic_getData(aDataDominoType& aDom, const Domino::EvName& aEvName)
{
return static_pointer_cast<aDataType>(aDom.wbasic_getData(aEvName));
return std::static_pointer_cast<aDataType>(aDom.wbasic_getData(aEvName));
}

// ***********************************************************************************************
Expand Down
8 changes: 3 additions & 5 deletions src/log/StrCoutFSL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@

#include "BaseSL.hpp"

using namespace std;

namespace RLib
{
// ***********************************************************************************************
class StrCoutFSL // FSL = Formatted Smart Log
class StrCoutFSL // FSL = Formatted Smart Log
: public BaseSL
, public stringstream // for operator<<(); must not ostringstream since dump need read it!!!
, public std::stringstream // for operator<<(); must not ostringstream since dump need read it!!!
{
public :
~StrCoutFSL();
Expand All @@ -56,7 +54,7 @@ StrCoutFSL::~StrCoutFSL()
inline
void StrCoutFSL::forceSave() const
{
cout << rdbuf() << endl; // internet says rdbuf() is faster than str()
std::cout << rdbuf() << std::endl; // internet says rdbuf() is faster than str()
}

} // namespace
Expand Down
14 changes: 6 additions & 8 deletions src/log/UniBaseLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
#include <memory>
#include <string>

using namespace std;
using namespace std::chrono;

using LogName = string;
using LogName = std::string;

// ***********************************************************************************************
// - mem safe: yes
// - MT safe : yes upon UniCoutLog, no upon UniSmartLog
#define BUF(content) __func__ << "():" << __LINE__ << ": " << content << endl // __FILE_NAME__ since GCC 12
#define BUF(content) __func__ << "():" << __LINE__ << ": " << content << std::endl // __FILE_NAME__ since GCC 12
#define INF(content) { oneLog() << "INF] " << BUF(content); }
#define WRN(content) { oneLog() << "WRN] " << BUF(content); }
#define ERR(content) { oneLog() << "ERR] " << BUF(content); }
Expand All @@ -49,11 +46,12 @@ inline const char* timestamp()
{
static thread_local char buf[] = "ddd/HH:MM:SS.123456"; // ddd is days/year; thread_local is MT safe

auto now_tp = system_clock::now();
auto now_tt = system_clock::to_time_t(now_tp);
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));
snprintf(buf + sizeof(buf) - 7, 7, "%06u", // snprintf is safer than sprintf
unsigned(duration_cast<microseconds>(now_tp.time_since_epoch()).count() % 1'000'000)); // can milliseconds
unsigned(std::chrono::duration_cast<std::chrono::microseconds>(now_tp.time_since_epoch()).count()
% 1'000'000));
return buf;
}

Expand Down
2 changes: 2 additions & 0 deletions src/log/UniCoutLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// ***********************************************************************************************
#include "UniCoutLog.hpp"

using namespace std;

namespace RLib
{
// ***********************************************************************************************
Expand Down
8 changes: 3 additions & 5 deletions src/log/UniCoutLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#include "UniBaseLog.hpp"

using namespace std;

namespace RLib
{
// ***********************************************************************************************
Expand All @@ -35,8 +33,8 @@ class UniCoutLog
explicit UniCoutLog(const LogName&) {} // compatible UniSmartLog
UniCoutLog() = default;

static ostream& oneLog();
ostream& operator()() const { return oneLog(); }
static std::ostream& oneLog();
std::ostream& operator()() const { return oneLog(); }
static void needLog() {}

static LogName uniLogName() { return ULN_DEFAULT; }
Expand All @@ -59,7 +57,7 @@ class UniCoutLog

// ***********************************************************************************************
// static than inline, avoid ut conflict when coexist both UniLog
static ostream& oneLog() { return UniCoutLog::oneLog(); }
static std::ostream& oneLog() { return UniCoutLog::oneLog(); }

using UniLog = UniCoutLog;

Expand Down
2 changes: 2 additions & 0 deletions src/log/UniSmartLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// ***********************************************************************************************
#include "UniSmartLog.hpp"

using namespace std;

namespace RLib
{
// ***********************************************************************************************
Expand Down
8 changes: 3 additions & 5 deletions src/log/UniSmartLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
#include "StrCoutFSL.hpp"
#include "UniBaseLog.hpp"

using namespace std;

namespace RLib
{
// ***********************************************************************************************
using SmartLog = StrCoutFSL;
using LogStore = unordered_map<LogName, shared_ptr<SmartLog> >;
using LogStore = std::unordered_map<LogName, std::shared_ptr<SmartLog> >;

// ***********************************************************************************************
class UniSmartLog
Expand All @@ -51,8 +49,8 @@ class UniSmartLog

private:
// -------------------------------------------------------------------------------------------
shared_ptr<SmartLog> smartLog_;
const LogName uniLogName_;
std::shared_ptr<SmartLog> smartLog_;
const LogName uniLogName_;

static LogStore name_log_S_;
public:
Expand Down
10 changes: 4 additions & 6 deletions src/msg_self/MsgSelf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@

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

using namespace std;

namespace RLib
{
// ***********************************************************************************************
Expand All @@ -64,9 +62,9 @@ enum EMsgPriority : unsigned char
// !!! MsgCB shall NEVER throw exception!!!
// - MsgCB can try-catch all exception
// - exception is bug to be fixed than pretected
using MsgCB = function<void()>;
using WeakMsgCB = weak_ptr<MsgCB>;
using SharedMsgCB = shared_ptr<MsgCB>;
using MsgCB = std::function<void()>;
using WeakMsgCB = std::weak_ptr<MsgCB>;
using SharedMsgCB = std::shared_ptr<MsgCB>;

// ***********************************************************************************************
class MsgSelf : public UniLog
Expand All @@ -86,7 +84,7 @@ class MsgSelf : public UniLog
bool handleOneMsg_();

// -------------------------------------------------------------------------------------------
deque<MsgCB> msgQueues_[EMsgPri_MAX];
std::deque<MsgCB> msgQueues_[EMsgPri_MAX];
size_t nMsg_ = 0;
};
} // namespace
Expand Down
6 changes: 2 additions & 4 deletions src/obj_anywhere/DataStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "SafePtr.hpp" // can't UniPtr.hpp since ut(=req) build-err
#include "UniLog.hpp" // debug

using namespace std;

namespace RLib
{
// ***********************************************************************************************
Expand All @@ -45,7 +43,7 @@ class DataStore

private:
// -------------------------------------------------------------------------------------------
unordered_map<aDataKey, SafePtr<void>> key_data_S_;
std::unordered_map<aDataKey, SafePtr<void>> key_data_S_;
};

// ***********************************************************************************************
Expand Down Expand Up @@ -82,7 +80,7 @@ SafePtr<aDataT> DataStore<aDataKey>::get(const aDataKey& aKey) const
HID("(DataStore) can't find key=" << aKey);
return nullptr;
}
return dynamic_pointer_cast<aDataT>(key_data->second);
return std::dynamic_pointer_cast<aDataT>(key_data->second);
}

// ***********************************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions src/obj_anywhere/ObjAnywhere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
#include "ObjAnywhere.hpp"

using namespace std;

namespace RLib
{
shared_ptr<DataStore<ObjName>> ObjAnywhere::name_obj_S_;
Expand Down
6 changes: 2 additions & 4 deletions src/obj_anywhere/ObjAnywhere.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
#include "DataStore.hpp"
#include "UniLog.hpp"

using namespace std;

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

// ***********************************************************************************************
class ObjAnywhere
Expand All @@ -57,7 +55,7 @@ class ObjAnywhere

private:
// -------------------------------------------------------------------------------------------
static shared_ptr<DataStore<ObjName>> name_obj_S_; // store aObj w/o include aObj.hpp; shared_ptr is safe here
static std::shared_ptr<DataStore<ObjName>> name_obj_S_; // store aObj w/o include aObj.hpp; shared_ptr is safe here
};

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

0 comments on commit 02f1971

Please sign in to comment.