Skip to content

Commit

Permalink
优化-规范化命名
Browse files Browse the repository at this point in the history
  • Loading branch information
NingLeixueR committed Jul 9, 2024
1 parent ce0b7dd commit c5ef493
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 29 deletions.
16 changes: 4 additions & 12 deletions public/cpp/protocol/protocol/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ namespace ngl
{
char m_hexstr[1024] = { 0 };
log_error()->print("protocol::push [{}] Error protocolnum[{}] "
, (int)aprotocoltype
, aprotocolnum
, (int)aprotocoltype, aprotocolnum
);
return nullptr;
}
Expand All @@ -46,16 +45,14 @@ namespace ngl
//{
// log_error()->print(
// "protocol::push Info {}:{}",
// aprotocolnum,
// lpair.first
// aprotocolnum, lpair.first
// );
//}
//else
//{
// log_error()->print(
// "protocol::push Info {}:{}",
// aprotocolnum,
// "not find protocol name"
// aprotocolnum, "not find protocol name"
// );
//}
/////////////////////////////////////////////
Expand Down Expand Up @@ -134,12 +131,7 @@ namespace ngl
, const char* aname)
{
impl_protocol::register_protocol(
atype,
aprotocolnumber,
aenumactor,
apackfun,
arunfun,
aname
atype, aprotocolnumber, aenumactor, apackfun, arunfun, aname
);
}

Expand Down
8 changes: 2 additions & 6 deletions public/cpp/protocol/protocol/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ namespace ngl
nguid lrequestactorguid(apack->m_head.get_request_actor());
std::shared_ptr<T> ldatapack = std::static_pointer_cast<T>(aptrpram);
handle_pram lpram = handle_pram::create<T, false, false>(
lactorguid
, lrequestactorguid
, ldatapack
lactorguid, lrequestactorguid, ldatapack
);
lpram.m_pack = apack;

