indent.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "indent.hpp"
  2. #include <ostream>
  3. #include <iostream>
  4. using namespace std ;
  5. namespace xios
  6. {
  7. Cindent iendl ;
  8. Cindent ireset(0,true) ;
  9. int Cindent::defaultIncSize=2 ;
  10. int Cindent::index=ios::xalloc() ;
  11. Cindent::Cindent(int i,bool r) : offset(i), reset(r), incSize(defaultIncSize)
  12. { }
  13. Cindent Cindent::operator++()
  14. {
  15. return Cindent(incSize) ;
  16. }
  17. Cindent Cindent::operator--()
  18. {
  19. return Cindent(-incSize) ;
  20. }
  21. Cindent Cindent::operator++(int)
  22. {
  23. return Cindent(incSize) ;
  24. }
  25. Cindent Cindent::operator--(int)
  26. {
  27. return Cindent(-incSize) ;
  28. }
  29. Cindent Cindent::operator+=(int i)
  30. {
  31. return Cindent(incSize*i) ;
  32. }
  33. Cindent Cindent::operator-=(int i)
  34. {
  35. return Cindent(-incSize*i) ;
  36. }
  37. ostream& Cindent::iendl(ostream& o) const
  38. {
  39. if (reset)
  40. {
  41. o.iword(index)=0 ;
  42. return o ;
  43. }
  44. else
  45. {
  46. o.iword(index)+=offset ;
  47. if (o.iword(index)<0) o.iword(index)=0 ;
  48. o<<"\n" ;
  49. int mem=o.width(o.iword(index)) ;
  50. o<<"";
  51. o.width(mem) ;
  52. return o ;
  53. }
  54. }
  55. ostream& operator <<(ostream& o, const Cindent& indent)
  56. {
  57. return indent.iendl(o) ;
  58. }
  59. }