Skip to content

Commit f3c9e7c

Browse files
committed
Cleanup duplicated macros
1 parent ed92f4c commit f3c9e7c

File tree

3 files changed

+48
-68
lines changed

3 files changed

+48
-68
lines changed

spectrum/src/frontends/slack/SlackAPI.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,6 @@
3535

3636
namespace Transport {
3737

38-
DEFINE_LOGGER(slackAPILogger, "SlackAPI");
39-
40-
#define GET_ARRAY(FROM, NAME) Json::Value &NAME = FROM[#NAME]; \
41-
if (!NAME.isArray()) { \
42-
LOG4CXX_ERROR(slackAPILogger, "No '" << #NAME << "' object in the reply."); \
43-
return; \
44-
}
45-
46-
#define STORE_STRING(FROM, NAME) Json::Value &NAME##_tmp = FROM[#NAME]; \
47-
if (!NAME##_tmp.isString()) { \
48-
LOG4CXX_ERROR(slackAPILogger, "No '" << #NAME << "' string in the reply."); \
49-
LOG4CXX_ERROR(slackAPILogger, data); \
50-
return; \
51-
} \
52-
std::string NAME = NAME##_tmp.asString();
53-
54-
#define STORE_BOOL(FROM, NAME) Json::Value &NAME##_tmp = FROM[#NAME]; \
55-
if (!NAME##_tmp.isBool()) { \
56-
LOG4CXX_ERROR(slackAPILogger, "No '" << #NAME << "' string in the reply."); \
57-
LOG4CXX_ERROR(slackAPILogger, data); \
58-
return; \
59-
} \
60-
bool NAME = NAME##_tmp.asBool();
61-
62-
#define GET_OBJECT(FROM, NAME) Json::Value &NAME = FROM[#NAME]; \
63-
if (!NAME.isObject()) { \
64-
LOG4CXX_ERROR(slackAPILogger, "No '" << #NAME << "' object in the reply."); \
65-
return; \
66-
}
67-
68-
#define STORE_STRING_OPTIONAL(FROM, NAME) Json::Value &NAME##_tmp = FROM[#NAME]; \
69-
std::string NAME; \
70-
if (NAME##_tmp.isString()) { \
71-
NAME = NAME##_tmp.asString(); \
72-
}
73-
7438
SlackAPI::SlackAPI(Component *component, SlackIdManager *idManager, const std::string &token, const std::string &domain) : HTTPRequestQueue(component, domain) {
7539
m_component = component;
7640
m_token = token;

spectrum/src/frontends/slack/SlackAPI.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,50 @@
2828
#include <algorithm>
2929
#include <map>
3030

31+
DEFINE_LOGGER(slackAPILogger, "SlackAPI");
32+
33+
#define GET_ARRAY(FROM, NAME) Json::Value &NAME = FROM[#NAME]; \
34+
if (!NAME.isArray()) { \
35+
LOG4CXX_ERROR(slackAPILogger, "No '" << #NAME << "' object in the reply."); \
36+
return; \
37+
}
38+
39+
#define STORE_STRING(FROM, NAME) Json::Value &NAME##_tmp = FROM[#NAME]; \
40+
if (!NAME##_tmp.isString()) { \
41+
LOG4CXX_ERROR(slackAPILogger, "No '" << #NAME << "' string in the reply."); \
42+
LOG4CXX_ERROR(slackAPILogger, data); \
43+
return; \
44+
} \
45+
std::string NAME = NAME##_tmp.asString();
46+
47+
#define STORE_BOOL(FROM, NAME) Json::Value &NAME##_tmp = FROM[#NAME]; \
48+
if (!NAME##_tmp.isBool()) { \
49+
LOG4CXX_ERROR(slackAPILogger, "No '" << #NAME << "' string in the reply."); \
50+
LOG4CXX_ERROR(slackAPILogger, data); \
51+
return; \
52+
} \
53+
bool NAME = NAME##_tmp.asBool();
54+
55+
#define GET_OBJECT(FROM, NAME) Json::Value &NAME = FROM[#NAME]; \
56+
if (!NAME.isObject()) { \
57+
LOG4CXX_ERROR(slackAPILogger, "No '" << #NAME << "' object in the reply."); \
58+
return; \
59+
}
60+
61+
#define STORE_STRING_OPTIONAL(FROM, NAME) Json::Value &NAME##_tmp = FROM[#NAME]; \
62+
std::string NAME; \
63+
if (NAME##_tmp.isString()) { \
64+
NAME = NAME##_tmp.asString(); \
65+
}
66+
67+
#define STORE_INT(FROM, NAME) Json::Value &NAME##_tmp = FROM[#NAME]; \
68+
if (!NAME##_tmp.isInt()) { \
69+
LOG4CXX_ERROR(slackAPILogger, "No '" << #NAME << "' number in the reply."); \
70+
LOG4CXX_ERROR(slackAPILogger, data); \
71+
return; \
72+
} \
73+
int NAME = NAME##_tmp.asInt();
74+
3175
namespace Transport {
3276

3377
class Component;

spectrum/src/frontends/slack/SlackRTM.cpp

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,41 +72,13 @@ void SlackRTM::start() {
7272
req->execute();
7373
}
7474

75-
#define STORE_STRING(FROM, NAME) Json::Value &NAME##_tmp = FROM[#NAME]; \
76-
if (!NAME##_tmp.isString()) { \
77-
LOG4CXX_ERROR(slackRTMLogger, "No '" << #NAME << "' string in the reply."); \
78-
LOG4CXX_ERROR(slackRTMLogger, payload); \
79-
return; \
80-
} \
81-
std::string NAME = NAME##_tmp.asString();
82-
83-
#define STORE_STRING_OPTIONAL(FROM, NAME) Json::Value &NAME##_tmp = FROM[#NAME]; \
84-
std::string NAME; \
85-
if (NAME##_tmp.isString()) { \
86-
NAME = NAME##_tmp.asString(); \
87-
}
88-
89-
#define GET_OBJECT(FROM, NAME) Json::Value &NAME = FROM[#NAME]; \
90-
if (!NAME.isObject()) { \
91-
LOG4CXX_ERROR(slackRTMLogger, "No '" << #NAME << "' object in the reply."); \
92-
return; \
93-
}
94-
95-
#define STORE_INT(FROM, NAME) Json::Value &NAME##_tmp = FROM[#NAME]; \
96-
if (!NAME##_tmp.isInt()) { \
97-
LOG4CXX_ERROR(slackRTMLogger, "No '" << #NAME << "' number in the reply."); \
98-
LOG4CXX_ERROR(slackRTMLogger, payload); \
99-
return; \
100-
} \
101-
int NAME = NAME##_tmp.asInt();
102-
103-
void SlackRTM::handlePayloadReceived(const std::string &payload) {
75+
void SlackRTM::handlePayloadReceived(const std::string &data) {
10476
Json::Value d;
10577
Json::CharReaderBuilder rbuilder;
10678
std::shared_ptr<Json::CharReader> const reader(rbuilder.newCharReader());
107-
if (!reader->parse(payload.c_str(), payload.c_str() + payload.size(), &d, NULL)) {
79+
if (!reader->parse(data.c_str(), data.c_str() + data.size(), &d, NULL)) {
10880
LOG4CXX_ERROR(slackRTMLogger, "Error while parsing JSON");
109-
LOG4CXX_ERROR(slackRTMLogger, payload);
81+
LOG4CXX_ERROR(slackRTMLogger, data);
11082
return;
11183
}
11284

@@ -152,7 +124,7 @@ void SlackRTM::handlePayloadReceived(const std::string &payload) {
152124
else if (type == "channel_joined"
153125
|| type == "channel_created") {
154126
std::map<std::string, SlackChannelInfo> &channels = m_idManager->getChannels();
155-
SlackAPI::getSlackChannelInfo(NULL, true, d, payload, channels);
127+
SlackAPI::getSlackChannelInfo(NULL, true, d, data, channels);
156128
}
157129
else if (type == "error") {
158130
GET_OBJECT(d, error);

0 commit comments

Comments
 (0)