Expand Down Expand Up @@ -143,9 +141,7 @@ namespace ngl
// 接收转发的消息
template <typename T, bool ISTRUE, EPROTOCOL_TYPE TYPE>
static void registry_actor_recvforward(
ENUM_ACTOR atype,
int32_t aprotocolnum,
const char* aname
ENUM_ACTOR atype, int32_t aprotocolnum, const char* aname
)
{
fun_pack lpackfun = [](std::shared_ptr<pack>& apack)->std::shared_ptr<void>
Expand Down
7 changes: 2 additions & 5 deletions public/cpp/protocol/tprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

#include <map>

// typeid(T).hash_code() #c++标准并没有强制要求只是建议编译器 不同类型生成不同的hash值
#define HASH_CODE_VALUE(_TYPE) typeid(T).hash_code()

namespace ngl
{
template <typename T, EPROTOCOL_TYPE PROTYPE, bool ISUSING, typename TREAL>
Expand All @@ -34,7 +31,7 @@ namespace ngl
template <typename T>
static size_t hash_code()
{
static size_t lcode = HASH_CODE_VALUE(T);
static size_t lcode = typeid(T).hash_code();
return lcode;
}

Expand Down Expand Up @@ -70,7 +67,7 @@ namespace ngl
{
return false;
}
m_keyval.insert(std::make_pair(HASH_CODE_VALUE(T), pinfo
m_keyval.insert(std::make_pair(typeid(T).hash_code(), pinfo
{
.m_type = EPROTOCOL_TYPE_PROTOCOLBUFF,
.m_protocol = lprotocol,
Expand Down
9 changes: 3 additions & 6 deletions public/cpp/tools/db/mysql/db_manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ namespace ngl
{
log_error()->print(
"db_manage::save id:{} !!! name:{}",
aid,
tools::protobuf_tabname<T>::name()
aid, tools::protobuf_tabname<T>::name()
);
return;
}
Expand All @@ -106,8 +105,7 @@ namespace ngl
lbuff,
1024,
"DELETE FROM %s WHERE id='%lld';",
tools::protobuf_tabname<T>::name().c_str(),
aid
tools::protobuf_tabname<T>::name().c_str(), aid
);
if (llen <= 0)
return;
Expand All @@ -123,8 +121,7 @@ namespace ngl
lbuff,
1024,
"SELECT id,data FROM %s WHERE id = '%lld';",
tools::protobuf_tabname<T>::name().c_str(),
aid
tools::protobuf_tabname<T>::name().c_str(), aid
);
if (llen <= 0)
return false;
Expand Down
33 changes: 33 additions & 0 deletions public/cpp/tools/localtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,75 +37,108 @@ namespace ngl

// # 设置时间
static bool settime(time_t sti);

// # 获取时间
static time_t gettime();

// # 获取秒与秒之间的毫秒数
static time_t getms();

// # 获取毫秒
static time_t gettimems();

static void printf_time2str(time_t anow, const char* format);

// # Year-Month-Day Hour:Minuts:Second %y-%m-%d %H:%M:%S
static size_t time2str(char* str, int len, time_t anow, const char* format);

static std::string time2str(time_t anow, const char* format);

static std::string time2str(const char* format);

static time_t str2time(const char* astr, const char* format = "%Y-%m-%d %H:%M:%S");

// # 获取utc时刻那天的 小时分钟的utc
static time_t getsecond2time(time_t utc, int hour/*0-23*/, int minute/*0-59*/, int sec/*0-59*/);

// # 获取今天的指定 小时分钟的utc(如果时间已过则获取下一天的指定小时分钟的utc)
static time_t getsecond2time(int hour/*0-23*/, int minute/*0-59*/, int sec/*0-59*/);

// # 获取指定分钟的utc(如果当前小时分钟秒数已过则获取下一个小时的)
static time_t getsecond2time(int minute/*0-59*/, int sec/*0-59*/);

// # 获取指定秒钟的utc(如果当前小时分钟秒数已过则获取下一个小时的)
static time_t getsecond2time(int sec/*0-59*/);

static time_t getweekday(time_t utc, int aweek/*0-6*/, int hour/*0-23*/, int minute/*0-59*/, int sec/*0-59*/);

// # 获取本周几的指定 小时分钟的utc(如果时间已过则获取下一周几的指定小时分钟的utc)
static time_t getweekday(int aweek/*0-6*/, int hour/*0-23*/, int minute/*0-59*/, int sec/*0-59*/);

static time_t getmothday(time_t utc, int amday/*1-31*/, int hour/*0-23*/, int minute/*0-59*/, int sec/*0-59*/);

// # 获取本月 指定 日小时分钟的utc(如果时间已过则获取下一月的指定日小时分钟的utc)
static time_t getmothday(int amday/*1-31*/, int hour/*0-23*/, int minute/*0-59*/, int sec/*0-59*/);

// # 获取两个时间之间相差的天数
static time_t getspandays(time_t curr, time_t last);

static time_t getnextweekdaytime(time_t curr, time_t weekday);

static time_t getnextweekdaytime(time_t curr, int weekday, int hour, int minute);

static bool isspanweekday(time_t curr, time_t last, int weekday);

static bool isspanweekday(time_t curr, time_t last, int weekday, int hour, int minute);

// # 获得两个时间之间相差多少周
static time_t getspanweeks(time_t curr, time_t last, int weekday);

// # 获取指定小时,分钟时间和目前时间的差值,返回负数则表示指定时间已过 */
static time_t getdesttimevalue(int hour, int minute, int sec);

// # 获取utc那天的第x天的0点的utc时间,utc当天算第0天,utc明天算第1天
static time_t getutcbyday(time_t utc, int dayNum);

// # 获取指定年,月,日,小时,分钟时间和目前时间的差值,返回负数则表示指定时间已过 */
static time_t getdestdayvalue(time_t curr, int year, int month, int day, int hour, int minute);

// # 当月的几号
static int getmoonday(const tm* atm);
static int getmoonday(time_t curr);
static int getmoonday();

static int getmoon(const tm* atm);
static int getmoon(time_t curr);
static int getmoon();

static int getyear(const tm* atm);
static int getyear(time_t curr);
static int getyear();

static int getweekday(const tm* atm);
static int getweekday(time_t curr);
static int getweekday();

static int gethour(const tm* atm);
static int gethour(time_t curr);
static int gethour();

static int getmin(const tm* atm);
static int getmin(time_t curr);
static int getmin();

static int getsec(const tm* atm);
static int getsec(time_t curr);
static int getsec();

static void getweekday(time_t curr, int& weekday, int& hour, int& minute);

static void gettm(time_t curr, tm& atm);

// # 获取指定utc后几个小时
static int getutcbyhour(time_t utc, int hour);

static int getutcbymin(time_t utc, int min);
private:
static time_t m_offset; //时间偏移量
Expand Down

0 comments on commit c5ef493

Please sign in to comment.