Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct FilterConfig {
- std::string name;
- std::vector<std::string> arguments;
- };
- struct ParserResults {
- std::string input_path;
- std::string output_path;
- std::vector<FilterConfig> filters;
- };
- ParserResults Parse(int argc, char *argv[]) {
- ParserResults parser_results;
- parser_results.input_path = argv[1];
- parser_results.output_path = argv[2];
- FilterConfig config;
- for (int index = 3; index < argc; ++index) {
- if (argv[index][0] == '-') {
- // не забыть добавить конфиг
- config.name = std::string(argv[index]).substr(1);
- }
- // доделать остальную логику
- }
- return parser_results;
- }
- class Image {
- //
- };
- class Filter {
- public:
- virtual Image Apply(const Image &image) = 0;
- };
- class FilterWithMatrix : public Filter {
- private:
- std::vector<std::vector<int>> matrix_;
- };
- class Crop : public Filter {
- public:
- Crop(size_t height, size_t width) : heigth_(height), width_(width) {}
- Image Apply(const Image &image) {
- // логика работы фильтра
- return image;
- }
- private:
- size_t heigth_;
- size_t width_;
- };
- // можно сделать отдельную функцию CreateFilter, которая будет выкидывать исключение, которое потом уже будет обрабатываться в CreateFilters
- std::vector<std::shared_ptr<Filter>> CreateFilters(const std::vector<FilterConfig> &filter_configs) {
- std::vector<std::shared_ptr<Filter>> filters;
- for (const auto& config: filter_configs) {
- if (config.name == "crop" && config.arguments.size() == 2) {
- if (config.arguments.size() != 2) {
- std::cerr << "Invalid amount arguments for crop\n";
- continue;
- }
- size_t heigth, width;
- try {
- heigth = std::stoull(config.arguments[0]);
- width = std::stoull(config.arguments[1]);
- } catch (std::invalid_argument& exc) {
- std::cerr << "Invalid argument for crop\n";
- continue;
- }
- filters.push_back(std::make_shared<Crop>(heigth, width);
- }
- }
- return filters;
- }
- Image ApplyFilters(Image image, const std::vector<std::shared_ptr<Filter>>& filters) {
- for (const auto& filter: filters) {
- image = filter->Apply(image);
- }
- return image;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement