Output.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef MY_OUTPUT_H
  2. #define MY_OUTPUT_H
  3. #include <cstdio>
  4. #include <iostream>
  5. #include <sstream>
  6. #include <string>
  7. class Output
  8. {
  9. static unsigned int pos;
  10. public:
  11. /* begin a line */
  12. static void Begin()
  13. {
  14. pos += 2;
  15. fprintf(stderr, "* ");
  16. }
  17. /* print a string */
  18. static void Print(std::string x)
  19. {
  20. pos += x.length();
  21. fprintf(stderr, "%s", x.c_str());
  22. }
  23. /* print c, cnt times */
  24. static void Repeat(int cnt, char c)
  25. {
  26. pos += cnt;
  27. for(int i = 0; i < cnt; i++) fprintf(stderr, "%c", c);
  28. }
  29. /* end the line */
  30. static void End()
  31. {
  32. Position(79);
  33. fprintf(stderr, " *\n");
  34. pos = 0;
  35. }
  36. /* position the stream upto, but excluding p */
  37. static void Position(unsigned int p)
  38. {
  39. if(p < pos) return;
  40. for(unsigned int i = pos; i < p; i++) fprintf(stderr, " ");
  41. pos = p - 1;
  42. }
  43. /* write a s after cnt spaces */
  44. static void WriteLn(int cnt, std::string s)
  45. {
  46. Begin();
  47. Repeat(cnt,' ');
  48. Print(s);
  49. End();
  50. }
  51. /* write a blank line */
  52. static void Ln()
  53. {
  54. Begin();
  55. End();
  56. }
  57. };
  58. #endif /* MY_OUTPUT */