Advertisement
Guest User

hpp

a guest
Oct 23rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include "printers.hpp"
  2.  
  3. #include <stdexcept>
  4. #include <utility>
  5. #include <string>
  6. StringPrinter::Stringprinter(std::ostream& o = std::cour) : os(o) { }
  7.  
  8. Printers::Printers() {
  9.  
  10. }
  11.  
  12. Printers::Printers(const Printers& target) {
  13. for( auto it = target.index.begin(); it != target.index.end(); it++ ) {
  14. StringPrinter*foo = new StringPrinter;
  15. index.emplace( (*it).first, std::get<1>(*it));
  16. }
  17.  
  18. }
  19.  
  20. Printers::~Printers() {
  21.  
  22. }
  23.  
  24. void Printers::add(const std::string& printerName, StringPrinter* printerPtr) {
  25. if(index.find(printerName) != index.end()) {
  26. throw std::invalid_argument("Duplicate index");
  27. }
  28. if(printerPtr == NULL) {
  29. throw std::invalid_argument("Invalid printer");
  30. }
  31. index.emplace(printerName, printerPtr);
  32. }
  33.  
  34. StringPrinter& Printers::operator[](const std::string& printerName) {
  35. if(index.find(printerName) == index.end()) {
  36. throw std::invalid_argument("Unknown index");
  37. }
  38. return *(index.find(printerName)->second);
  39. }
  40.  
  41.  
  42. Printers& Printers::operator=(const Printers& target) {
  43. index = target.index;
  44. return *(this);
  45. }
  46.  
  47. StringPrinter& DiagonalPrinter::operator()(const std::string &str) {
  48.  
  49. if(first != "")
  50. os << first;
  51. for( auto it = str.cbegin(); it != str.cend(); it++) {
  52.  
  53. int before = std::distance(str.begin(), it);
  54. int after = std::distance(str.end(), it);
  55. char space = ' ';
  56. os << std::string(before, space) << *it << std::string(after, space) << std::endl;
  57. }
  58. if(last != "")
  59. os << last;
  60. return *this;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement