QwAnalysis
QwColor Class Reference

A color changing class for the output stream. More...

#include <QwColor.h>

Public Member Functions

 QwColor (const Qw::EQwColor f=Qw::kDefaultForeground, const Qw::EQwColor b=Qw::kDefaultBackground)
 Default constructor. More...
 
virtual ~QwColor ()
 

Static Protected Member Functions

static QwColorMap CreateColorMap ()
 

Static Protected Attributes

static QwColorMap kColorMap = QwColor::CreateColorMap()
 

Private Attributes

Qw::EQwColor foreground
 Foreground color. More...
 
Qw::EQwColor background
 Background color (not yet supported) More...
 

Friends

std::ostream & operator<< (std::ostream &out, const QwColor &color)
 Output stream operator. More...
 

Detailed Description

A color changing class for the output stream.

This class changes the color in the output stream by inserting 'magic' escape sequences that are interpreted by smart terminals. On dumb terminals this will probably just print garbage. To use the color, a QwColor object should be streamed to the output stream:

* QwMessage << "Hello, " << QwColor(Qw::kRed) << "Qweak!" << QwLog::endl;
*

Definition at line 98 of file QwColor.h.

Constructor & Destructor Documentation

QwColor::QwColor ( const Qw::EQwColor  f = Qw::kDefaultForeground,
const Qw::EQwColor  b = Qw::kDefaultBackground 
)
inline

Default constructor.

Definition at line 103 of file QwColor.h.

104  : foreground(f), background(b) { };
Qw::EQwColor foreground
Foreground color.
Definition: QwColor.h:147
Qw::EQwColor background
Background color (not yet supported)
Definition: QwColor.h:148
virtual QwColor::~QwColor ( )
inlinevirtual

Definition at line 105 of file QwColor.h.

105 { };

Member Function Documentation

static QwColorMap QwColor::CreateColorMap ( )
inlinestaticprotected

Definition at line 112 of file QwColor.h.

References BACKBLUE, BACKGREEN, BACKRED, BLACK, BLUE, BOLD, BOLDBLUE, BOLDBROWN, BOLDCYAN, BOLDGREEN, BOLDMAGENTA, BOLDRED, BOLDWHITE, BROWN, CYAN, GREEN, Qw::kBackBlue, Qw::kBackGreen, Qw::kBackRed, Qw::kBlack, Qw::kBlue, Qw::kBold, Qw::kBoldBlue, Qw::kBoldBrown, Qw::kBoldCyan, Qw::kBoldGreen, Qw::kBoldMagenta, Qw::kBoldRed, Qw::kBoldWhite, Qw::kBrown, Qw::kCyan, Qw::kDefaultBackground, Qw::kDefaultForeground, Qw::kGreen, Qw::kMagenta, Qw::kNormal, Qw::kRed, Qw::kWhite, MAGENTA, NORMAL, RED, and WHITE.

112  {
113  QwColorMap map;
114  map[Qw::kBlack] = BLACK;
115  map[Qw::kRed] = RED;
116  map[Qw::kGreen] = GREEN;
117  map[Qw::kBrown] = BROWN;
118  map[Qw::kBlue] = BLUE;
119  map[Qw::kMagenta] = MAGENTA;
120  map[Qw::kCyan] = CYAN;
121  map[Qw::kWhite] = WHITE;
122  //
123  map[Qw::kBold] = BOLD;
124  //
125  map[Qw::kBoldRed] = BOLDRED;
126  map[Qw::kBoldGreen] = BOLDGREEN;
127  map[Qw::kBoldBrown] = BOLDBROWN;
128  map[Qw::kBoldBlue] = BOLDBLUE;
130  map[Qw::kBoldCyan] = BOLDCYAN;
131  map[Qw::kBoldWhite] = BOLDWHITE;
132  //
133  map[Qw::kBackRed] = BACKRED;
134  map[Qw::kBackGreen] = BACKGREEN;
135  map[Qw::kBackBlue] = BACKBLUE;
136  //
137  map[Qw::kDefaultForeground] = "\033[39m";
138  map[Qw::kDefaultBackground] = "\033[49m";
139  //
140  map[Qw::kNormal] = NORMAL;
141  return map;
142  };
#define WHITE
Definition: QwColor.h:35
#define BLACK
Definition: QwColor.h:28
#define BOLDGREEN
Definition: QwColor.h:48
#define BOLD
Definition: QwColor.h:37
#define BOLDCYAN
Definition: QwColor.h:52
#define CYAN
Definition: QwColor.h:34
#define BACKRED
Definition: QwColor.h:55
#define BACKBLUE
Definition: QwColor.h:57
#define BOLDBROWN
Definition: QwColor.h:49
#define GREEN
Definition: QwColor.h:30
#define RED
Definition: QwColor.h:29
#define BOLDMAGENTA
Definition: QwColor.h:51
#define BLUE
Definition: QwColor.h:32
#define BOLDBLUE
Definition: QwColor.h:50
#define BOLDRED
Definition: QwColor.h:47
#define NORMAL
Definition: QwColor.h:61
#define MAGENTA
Definition: QwColor.h:33
#define BOLDWHITE
Definition: QwColor.h:53
#define BACKGREEN
Definition: QwColor.h:56
#define BROWN
Definition: QwColor.h:31
std::map< Qw::EQwColor, std::string > QwColorMap
Definition: QwColor.h:83

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const QwColor color 
)
friend

Output stream operator.

Definition at line 153 of file QwColor.h.

154 {
155  return out << color.kColorMap[color.foreground];
156 }
Qw::EQwColor foreground
Foreground color.
Definition: QwColor.h:147
static QwColorMap kColorMap
Definition: QwColor.h:142

Field Documentation

Qw::EQwColor QwColor::background
private

Background color (not yet supported)

Definition at line 148 of file QwColor.h.

Qw::EQwColor QwColor::foreground
private

Foreground color.

Definition at line 147 of file QwColor.h.

Referenced by operator<<().

QwColorMap QwColor::kColorMap = QwColor::CreateColorMap()
staticprotected

Definition at line 142 of file QwColor.h.

Referenced by operator<<().


The documentation for this class was generated from the following files: