From: Arnaud Giersch Date: Mon, 9 Apr 2018 13:33:03 +0000 (+0200) Subject: Reduce code duplication. X-Git-Tag: v3.20~479 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e3be783d9ed8c1a85f7460b57b4f1243ac87c948?hp=9e476ee01b1d7e968ab660c16898d5a542a6b481 Reduce code duplication. --- diff --git a/src/bindings/lua/lua_platf.cpp b/src/bindings/lua/lua_platf.cpp index da34ce4580..26c9276499 100644 --- a/src/bindings/lua/lua_platf.cpp +++ b/src/bindings/lua/lua_platf.cpp @@ -45,6 +45,20 @@ static const luaL_Reg platf_functions[] = { {nullptr, nullptr} }; +static simgrid::s4u::Link::SharingPolicy link_policy_get_by_name(const char* policy) +{ + if (policy && not strcmp(policy, "FULLDUPLEX")) { + XBT_WARN("Please update your platform to use SPLITDUPLEX instead of FULLDUPLEX"); + return simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; + } else if (policy && not strcmp(policy, "SPLITDUPLEX")) { + return simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; + } else if (policy && not strcmp(policy, "FATPIPE")) { + return simgrid::s4u::Link::SharingPolicy::FATPIPE; + } else { + return simgrid::s4u::Link::SharingPolicy::SHARED; + } +} + int console_open(lua_State *L) { sg_platf_init(); sg_platf_begin(); @@ -91,16 +105,7 @@ int console_add_backbone(lua_State *L) { lua_gettable(L, -2); const char* policy = lua_tostring(L, -1); lua_pop(L, 1); - if (policy && not strcmp(policy, "FULLDUPLEX")) { - XBT_WARN("Please update your platform to use SPLITDUPLEX instead of FULLDUPLEX"); - link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; - } else if (policy && not strcmp(policy, "SPLITDUPLEX")) { - link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; - } else if (policy && not strcmp(policy, "FATPIPE")) { - link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE; - } else { - link.policy = simgrid::s4u::Link::SharingPolicy::SHARED; - } + link.policy = link_policy_get_by_name(policy); sg_platf_new_link(&link); routing_cluster_add_backbone(simgrid::kernel::resource::LinkImpl::byName(link.id)); @@ -267,16 +272,7 @@ int console_add_link(lua_State *L) { lua_gettable(L, -2); policy = lua_tostring(L, -1); lua_pop(L, 1); - if (policy && not strcmp(policy, "FULLDUPLEX")) { - XBT_WARN("Please update your platform to use SPLITDUPLEX instead of FULLDUPLEX"); - link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; - } else if (policy && not strcmp(policy, "SPLITDUPLEX")) { - link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; - } else if (policy && not strcmp(policy, "FATPIPE")) { - link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE; - } else { - link.policy = simgrid::s4u::Link::SharingPolicy::SHARED; - } + link.policy = link_policy_get_by_name(policy); sg_platf_new_link(&link);