orotool/src/oro/shops.cpp

60 lines
1.6 KiB
C++
Raw Normal View History

2020-08-10 10:22:25 +00:00
/* Copyright 2020, Michele Santullo
* This file is part of orotool.
*
* Orotool is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Orotool is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Orotool. If not, see <http://www.gnu.org/licenses/>.
*/
2020-06-23 08:19:02 +00:00
#include "shops.hpp"
#include <stdexcept>
namespace oro {
2020-08-10 22:17:17 +00:00
ShopTypeWrapper::ShopTypeWrapper (int val) {
*this = val;
}
2020-06-23 08:19:02 +00:00
ShopTypeWrapper::ShopTypeWrapper (const std::string& str) {
*this = str;
}
2020-09-03 23:46:21 +00:00
ShopTypeWrapper::ShopTypeWrapper (std::string_view str) {
*this = str;
}
2020-08-10 22:17:17 +00:00
ShopTypeWrapper& ShopTypeWrapper::operator= (int val) {
if (static_cast<int>(ShopType::Vending) == val)
value = ShopType::Vending;
else if (static_cast<int>(ShopType::Buying) == val)
value = ShopType::Buying;
else
value = ShopType::Unknown;
return *this;
}
2020-06-23 08:19:02 +00:00
ShopTypeWrapper& ShopTypeWrapper::operator= (const std::string& str) {
2020-09-03 23:46:21 +00:00
return this->operator=(std::string_view(str));
}
ShopTypeWrapper& ShopTypeWrapper::operator= (std::string_view str) {
2020-06-23 08:19:02 +00:00
if ("V" == str)
value = ShopType::Vending;
else if ("B" == str)
value = ShopType::Buying;
else
2020-09-03 23:46:21 +00:00
throw std::runtime_error("Unknown shop type '" + std::string(str) + "'");
2020-06-23 08:19:02 +00:00
return *this;
}
} //namespace oro