Advertisement
Guest User

ConfigValidator.h

a guest
Oct 17th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #ifndef CONFIGVALIDATOR_H
  2. #define CONFIGVALIDATOR_H
  3. /* C system icnludes */
  4.  
  5. /* C++ system icnludes */
  6. #include <iostream>
  7. #include <string>
  8.  
  9. /* Third-party icnludes */
  10.  
  11. /* Own icnludes */
  12.  
  13. /* Forward Declaration */
  14. #include "sdl_utils/config/MonitorConfig.h"
  15.  
  16. class ConfigValidator {
  17. public:
  18.     static int32_t checkConfig(const std::string &configValue, configType type) {
  19.         if (configValue == "") {
  20.             std::cerr << "Configuration value is empty. " << std::endl;
  21.             return EXIT_FAILURE;
  22.         }
  23.  
  24.         switch (type) {
  25.         case INT:
  26.             if (!stoi(configValue)) {
  27.                 std::cerr << "Configuration type Integer is with wrong value: " << configValue << std::endl;
  28.                 return EXIT_FAILURE;
  29.             }
  30.             break;
  31.         case STRING:
  32.             // n/a
  33.             break;
  34.         case BOOLEAN:
  35.             if (configValue != "1" || configValue != "0") {
  36.                 std::cerr << "Configuration type Boolean is with wrong value: " << configValue << std::endl;
  37.                 return EXIT_FAILURE;
  38.             }
  39.             break;
  40.         default:
  41.             std::cerr << "Wrong configType passed to switch statment. Type value: " << type << std::endl;
  42.             return EXIT_FAILURE;
  43.             break;
  44.         }
  45.         return EXIT_SUCCESS;
  46.     }
  47. };
  48.  
  49. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement