Created
July 7, 2020 19:22
-
-
Save sweethuman/77102b394024c4f999f2ad2c4ddf9590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by sweethuman on 20.06.2020. | |
// | |
#ifndef EEEEEEWWW_STUFF_H | |
#define EEEEEEWWW_STUFF_H | |
#include <iostream> | |
#include <regex> | |
#include <string> | |
class Checker; | |
class Section { | |
private: | |
friend class Checker; | |
friend class TitleChecker; | |
friend class ContentChecker; | |
protected: | |
std::string title; | |
std::string content; | |
Checker *checker; | |
public: | |
Section(std::string title, std::string content, Checker *checker) | |
: title(title), content(content), checker(checker) { | |
} | |
virtual void addSection(Section *s) = 0; | |
virtual void generate(); | |
}; | |
class Chapter : public Section { | |
private: | |
std::vector<Section *> sections; | |
public: | |
Chapter(std::string title, std::string content, Checker *checker) | |
: Section(title, content, checker) { | |
} | |
void addSection(Section *s) override { | |
sections.push_back(s); | |
}; | |
void generate() override { | |
Section::generate(); | |
for(auto &s : sections){ | |
s->generate(); | |
} | |
} | |
}; | |
class Preface : public Section { | |
public: | |
Preface(std::string title, std::string content, Checker *checker) | |
: Section(title, content, checker) { | |
} | |
void addSection(Section *s) override{ | |
return; | |
}; | |
}; | |
class Checker { | |
public: | |
virtual bool check(Section *s) = 0; | |
}; | |
class TitleChecker : public Checker { | |
public: | |
bool check(Section *s) override { | |
return s->title.size() > 2; | |
}; | |
}; | |
class ContentChecker : public Checker { | |
public: | |
bool check(Section *s) override { | |
const std::regex base_regex("^([A-Z][^\\.]*\\. *)+"); | |
std::smatch base_match; | |
if (std::regex_match(s->content, base_match, base_regex)) { | |
if (base_match[0].length() == s->content.size()) { | |
return true; | |
} | |
} | |
return false; | |
}; | |
}; | |
class DoubleChecker : public Checker { | |
private: | |
Checker *check1, *check2; | |
public: | |
DoubleChecker(Checker *check1, Checker *check2) : check1(check1), check2(check2) { | |
} | |
bool check(Section *s) override { | |
return check1->check(s) && check2->check(s); | |
}; | |
}; | |
void Section::generate() { | |
if (checker->check(this)) { | |
std::cout << "Title: " << title << "\nContent: " << content << std::endl << std::endl; | |
} | |
}; | |
#endif // EEEEEEWWW_STUFF_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment