for (int i = 0; i < max; i++) {
if (i <= max_index_src && max <= max_index_dst) {
key = {path_src.at(i)->netpoint_, path_dst.at(max)->netpoint_};
- try {
- bypassedRoute = bypassRoutes_.at(key);
+ auto bpr = bypassRoutes_.find(key);
+ if (bpr != bypassRoutes_.end()) {
+ bypassedRoute = bpr->second;
break;
- } catch (std::out_of_range& unfound) {
- // Do nothing
}
}
if (max <= max_index_src && i <= max_index_dst) {
key = {path_src.at(max)->netpoint_, path_dst.at(i)->netpoint_};
- try {
- bypassedRoute = bypassRoutes_.at(key);
+ auto bpr = bypassRoutes_.find(key);
+ if (bpr != bypassRoutes_.end()) {
+ bypassedRoute = bpr->second;
break;
- } catch (std::out_of_range& unfound) {
- // Do nothing
}
}
}
if (max <= max_index_src && max <= max_index_dst) {
key = {path_src.at(max)->netpoint_, path_dst.at(max)->netpoint_};
- try {
- bypassedRoute = bypassRoutes_.at(key);
+ auto bpr = bypassRoutes_.find(key);
+ if (bpr != bypassRoutes_.end()) {
+ bypassedRoute = bpr->second;
break;
- } catch (std::out_of_range& unfound) {
- // Do nothing
}
}
}
}
/* Retrieve the private links */
- try {
- std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id());
+ auto src_link = privateLinks_.find(src->id());
+ if (src_link != privateLinks_.end()) {
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info = src_link->second;
if (info.first) {
route->link_list->push_back(info.first);
if (lat)
*lat += info.first->latency();
}
- } catch (std::out_of_range& unfound) {
+ } else {
XBT_DEBUG("Source of private link (%u) doesn't exist", src->id());
}
- try {
- std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(dst->id());
+ auto dst_link = privateLinks_.find(dst->id());
+ if (dst_link != privateLinks_.end()) {
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info = dst_link->second;
if (info.second) {
route->link_list->push_back(info.second);
if (lat)
*lat += info.second->latency();
}
- } catch (std::out_of_range& unfound) {
+ } else {
XBT_DEBUG("Destination of private link (%u) doesn't exist", dst->id());
}
/** @brief Retrieve the netpoint of the given name (or nullptr if not found) */
simgrid::kernel::routing::NetPoint* Engine::getNetpointByNameOrNull(const char* name)
{
- try {
- return pimpl->netpoints_.at(name);
- } catch (std::out_of_range& unfound) {
- return nullptr;
- }
+ auto netp = pimpl->netpoints_.find(name);
+ return netp == pimpl->netpoints_.end() ? nullptr : netp->second;
}
/** @brief Fill the provided vector with all existing netpoints */
void Engine::getNetpointList(std::vector<simgrid::kernel::routing::NetPoint*>* list)
}
Host* Host::by_name_or_null(std::string name)
{
- try {
- return host_list.at(name);
- } catch (std::out_of_range& unfound) {
- return nullptr;
- }
+ auto host = host_list.find(name);
+ return host == host_list.end() ? nullptr : host->second;
}
Host *Host::current(){
-/* Copyright (c) 2009-2016. The SimGrid Team.
+/* Copyright (c) 2009-2017. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
static SD_task_t current_child;
void STag_dax__child()
{
- try {
- current_child = jobs.at(A_dax__child_ref);
- } catch (std::out_of_range& unfound) {
+ auto job = jobs.find(A_dax__child_ref);
+ if (job != jobs.end()) {
+ current_child = job->second;
+ } else {
throw std::out_of_range(std::string("Parse error on line ") + std::to_string(dax_lineno) +
": Asked to add dependencies to the non-existent " + A_dax__child_ref + "task");
}
void STag_dax__parent()
{
- try {
- SD_task_t parent = jobs.at(A_dax__parent_ref);
+ auto job = jobs.find(A_dax__parent_ref);
+ if (job != jobs.end()) {
+ SD_task_t parent = job->second;
SD_task_dependency_add(nullptr, nullptr, parent, current_child);
XBT_DEBUG("Control-flow dependency from %s to %s", current_child->name, parent->name);
- } catch (std::out_of_range& unfound) {
+ } else {
throw std::out_of_range(std::string("Parse error on line ") + std::to_string(dax_lineno) +
": Asked to add a dependency from " + current_child->name + " to " + A_dax__parent_ref +
", but " + A_dax__parent_ref + " does not exist");
if ((performer != -1 && order != -1) && performer < static_cast<int>(sg_host_count())) {
/* required parameters are given and less performers than hosts are required */
XBT_DEBUG ("Task '%s' is scheduled on workstation '%d' in position '%d'", task->name, performer, order);
- try {
- computer = computers.at(char_performer);
- } catch (std::out_of_range& unfound) {
+ auto comp = computers.find(char_performer);
+ if (comp != computers.end()) {
+ computer = comp->second;
+ } else {
computer = new std::vector<SD_task_t>;
computers.insert({char_performer, computer});
}
/** @brief Returns the process from PID. */
smx_actor_t SIMIX_process_from_PID(aid_t PID)
{
- try {
- return simix_global->process_list.at(PID);
- } catch (std::out_of_range& unfound) {
- return nullptr;
- }
+ auto process = simix_global->process_list.find(PID);
+ return process == simix_global->process_list.end() ? nullptr : process->second;
}
/** @brief returns a dynar containing all currently existing processes */
*flag=0;
return MPI_SUCCESS;
}
- try {
- *static_cast<void**>(attr_value) = attributes()->at(keyval);
+ const auto& attribs = attributes();
+ auto attr = attribs->find(keyval);
+ if (attr != attribs->end()) {
+ *static_cast<void**>(attr_value) = attr->second;
*flag=1;
- }
- catch (const std::out_of_range& oor) {
+ } else {
*flag=0;
}
return MPI_SUCCESS;
if (not attributes()->empty()) {
int flag=0;
for(auto it : attributes_){
- try{
- smpi_key_elem elem = T::keyvals_.at(it.first);
+ auto elm = T::keyvals_.find(it.first);
+ if (elm != T::keyvals_.end()) {
+ smpi_key_elem elem = elm->second;
if(elem != nullptr){
call_deleter<T>((T*)this, elem, it.first,it.second,&flag);
}
- }catch(const std::out_of_range& oor) {
+ } else {
//already deleted, not a problem;
flag=0;
}
return MPI_COMM_WORLD;
} else if(F2C::f2c_lookup() != nullptr && id >= 0) {
char key[KEY_SIZE];
- try {
- return static_cast<MPI_Comm>(F2C::f2c_lookup()->at(get_key_id(key, id)));
- } catch (std::out_of_range& unfound) {
- return MPI_COMM_NULL;
- }
+ const auto& lookup = F2C::f2c_lookup();
+ auto comm = lookup->find(get_key_id(key, id));
+ return comm == lookup->end() ? MPI_COMM_NULL : static_cast<MPI_Comm>(comm->second);
} else {
return MPI_COMM_NULL;
}
if(id >= 0){
char key[KEY_SIZE];
- try {
- return f2c_lookup_->at(get_key(key, id));
- } catch (std::out_of_range& unfound) {
- return nullptr;
- }
+ auto comm = f2c_lookup_->find(get_key(key, id));
+ return comm == f2c_lookup_->end() ? nullptr : comm->second;
}else
return nullptr;
}
{
if (this == MPI_GROUP_EMPTY)
return MPI_UNDEFINED;
- try {
- return index_to_rank_map_.at(index);
- } catch (std::out_of_range& unfound) {
- return MPI_UNDEFINED;
- }
+ auto rank = index_to_rank_map_.find(index);
+ return rank == index_to_rank_map_.end() ? MPI_UNDEFINED : rank->second;
}
void Group::ref()
int Info::get(char *key, int valuelen, char *value, int *flag){
*flag=false;
- try {
- std::string tmpvalue = map_.at(key);
+ auto val = map_.find(key);
+ if (val != map_.end()) {
+ std::string tmpvalue = val->second;
memset(value, 0, valuelen);
memcpy(value, tmpvalue.c_str(),
(tmpvalue.length() + 1 < static_cast<size_t>(valuelen)) ? tmpvalue.length() + 1 : valuelen);
*flag=true;
return MPI_SUCCESS;
- } catch (std::out_of_range& unfound) {
+ } else {
return MPI_ERR_INFO_KEY;
}
}
int Info::get_valuelen(char *key, int *valuelen, int *flag){
*flag=false;
- try {
- *valuelen = map_.at(key).length();
+ auto val = map_.find(key);
+ if (val != map_.end()) {
+ *valuelen = val->second.length();
*flag=true;
return MPI_SUCCESS;
- } catch (std::out_of_range& unfound) {
+ } else {
return MPI_ERR_INFO_KEY;
}
}
location_ = st->getImpl();
std::map<std::string, sg_size_t>* content = location_->getContent();
// if file does not exist create an empty file
- try {
- size_ = content->at(path);
- } catch (std::out_of_range& unfound) {
+ auto sz = content->find(path);
+ if (sz != content->end()) {
+ size_ = sz->second;
+ } else {
size_ = 0;
content->insert({path, size_});
XBT_DEBUG("File '%s' was not found, file created.", path.c_str());
/* Check if the new full path is on the same mount point */
if (not strncmp(mount_point_.c_str(), fullpath, mount_point_.size())) {
std::map<std::string, sg_size_t>* content = location_->getContent();
- try { // src file exists
- sg_size_t new_size = content->at(path_);
+ auto sz = content->find(path_);
+ if (sz != content->end()) { // src file exists
+ sg_size_t new_size = sz->second;
content->erase(path_);
std::string path = std::string(fullpath).substr(mount_point_.size(), strlen(fullpath));
content->insert({path.c_str(), new_size});
XBT_DEBUG("Move file from %s to %s, size '%llu'", path_.c_str(), fullpath, new_size);
- } catch (std::out_of_range& unfound) {
+ } else {
XBT_WARN("File %s doesn't exist", path_.c_str());
}
} else {
-/* Copyright (c) 2015. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2015-2017. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
const char *PropertyHolder::getProperty(const char*key) {
if (properties_ == nullptr)
return nullptr;
- try {
- return properties_->at(key).c_str();
- } catch (std::out_of_range& unfound) {
- return nullptr;
- }
+ auto prop = properties_->find(key);
+ return prop == properties_->end() ? nullptr : prop->second.c_str();
}
/** @brief Change the value of a given key in the property set */
-/* Copyright (c) 2014-2015. The SimGrid Team.
+/* Copyright (c) 2014-2017. The SimGrid Team.
*All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
simgrid::surf::IBNode* act_src;
simgrid::surf::IBNode* act_dst;
- try {
- act_src = ibModel->active_nodes.at(src->getName());
- } catch (std::out_of_range& unfound) {
+ auto asrc = ibModel->active_nodes.find(src->getName());
+ if (asrc != ibModel->active_nodes.end()) {
+ act_src = asrc->second;
+ } else {
throw std::out_of_range(std::string("Could not find '") + src->getCname() + "' active comms !");
}
- try {
- act_dst = ibModel->active_nodes.at(dst->getName());
- } catch (std::out_of_range& unfound) {
+ auto adst = ibModel->active_nodes.find(dst->getName());
+ if (adst != ibModel->active_nodes.end()) {
+ act_dst = adst->second;
+ } else {
throw std::out_of_range(std::string("Could not find '") + dst->getCname() + "' active comms !");
}
-/* Copyright (c) 2013-2015. The SimGrid Team.
+/* Copyright (c) 2013-2017. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
LinkImpl* LinkImpl::byName(const char* name)
{
- try {
- return links->at(name);
- } catch (std::out_of_range& unfound) {
- return nullptr;
- }
+ auto link = links->find(name);
+ return link == links->end() ? nullptr : link->second;
}
/** @brief Returns the amount of links in the platform */
int LinkImpl::linksCount()
"Refusing to add a second storage named \"%s\"", storage->id.c_str());
simgrid::surf::StorageType* stype;
- try {
- stype = storage_types.at(storage->type_id);
- } catch (std::out_of_range& unfound) {
+ auto st = storage_types.find(storage->type_id);
+ if (st != storage_types.end()) {
+ stype = st->second;
+ } else {
xbt_die("No storage type '%s'", storage->type_id.c_str());
}
inline ConfigurationElement* Config::getDictElement(const char* name)
{
- try {
- return options.at(name);
- } catch (std::out_of_range& unfound) {
- try {
- ConfigurationElement* res = aliases.at(name);
+ auto opt = options.find(name);
+ if (opt != options.end()) {
+ return opt->second;
+ } else {
+ auto als = aliases.find(name);
+ if (als != aliases.end()) {
+ ConfigurationElement* res = als->second;
if (warn_for_aliases)
XBT_INFO("Option %s has been renamed to %s. Consider switching.", name, res->getKey().c_str());
return res;
- } catch (std::out_of_range& missing_key) {
+ } else {
throw simgrid::config::missing_key_error(std::string("Bad config key: ") + name);
}
}
} else {
// Else, I have to store it for the relevant colleague
std::queue<ReplayAction*>* otherqueue = nullptr;
- try {
- otherqueue = action_queues.at(evtname);
- } catch (std::out_of_range& unfound) { // Damn. Create the queue of that guy
+ auto act = action_queues.find(evtname);
+ if (act != action_queues.end()) {
+ otherqueue = act->second;
+ } else { // Damn. Create the queue of that guy
otherqueue = new std::queue<ReplayAction*>();
action_queues.insert({evtname, otherqueue});
}