Skip to content

Commit

Permalink
change to find
Browse files Browse the repository at this point in the history
  • Loading branch information
Brat-vseznamus committed Jul 30, 2024
1 parent 51db21f commit cbdafcb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
19 changes: 11 additions & 8 deletions internal/tlcodegen/test/gen/cases_cpp/__meta/details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,27 @@ namespace {
}

tl2::meta::tl_item tl2::meta::get_item_by_name(std::string &&s) {
if (items.items.count(s)) {
return items.items[s];
auto item = items.items.find(s);
if (item != items.items.end()) {
return item->second;
}
throw std::runtime_error("no item with such name + \"" + s + "\"");
}

void tl2::meta::set_create_object_by_name(std::string &&s, std::function<std::unique_ptr<tl2::meta::tl_object>()>&& gen) {
if (items.items.count(s)) {
items.items[s].create_object = gen;
return;
auto item = items.items.find(s);
if (item != items.items.end()) {
item->second.create_object = gen;
return;
}
throw std::runtime_error("no item with such name + \"" + s + "\"");
}

void tl2::meta::set_create_function_by_name(std::string &&s, std::function<std::unique_ptr<tl2::meta::tl_function>()>&& gen) {
if (items.items.count(s)) {
items.items[s].create_function = gen;
return;
auto item = items.items.find(s);
if (item != items.items.end()) {
item->second.create_function = gen;
return;
}
throw std::runtime_error("no item with such name + \"" + s + "\"");
}
Expand Down
19 changes: 11 additions & 8 deletions internal/tlcodegen/test/gen/schema_cpp/__meta/details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,27 @@ namespace {
}

tl2::meta::tl_item tl2::meta::get_item_by_name(std::string &&s) {
if (items.items.count(s)) {
return items.items[s];
auto item = items.items.find(s);
if (item != items.items.end()) {
return item->second;
}
throw std::runtime_error("no item with such name + \"" + s + "\"");
}

void tl2::meta::set_create_object_by_name(std::string &&s, std::function<std::unique_ptr<tl2::meta::tl_object>()>&& gen) {
if (items.items.count(s)) {
items.items[s].create_object = gen;
return;
auto item = items.items.find(s);
if (item != items.items.end()) {
item->second.create_object = gen;
return;
}
throw std::runtime_error("no item with such name + \"" + s + "\"");
}

void tl2::meta::set_create_function_by_name(std::string &&s, std::function<std::unique_ptr<tl2::meta::tl_function>()>&& gen) {
if (items.items.count(s)) {
items.items[s].create_function = gen;
return;
auto item = items.items.find(s);
if (item != items.items.end()) {
item->second.create_function = gen;
return;
}
throw std::runtime_error("no item with such name + \"" + s + "\"");
}
Expand Down
19 changes: 11 additions & 8 deletions internal/tlcodegen/tlgen_cpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,24 +570,27 @@ namespace {
}
tl2::meta::tl_item tl2::meta::get_item_by_name(std::string &&s) {
if (items.items.count(s)) {
return items.items[s];
auto item = items.items.find(s);
if (item != items.items.end()) {
return item->second;
}
throw std::runtime_error("no item with such name + \"" + s + "\"");
}
void tl2::meta::set_create_object_by_name(std::string &&s, std::function<std::unique_ptr<tl2::meta::tl_object>()>&& gen) {
if (items.items.count(s)) {
items.items[s].create_object = gen;
return;
auto item = items.items.find(s);
if (item != items.items.end()) {
item->second.create_object = gen;
return;
}
throw std::runtime_error("no item with such name + \"" + s + "\"");
}
void tl2::meta::set_create_function_by_name(std::string &&s, std::function<std::unique_ptr<tl2::meta::tl_function>()>&& gen) {
if (items.items.count(s)) {
items.items[s].create_function = gen;
return;
auto item = items.items.find(s);
if (item != items.items.end()) {
item->second.create_function = gen;
return;
}
throw std::runtime_error("no item with such name + \"" + s + "\"");
}
Expand Down

0 comments on commit cbdafcb

Please sign in to comment.