Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "printers.hpp"
- #include <stdexcept>
- #include <utility>
- #include <string>
- StringPrinter::Stringprinter(std::ostream& o = std::cour) : os(o) { }
- Printers::Printers() {
- }
- Printers::Printers(const Printers& target) {
- for( auto it = target.index.begin(); it != target.index.end(); it++ ) {
- StringPrinter*foo = new StringPrinter;
- index.emplace( (*it).first, std::get<1>(*it));
- }
- }
- Printers::~Printers() {
- }
- void Printers::add(const std::string& printerName, StringPrinter* printerPtr) {
- if(index.find(printerName) != index.end()) {
- throw std::invalid_argument("Duplicate index");
- }
- if(printerPtr == NULL) {
- throw std::invalid_argument("Invalid printer");
- }
- index.emplace(printerName, printerPtr);
- }
- StringPrinter& Printers::operator[](const std::string& printerName) {
- if(index.find(printerName) == index.end()) {
- throw std::invalid_argument("Unknown index");
- }
- return *(index.find(printerName)->second);
- }
- Printers& Printers::operator=(const Printers& target) {
- index = target.index;
- return *(this);
- }
- StringPrinter& DiagonalPrinter::operator()(const std::string &str) {
- if(first != "")
- os << first;
- for( auto it = str.cbegin(); it != str.cend(); it++) {
- int before = std::distance(str.begin(), it);
- int after = std::distance(str.end(), it);
- char space = ' ';
- os << std::string(before, space) << *it << std::string(after, space) << std::endl;
- }
- if(last != "")
- os << last;
- return *this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement