| 1 | /*
|
| 2 | * IndentHandler.h
|
| 3 | *
|
| 4 | * This file is part of the XShaderCompiler project (Copyright (c) 2014-2017 by Lukas Hermanns)
|
| 5 | * See "LICENSE.txt" for license information.
|
| 6 | */
|
| 7 |
|
| 8 | #ifndef XSC_INDENT_HANDLER_H
|
| 9 | #define XSC_INDENT_HANDLER_H
|
| 10 |
|
| 11 |
|
| 12 | #include "Export.h"
|
| 13 | #include <string>
|
| 14 | #include <stack>
|
| 15 |
|
| 16 |
|
| 17 | namespace Xsc
|
| 18 | {
|
| 19 |
|
| 20 |
|
| 21 | /* ===== Public classes ===== */
|
| 22 |
|
| 23 | //! Indentation handler base class.
|
| 24 | class XSC_EXPORT IndentHandler
|
| 25 | {
|
| 26 |
|
| 27 | public:
|
| 28 |
|
| 29 | IndentHandler(const std::string& initialIndent = std::string(2, ' '));
|
| 30 |
|
| 31 | //! Sets the next indentation string. By default two spaces.
|
| 32 | void SetIndent(const std::string& indent);
|
| 33 |
|
| 34 | //! Increments the indentation.
|
| 35 | void IncIndent();
|
| 36 |
|
| 37 | //! Decrements the indentation.
|
| 38 | void DecIndent();
|
| 39 |
|
| 40 | //! Returns the current full indentation string.
|
| 41 | inline const std::string& FullIndent() const
|
| 42 | {
|
| 43 | return indentFull_;
|
| 44 | }
|
| 45 |
|
| 46 | private:
|
| 47 |
|
| 48 | std::string indent_;
|
| 49 | std::string indentFull_;
|
| 50 | std::stack<std::string::size_type> indentStack_;
|
| 51 |
|
| 52 | };
|
| 53 |
|
| 54 | //! Helper class for temporary indentation.
|
| 55 | class ScopedIndent
|
| 56 | {
|
| 57 |
|
| 58 | public:
|
| 59 |
|
| 60 | inline ScopedIndent(IndentHandler& handler) :
|
| 61 | handler_ { handler }
|
| 62 | {
|
| 63 | handler_.IncIndent();
|
| 64 | }
|
| 65 |
|
| 66 | inline ~ScopedIndent()
|
| 67 | {
|
| 68 | handler_.DecIndent();
|
| 69 | }
|
| 70 |
|
| 71 | private:
|
| 72 |
|
| 73 | IndentHandler& handler_;
|
| 74 |
|
| 75 | };
|
| 76 |
|
| 77 |
|
| 78 | } // /namespace Xsc
|
| 79 |
|
| 80 |
|
| 81 | #endif
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 | // ================================================================================ |