richelbilderbeek / djog_unos_2018

Project by the Uno's at DJOG 2018-2019: Nature Zen
GNU General Public License v3.0
6 stars 2 forks source link

Simplfy 'to_str(tile_type t)' by using a std::map #556

Closed richelbilderbeek closed 5 years ago

richelbilderbeek commented 5 years ago

Is your feature request related to a problem? Please describe.

Currently, we have:

std::string to_str(tile_type t) //!OCLINT cannot be simpler
{
  switch (t)
  {
    case tile_type::arctic: return "arctic";
    // ...
    case tile_type::woods: return "woods";
  }
  assert(!"Should not get here"); //!OCLINT acceptable idiom
  return "";
}

The OCLint tag is wrong. Take a look at to_tile:

tile_type to_tile(std::string str)
{
  const std::map<std::string, tile_type> m{
    { "arctic", tile_type::arctic},
    // ...
    { "beach", tile_type::beach}
  };
  //This assert will fail if the string is not in the map
  assert(m.find(str) != std::end(m));
  return m.find(str)->second;
}

Describe the solution you'd like

Apply the approach used in to_tile in to_str. All tests should still pass. OCLint tag must be removed, iff allowed by OCLint.

Describe alternatives you've considered

None.

Additional context

None.

richelbilderbeek commented 5 years ago

I see in a Travis log, this build failed on the enzo branch. Try to understand and fix this. Ask a medior if you need help. Good luck :+1:

richelbilderbeek commented 5 years ago

Well done :+1: