CLIParser.h
branchv_0
changeset 5 ee4ba9f5a053
parent 0 bb715a82a8f1
child 6 fd93a46db15b
equal deleted inserted replaced
4:9aba96f0b001 5:ee4ba9f5a053
    24 
    24 
    25 class CLIParser {
    25 class CLIParser {
    26 private:
    26 private:
    27 
    27 
    28 	static const std::string OPTION_TEXTURE;
    28 	static const std::string OPTION_TEXTURE;
       
    29 	static const std::string OPTION_SHADER;
    29 	static const std::string OPTION_BACKGROUND_COLOR;
    30 	static const std::string OPTION_BACKGROUND_COLOR;
    30 	static const std::string OPTION_ROOT_WINDOW;
    31 	static const std::string OPTION_ROOT_WINDOW;
    31 
    32 
    32 	const std::string
    33 	const std::string
    33 	readNext(const std::vector<std::string>& arguments, int& i) {
    34 	readNext(const std::vector<std::string>& arguments, int& i) {
    68 
    69 
    69 			if (option == OPTION_TEXTURE) {
    70 			if (option == OPTION_TEXTURE) {
    70 				Configuration::Texture tex;
    71 				Configuration::Texture tex;
    71 				tex.fileName = readNext(arguments, i);
    72 				tex.fileName = readNext(arguments, i);
    72 				c.textures.push_back(tex);
    73 				c.textures.push_back(tex);
       
    74 			} else if (option == OPTION_SHADER) {
       
    75 				const auto type = readNext(arguments, i);
       
    76 				const auto file = readNext(arguments, i);
       
    77 				if (type == "fragment") c.fragmentShaders.push_back({file});
       
    78 				else if (type == "vertex") c.vertexShaders .push_back({file});
       
    79 				else throw std::invalid_argument("unsupported shader type");
    73 			} else if (option == OPTION_BACKGROUND_COLOR) {
    80 			} else if (option == OPTION_BACKGROUND_COLOR) {
    74 				c.backgroundColor = parseHexColor(readNext(arguments, i));
    81 				c.backgroundColor = parseHexColor(readNext(arguments, i));
    75 			} else if (option == OPTION_ROOT_WINDOW) {
    82 			} else if (option == OPTION_ROOT_WINDOW) {
    76 				c.rootWindow = std::stoul(readNext(arguments, i));
    83 				c.rootWindow = std::stoul(readNext(arguments, i));
    77 			} else throw std::logic_error("Unsupported CLI option: " + option);
    84 			} else throw std::logic_error("Unsupported CLI option: " + option);
    80 		return c;
    87 		return c;
    81 	}
    88 	}
    82 };
    89 };
    83 
    90 
    84 const std::string CLIParser::OPTION_TEXTURE = "--texture";
    91 const std::string CLIParser::OPTION_TEXTURE = "--texture";
       
    92 const std::string CLIParser::OPTION_SHADER = "--shader";
    85 const std::string CLIParser::OPTION_BACKGROUND_COLOR = "--background-color";
    93 const std::string CLIParser::OPTION_BACKGROUND_COLOR = "--background-color";
    86 const std::string CLIParser::OPTION_ROOT_WINDOW = "--root-window";
    94 const std::string CLIParser::OPTION_ROOT_WINDOW = "--root-window";