| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (C) 2009, 2010 by Thomas Moulard, CNRS. | ||
| 2 | // | ||
| 3 | |||
| 4 | // Redistribution and use in source and binary forms, with or without | ||
| 5 | // modification, are permitted provided that the following conditions are | ||
| 6 | // met: | ||
| 7 | // | ||
| 8 | // 1. Redistributions of source code must retain the above copyright | ||
| 9 | // notice, this list of conditions and the following disclaimer. | ||
| 10 | // | ||
| 11 | // 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | // notice, this list of conditions and the following disclaimer in the | ||
| 13 | // documentation and/or other materials provided with the distribution. | ||
| 14 | // | ||
| 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 19 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
| 26 | // DAMAGE. | ||
| 27 | |||
| 28 | #include "hpp/util/indent.hh" | ||
| 29 | |||
| 30 | #include <cassert> | ||
| 31 | #include <iomanip> | ||
| 32 | #include <ostream> | ||
| 33 | |||
| 34 | namespace hpp { | ||
| 35 | 789 | inline long& indent(std::ostream& o) { | |
| 36 | // The slot to store the current indentation level. | ||
| 37 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 787 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
789 | static const int indent_index = std::ios::xalloc(); |
| 38 | 789 | return o.iword(indent_index); | |
| 39 | } | ||
| 40 | |||
| 41 | 222 | std::ostream& incindent(std::ostream& o) { | |
| 42 | 222 | indent(o) += 2; | |
| 43 | 222 | return o; | |
| 44 | } | ||
| 45 | |||
| 46 | 222 | std::ostream& decindent(std::ostream& o) { | |
| 47 | 222 | long& ind = indent(o); | |
| 48 |
1/2✓ Branch 0 taken 222 times.
✗ Branch 1 not taken.
|
222 | if (ind >= 2) |
| 49 | 222 | indent(o) -= 2; | |
| 50 | else | ||
| 51 | ✗ | ind = 0; | |
| 52 | 222 | return o; | |
| 53 | } | ||
| 54 | |||
| 55 | ✗ | std::ostream& resetindent(std::ostream& o) { | |
| 56 | ✗ | indent(o) = 0; | |
| 57 | ✗ | return o; | |
| 58 | } | ||
| 59 | |||
| 60 | 123 | std::ostream& iendl(std::ostream& o) { | |
| 61 | 123 | o << std::endl; | |
| 62 | // Be sure to be able to restore the stream flags. | ||
| 63 | 123 | char fill = o.fill(' '); | |
| 64 | 123 | return o << std::setw((int)indent(o)) << "" << std::setfill(fill); | |
| 65 | } | ||
| 66 | |||
| 67 | ✗ | std::ostream& incendl(std::ostream& o) { return o << incindent << iendl; } | |
| 68 | |||
| 69 | ✗ | std::ostream& decendl(std::ostream& o) { return o << decindent << iendl; } | |
| 70 | |||
| 71 | } // end of namespace hpp. | ||
| 72 |