forked from anqin/trident
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.h
More file actions
100 lines (79 loc) · 3.13 KB
/
common.h
File metadata and controls
100 lines (79 loc) · 3.13 KB
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
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2014 The Trident Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
//
#ifndef _TRIDENT_COMMON_H_
#define _TRIDENT_COMMON_H_
#include <google/protobuf/stubs/callback.h>
#include <trident/smart_ptr/smart_ptr.hpp>
namespace std {}
namespace trident {
/////////////// types /////////////
typedef ::google::protobuf::uint uint;
typedef ::google::protobuf::int8 int8;
typedef ::google::protobuf::int16 int16;
typedef ::google::protobuf::int32 int32;
typedef ::google::protobuf::int64 int64;
typedef ::google::protobuf::uint8 uint8;
typedef ::google::protobuf::uint16 uint16;
typedef ::google::protobuf::uint32 uint32;
typedef ::google::protobuf::uint64 uint64;
static const int32 kint32max = ::google::protobuf::kint32max;
static const int32 kint32min = ::google::protobuf::kint32min;
static const int64 kint64max = ::google::protobuf::kint64max;
static const int64 kint64min = ::google::protobuf::kint64min;
static const uint32 kuint32max = ::google::protobuf::kuint32max;
static const uint64 kuint64max = ::google::protobuf::kuint64max;
/////////////// util macros /////////////
#define TRIDENT_PP_CAT(a, b) TRIDENT_PP_CAT_I(a, b)
#define TRIDENT_PP_CAT_I(a, b) a ## b
#define TRIDENT_DISALLOW_EVIL_CONSTRUCTORS(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
/////////////// logging and check /////////////
// default log level: ERROR
enum LogLevel {
LOG_LEVEL_FATAL = 0,
LOG_LEVEL_ERROR = 1,
LOG_LEVEL_WARNING = 2,
LOG_LEVEL_NOTICE = 3,
LOG_LEVEL_INFO = 3,
LOG_LEVEL_TRACE = 4,
LOG_LEVEL_DEBUG = 5,
};
namespace internal {
LogLevel get_log_level();
void set_log_level(LogLevel level);
void log_handler(LogLevel level, const char* filename, int line, const char *fmt, ...);
} // namespace internal
#define TRIDENT_SET_LOG_LEVEL(level) \
::trident::internal::set_log_level(::trident::LOG_LEVEL_##level)
#define SLOG(level, fmt, arg...) \
(::trident::LOG_LEVEL_##level > ::trident::internal::get_log_level()) ? \
(void)0 : ::trident::internal::log_handler( \
::trident::LOG_LEVEL_##level, __FILE__, __LINE__, fmt, ##arg) \
#define SLOG_IF(condition, level, fmt, arg...) \
!(condition) ? (void)0 : ::trident::internal::log_handler( \
::trident::LOG_LEVEL_##level, __FILE__, __LINE__, fmt, ##arg)
#if 0
#define SCHECK(expression) CHECK(expression)
#define SCHECK_EQ(a, b) CHECK_EQ(a, b)
#define SCHECK_NE(a, b) CHECK_NE(a, b)
#define SCHECK_LT(a, b) CHECK_LT(a, b)
#define SCHECK_LE(a, b) CHECK_LE(a, b)
#define SCHECK_GT(a, b) CHECK_GT(a, b)
#define SCHECK_GE(a, b) CHECK_GE(a, b)
#else
#define SCHECK(expression) \
SLOG_IF(!(expression), FATAL, "CHECK failed: " #expression)
#define SCHECK_EQ(a, b) SCHECK((a) == (b))
#define SCHECK_NE(a, b) SCHECK((a) != (b))
#define SCHECK_LT(a, b) SCHECK((a) < (b))
#define SCHECK_LE(a, b) SCHECK((a) <= (b))
#define SCHECK_GT(a, b) SCHECK((a) > (b))
#define SCHECK_GE(a, b) SCHECK((a) >= (b))
#endif
} // namespace trident
#endif // _TRIDENT_COMMON_H_
/* vim: set ts=4 sw=4 sts=4 tw=100 */