Project

General

Profile

Actions

Task #1531

closed

Change the return type of lookup method

Added by Yingdi Yu over 11 years ago. Updated over 11 years ago.

Status:
Closed
Priority:
High
Target version:
-
Start date:
04/23/2014
Due date:
% Done:

100%

Estimated time:

Description

For methods like this:

std::pair<NameLsa&, bool>
Lsdb::getNameLsa(string key)
{
  std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
                                                 m_nameLsdb.end(),
                                                 bind(nameLsaCompareByKey, _1, key));
  if (it != m_nameLsdb.end())
  {
    return std::make_pair(boost::ref((*it)), true);
  }
  NameLsa nlsa;
  return std::make_pair(boost::ref(nlsa), false);
}

We do not need to return std::pair. The purpose of the method is to lookup a NameLsa in Lsdb. It would be reasonable to return just a pointer to NameLsa or an empty pointer if the NameLsa does not exist.

Given this is a lookup method, it would be better to name it as findNameLsa rather than getNameLsa.

Also, the parameter key, as suggested by its name, should not be changed during the lookup process. In this case, please use const std::string&.

Similar issues appear in many places in the code, please fix them as well.

Actions

Also available in: Atom PDF