reseting isreams

This commit is contained in:
Johannes Wendel
2019-08-08 23:58:45 +02:00
parent 9cc3a7eb91
commit 8cb117dca6
6 changed files with 27 additions and 17 deletions

View File

@@ -53,6 +53,7 @@ std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& solenoid_config,
std::map<std::string, std::shared_ptr<items::Solenoid>> create_solenoids(std::istream & solenoid_config, std::shared_ptr<DriverBoardPinController> &pin_controller)
{
solenoid_config.clear();
json solenoid_config_json;
solenoid_config >> solenoid_config_json;
@@ -74,6 +75,7 @@ std::map<std::string, std::shared_ptr<items::Solenoid>> create_solenoids(std::is
std::shared_ptr<items::detail::Solenoid> create_solenoid(nlohmann::json &solenoid_json, nlohmann::json &port_extenders, std::shared_ptr<DriverBoardPinController> &pin_controller, std::chrono::milliseconds deactivation_time)
{
solenoid_json.clear();
std::string config_file_name = "solenoid_config.json";
uint8_t pin_base = get_pin_base(solenoid_json, port_extenders, config_file_name);
@@ -91,6 +93,7 @@ std::shared_ptr<items::detail::Solenoid> create_solenoid(nlohmann::json &solenoi
std::map<std::string, std::shared_ptr<items::Flipper>> create_flippers(std::istream &solenoid_config, std::shared_ptr<DriverBoardPinController> &pin_controller)
{
solenoid_config.clear();
json solenoid_config_json;
solenoid_config >> solenoid_config_json;
@@ -121,6 +124,7 @@ std::shared_ptr<items::detail::Flipper> create_flipper(nlohmann::json &flipper_j
std::map<std::string, std::shared_ptr<items::Lamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<DriverBoardPinController> &pin_controller)
{
lamp_config.clear();
json lamp_config_json;
lamp_config >> lamp_config_json;
@@ -152,6 +156,7 @@ std::shared_ptr<items::detail::Lamp> create_lamp(json &lamp_json, json & port_ex
std::map<std::string, std::shared_ptr<items::Sound>> create_sounds(std::istream &sound_config, std::shared_ptr<SoundBoardPinController> &pin_controller)
{
sound_config.clear();
json sound_config_json;
sound_config >> sound_config_json;
@@ -186,6 +191,7 @@ std::shared_ptr<items::detail::Sound> create_sound(json &sound_json, json &port_
uint8_t get_sound_fire_address(std::istream &sound_config)
{
sound_config.clear();
json sound_config_json;
sound_config >> sound_config_json;
@@ -200,6 +206,7 @@ uint8_t get_sound_fire_address(std::istream &sound_config)
std::map<std::string, uint8_t> parse_pins_display_board(std::istream &display_config)
{
display_config.clear();
std::string config_file = "display_config.json";
json display_config_json;
@@ -233,7 +240,7 @@ std::map<std::string, uint8_t> parse_pins_display_board(std::istream &display_co
std::vector<std::shared_ptr<items::OutputDisplay>> create_displays(std::istream &display_config)
{
display_config.clear();
json display_config_json;
display_config >> display_config_json;
@@ -259,7 +266,7 @@ std::shared_ptr<items::OutputDisplay> create_display(json & display_json)
return std::make_shared<items::detail::EightDigitDisplay>(address, id);
else if(digits == 7)
return std::make_shared<items::detail::SevenDigitDisplay>(address, id);
return std::make_shared<items::detail::SevenDigitDisplcreatay>(address, id);
else
throw new std::logic_error("Display digits can either be 7 or 8");
@@ -314,7 +321,6 @@ json get_element(const std::string & name, json & object, const std::string & fi
try
{
sub_object = object.at(name);
return sub_object;
}
catch(json::exception &e)
{
@@ -322,21 +328,23 @@ json get_element(const std::string & name, json & object, const std::string & fi
exit(EXIT_FAILURE);
}
return sub_object;
}
template<typename type>
type get_value(const std::string & name, json & object, const std::string & file_name)
{
type element;
try
{
type element = object.at(name).get<type>();
return element;
element = object.at(name).get<type>();
}
catch(json::exception &e)
{
CLOG(ERROR, OUTPUT_LOGGER) << "File " << file_name << " seems to be corrupted at " << name << ": " << e.what();
exit(EXIT_FAILURE);
}
return element;
}
}