@@ -109,7 +109,8 @@ class outputStream : public CHeapObjBase {
109
109
// line starts depending on the current indentation level:
110
110
// print(), print_cr(), print_raw(), print_raw_cr()
111
111
// Other APIs are unaffected
112
- void set_autoindent (bool value) { _autoindent = value; }
112
+ // Returns old autoindent state.
113
+ bool set_autoindent (bool value);
113
114
114
115
// sizing
115
116
int position () const { return _position; }
@@ -175,17 +176,26 @@ class outputStream : public CHeapObjBase {
175
176
extern outputStream* tty; // tty output
176
177
177
178
class streamIndentor : public StackObj {
178
- private:
179
- outputStream* _str;
180
- int _amount;
181
-
182
- public:
179
+ outputStream* const _str;
180
+ const int _amount;
181
+ NONCOPYABLE (streamIndentor);
182
+ public:
183
183
streamIndentor (outputStream* str, int amt = 2 ) : _str(str), _amount(amt) {
184
184
_str->inc (_amount);
185
185
}
186
186
~streamIndentor () { _str->dec (_amount); }
187
187
};
188
188
189
+ class StreamAutoIndentor : public StackObj {
190
+ outputStream* const _os;
191
+ const bool _old;
192
+ NONCOPYABLE (StreamAutoIndentor);
193
+ public:
194
+ StreamAutoIndentor (outputStream* os) :
195
+ _os (os), _old(os->set_autoindent (true )) {}
196
+ ~StreamAutoIndentor () { _os->set_autoindent (_old); }
197
+ };
198
+
189
199
// advisory locking for the shared tty stream:
190
200
class ttyLocker : StackObj {
191
201
friend class ttyUnlocker ;
0 commit comments