Skip to content

Commit 2ee0959

Browse files
author
Daniel Kroening
committed
mstream manipulators are now static
This matches what clang/gcc's STL implementations do; the key benefit is that the methods/members for the manipulators can now be static.
1 parent 8dbe79f commit 2ee0959

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

src/util/message.h

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,6 @@ class messaget
240240
return *this;
241241
}
242242

243-
// for feeding in manipulator functions such as eom
244-
mstreamt &operator << (mstreamt &(*func)(mstreamt &))
245-
{
246-
return func(*this);
247-
}
248-
249243
private:
250244
void assign_from(const mstreamt &other)
251245
{
@@ -259,7 +253,13 @@ class messaget
259253

260254
// Feeding 'eom' into the stream triggers
261255
// the printing of the message
262-
static mstreamt &eom(mstreamt &m)
256+
class eomt
257+
{
258+
};
259+
260+
static eomt eom;
261+
262+
friend mstreamt &operator<<(mstreamt &m, eomt)
263263
{
264264
if(m.message.message_handler)
265265
{
@@ -275,55 +275,64 @@ class messaget
275275
return m;
276276
}
277277

278-
// in lieu of std::endl
279-
static mstreamt &endl(mstreamt &m)
278+
class commandt
280279
{
281-
static_cast<std::ostream &>(m) << std::endl;
282-
return m;
280+
public:
281+
commandt(unsigned _command) : command(_command)
282+
{
283+
}
284+
285+
unsigned command;
286+
};
287+
288+
/// feed a command into an mstreamt
289+
friend mstreamt &operator<<(mstreamt &m, const commandt &c)
290+
{
291+
if(m.message.message_handler)
292+
return m << m.message.message_handler->command(c.command);
293+
else
294+
return m;
283295
}
284296

285297
/// \brief Create an ECMA-48 SGR (Select Graphic Rendition) command.
286-
std::string command(unsigned c) const
298+
static commandt command(unsigned c)
287299
{
288-
if(message_handler)
289-
return message_handler->command(c);
290-
else
291-
return std::string();
300+
return commandt(c);
292301
}
293302

294303
/// return to default formatting,
295304
/// as defined by the terminal
296-
std::string reset() const
305+
static commandt reset()
297306
{
298307
return command(0);
299308
}
300309

301310
/// render text with red foreground color
302-
std::string red() const
311+
static commandt red()
303312
{
304313
return command(31);
305314
}
306315

307316
/// render text with green foreground color
308-
std::string green() const
317+
static commandt green()
309318
{
310319
return command(32);
311320
}
312321

313322
/// render text with yellow foreground color
314-
std::string yellow() const
323+
static commandt yellow()
315324
{
316325
return command(33);
317326
}
318327

319328
/// render text with blue foreground color
320-
std::string blue() const
329+
static commandt blue()
321330
{
322331
return command(34);
323332
}
324333

325334
/// render text with bold font
326-
std::string bold() const
335+
static commandt bold()
327336
{
328337
return command(1);
329338
}

0 commit comments

Comments
 (0)