Color.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 Kamil Dudka <xdudka00@stud.fit.vutbr.cz>
00003  *
00004  * This file is part of nucad (Non-Uniform CA Designer).
00005  *
00006  * nucad is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * any later version.
00010  *
00011  * nucad is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with nucad.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00025 #include "Color.h"
00026 
00027 #include <iomanip>
00028 
00029 // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00030 // Color implementation
00031 bool Color::useColors = false;
00032 #ifndef BUILDING_DOX
00033 struct Color::Private {
00034     EColor            color;
00035 };
00036 #endif
00037 
00038 Color::Color(EColor color):
00039     d(new Private)
00040 {
00041     d->color = color;
00042 }
00043  
00044 Color::Color(const Color &cObj):
00045     d(new Private)
00046 {
00047     d->color = cObj.d->color;
00048 }
00049  
00050 Color::~Color() {
00051     delete d;
00052 }
00053  
00054 void Color::enable(bool b) {
00055     Color::useColors = b;
00056 }
00057  
00058 bool Color::isEnabled() {
00059     return Color::useColors;
00060 }
00061  
00062 std::ostream& operator<< (std::ostream &stream, const Color &cObj) {
00063     if (Color::useColors) {
00064         static const char ESC = '\033';
00065         stream << ESC;
00066         switch (cObj.d->color) {
00067             case C_NO_COLOR:     stream << "[0m";    break;
00068             case C_BLUE:         stream << "[0;34m"; break;
00069             case C_GREEN:        stream << "[0;32m"; break;
00070             case C_CYAN:         stream << "[0;36m"; break;
00071             case C_RED:          stream << "[0;31m"; break;
00072             case C_PURPLE:       stream << "[0;35m"; break;
00073             case C_BROWN:        stream << "[0;33m"; break;
00074             case C_LIGHT_GRAY:   stream << "[0;37m"; break;
00075             case C_DARK_GRAY:    stream << "[1;30m"; break;
00076             case C_LIGHT_BLUE:   stream << "[1;34m"; break;
00077             case C_LIGHT_GREEN:  stream << "[1;32m"; break;
00078             case C_LIGHT_CYAN:   stream << "[1;36m"; break;
00079             case C_LIGHT_RED:    stream << "[1;31m"; break;
00080             case C_LIGHT_PURPLE: stream << "[1;35m"; break;
00081             case C_YELLOW:       stream << "[1;33m"; break;
00082             case C_WHITE:        stream << "[1;37m"; break;
00083         }
00084     }
00085     return stream;
00086 }
00087 
00088 // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00089 // FixedFloat implementation
00090 #ifndef BUILDING_DOX
00091 struct FixedFloat::Private {
00092     int width;
00093     int precision;
00094 };
00095 #endif
00096 
00097 FixedFloat::FixedFloat(int integral, int decimal):
00098     d(new Private)
00099 {
00100     d->width = integral+decimal+1;
00101     d->precision = decimal;
00102 }
00103 
00104 FixedFloat::~FixedFloat() {
00105     delete d;
00106 }
00107 
00108 std::ostream& operator<< (std::ostream &stream, const FixedFloat &manip) {
00109     return stream
00110         << std::fixed
00111         << std::setw(manip.d->width)
00112         << std::setprecision(manip.d->precision);
00113 }

Generated on Sat May 2 16:39:31 2009 for nucad by  doxygen 1.5.4