Skip to content

Commit 19f9acb

Browse files
committed
Shipping heavy objects in std::shared_ptr
1 parent 2962a3c commit 19f9acb

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

examples/workspaces.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ void dump_tree_container(const i3ipc::container_t& c, std::string& prefix) {
3030
int main() {
3131
i3ipc::connection conn;
3232
for (auto& w : conn.get_workspaces()) {
33-
std::cout << '#' << std::hex << w.num << std::dec
34-
<< "\n\tName: " << w.name
35-
<< "\n\tVisible: " << w.visible
36-
<< "\n\tFocused: " << w.focused
37-
<< "\n\tUrgent: " << w.urgent
33+
std::cout << '#' << std::hex << w->num << std::dec
34+
<< "\n\tName: " << w->name
35+
<< "\n\tVisible: " << w->visible
36+
<< "\n\tFocused: " << w->focused
37+
<< "\n\tUrgent: " << w->urgent
3838
<< "\n\tRect: "
39-
<< "\n\t\tX: " << w.rect.x
40-
<< "\n\t\tY: " << w.rect.y
41-
<< "\n\t\tWidth: " << w.rect.width
42-
<< "\n\t\tHeight: " << w.rect.height
43-
<< "\n\tOutput: " << w.output
39+
<< "\n\t\tX: " << w->rect.x
40+
<< "\n\t\tY: " << w->rect.y
41+
<< "\n\t\tWidth: " << w->rect.width
42+
<< "\n\t\tHeight: " << w->rect.height
43+
<< "\n\tOutput: " << w->output
4444
<< std::endl;
4545
}
4646
std::string prefix_buf;

include/i3ipc++/ipc.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ class connection {
182182
* Request a list of workspaces
183183
* @return List of workspaces
184184
*/
185-
std::vector<workspace_t> get_workspaces() const;
185+
std::vector< std::shared_ptr<workspace_t> > get_workspaces() const;
186186

187187
/**
188188
* Request a list of outputs
189189
* @return List of outputs
190190
*/
191-
std::vector<output_t> get_outputs() const;
191+
std::vector< std::shared_ptr<output_t> > get_outputs() const;
192192

193193
/**
194194
* Request a version of i3

src/ipc.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static std::shared_ptr<container_t> parse_container_from_json(const Json::Value
113113
#undef i3IPC_TYPE_STR
114114
}
115115

116-
static workspace_t parse_workspace_from_json(const Json::Value& value) {
116+
static std::shared_ptr<workspace_t> parse_workspace_from_json(const Json::Value& value) {
117117
Json::Value num = value["num"];
118118
Json::Value name = value["name"];
119119
Json::Value visible = value["visible"];
@@ -122,29 +122,29 @@ static workspace_t parse_workspace_from_json(const Json::Value& value) {
122122
Json::Value rect = value["rect"];
123123
Json::Value output = value["output"];
124124

125-
return {
126-
.num = num.asInt(),
127-
.name = name.asString(),
128-
.visible = visible.asBool(),
129-
.focused = focused.asBool(),
130-
.urgent = urgent.asBool(),
131-
.rect = parse_rect_from_json(rect),
132-
.output = output.asString(),
133-
};
125+
std::shared_ptr<workspace_t> p;
126+
p->num = num.asInt();
127+
p->name = name.asString();
128+
p->visible = visible.asBool();
129+
p->focused = focused.asBool();
130+
p->urgent = urgent.asBool();
131+
p->rect = parse_rect_from_json(rect);
132+
p->output = output.asString();
133+
return p;
134134
}
135135

136-
static output_t parse_output_from_json(const Json::Value& value) {
136+
static std::shared_ptr<output_t> parse_output_from_json(const Json::Value& value) {
137137
Json::Value name = value["name"];
138138
Json::Value active = value["active"];
139139
Json::Value current_workspace = value["current_workspace"];
140140
Json::Value rect = value["rect"];
141141

142-
return {
143-
.name = name.asString(),
144-
.active = active.asBool(),
145-
.current_workspace = (current_workspace.isNull() ? std::string() : current_workspace.asString()),
146-
.rect = parse_rect_from_json(rect),
147-
};
142+
std::shared_ptr<output_t> p;
143+
p->name = name.asString();
144+
p->active = active.asBool();
145+
p->current_workspace = (current_workspace.isNull() ? std::string() : current_workspace.asString());
146+
p->rect = parse_rect_from_json(rect);
147+
return p;
148148
}
149149

150150

@@ -332,14 +332,14 @@ std::shared_ptr<container_t> connection::get_tree() const {
332332
}
333333

334334

335-
std::vector<output_t> connection::get_outputs() const {
335+
std::vector< std::shared_ptr<output_t> > connection::get_outputs() const {
336336
#define i3IPC_TYPE_STR "GET_OUTPUTS"
337337
auto buf = i3_msg(m_main_socket, ClientMessageType::GET_OUTPUTS);
338338
Json::Value root;
339339
IPC_JSON_READ(root)
340340
IPC_JSON_ASSERT_TYPE_ARRAY(root, "root")
341341

342-
std::vector<output_t> outputs;
342+
std::vector< std::shared_ptr<output_t> > outputs;
343343

344344
for (auto w : root) {
345345
outputs.push_back(parse_output_from_json(w));
@@ -350,14 +350,14 @@ std::vector<output_t> connection::get_outputs() const {
350350
}
351351

352352

353-
std::vector<workspace_t> connection::get_workspaces() const {
353+
std::vector< std::shared_ptr<workspace_t> > connection::get_workspaces() const {
354354
#define i3IPC_TYPE_STR "GET_WORKSPACES"
355355
auto buf = i3_msg(m_main_socket, ClientMessageType::GET_WORKSPACES);
356356
Json::Value root;
357357
IPC_JSON_READ(root)
358358
IPC_JSON_ASSERT_TYPE_ARRAY(root, "root")
359359

360-
std::vector<workspace_t> workspaces;
360+
std::vector< std::shared_ptr<workspace_t> > workspaces;
361361

362362
for (auto w : root) {
363363
workspaces.push_back(parse_workspace_from_json(w));

0 commit comments

Comments
 (0)