-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUtil.h
90 lines (72 loc) · 2.11 KB
/
Util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef __UTIL_H__
#define __UTIL_H__
#define _CRT_SECURE_NO_DEPRECATE //remove warning C4996
#include "Ostype.h"
//#include "UtilPdu.h"
#include "Lock.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <list>
//#include "slog/slog_api.h"
#ifndef _WIN32
#include <strings.h>
#endif
#include <sys/stat.h>
#include <assert.h>
#ifdef _WIN32
#define snprintf sprintf_s
#else
#include <stdarg.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#endif
using namespace std;
#define NOTUSED_AGR(v) ((void)v) //used this to remove warning C4100,unreferencded parameter
class CRefObject
{
public:
CRefObject();
virtual ~CRefObject();
void SetLock(CLock* lock) { m_lock = lock;}
void AddRef();
void ReleaseRef();
private:
int m_refCount;
CLock* m_lock;
};
//extern CSLog g_imlog;
#define __FILENAME__ (strrchr(__FILE__,'/') ? (strrchr(__FILE__,'/') + 1):__FILE__)
#if defined (_WIN32) || defined(_WIN64)
//#define log(fmt,...) g_imlog.Info("<%s>\t<%d>\t<%s>,"fmt,__FILENAME__,__LINE__,__FUNCTION__,##__va_args__)
#else
//#define log(fmt, args...) g_imlog.Info("<%s>|<%d>|<%s>,"fmt,__FILENAME__,__LINE__,__FUNCTION__,##args)
#endif
uint64_t get_tick_count();
void util_sleep(uint32_t millisecond);
class CStrExplode
{
public:
CStrExplode(char* str, char seperator);
virtual ~CStrExplode();
uint32_t GetItemCnt() { return m_item_cnt;}
char* GetItem(uint32_t idx) { return m_item_list[idx];}
private:
uint32_t m_item_cnt;
char** m_item_list;
};
char* replaceStr(char* pStr, char oldChar, char newChar);
string int2string(uint32_t user_id);
uint32_t string2int(const string& value);
void replace_mark(string& str, string& new_value, uint32_t & begin_pos);
void replace_mark(string& str, uint32_t new_value, uint32_t& begin_pos);
void writePid();
inline unsigned char toHex(const unsigned char &x);
inline unsigned char fromHex(const unsigned char &x);
string URLEncode(const string &sIn);
string URLDecode(const string &sIn);
int64_t get_file_size(const char* path);
const char* memfind(const char* src_str,size_t src_len, const char* sub_str, size_t sub_len, bool flag = true);
#endif