fssIO.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Kamil Dudka <xdudka00@stud.fit.vutbr.cz>
00003  *
00004  * This file is part of fss (Fast SAT Solver).
00005  *
00006  * fss 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  * fss 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 fss.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include <string>
00021 #include <iomanip>
00022 #include "fssIO.h"
00023 
00024 using std::string;
00025 
00026 namespace FastSatSolver {
00027 
00028   // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00029   // GenericException implementation
00030   GenericException::GenericException(std::string text):
00031     text_(text)
00032   {
00033   }
00034   string GenericException::getText() {
00035     return text_;
00036   }
00037 
00038   namespace StreamDecorator {
00039     // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00040     // FixedFloat implementation
00041     struct FixedFloat::Private {
00042       int width;
00043       int precision;
00044     };
00045     FixedFloat::FixedFloat(int integral, int decimal):
00046       d(new Private)
00047     {
00048       d->width = integral+decimal+1;
00049       d->precision = decimal;
00050     }
00051     FixedFloat::~FixedFloat() {
00052       delete d;
00053     }
00054     std::ostream& operator<< (std::ostream &stream, const FixedFloat &manip) {
00055       return stream
00056         << std::fixed
00057         << std::setw(manip.d->width)
00058         << std::setprecision(manip.d->precision);
00059     }
00060 
00061     // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00062     // Color implementation
00063     bool Color::useColors = false;
00064     struct Color::Private {
00065       EColor            color;
00066     };
00067     Color::Color(EColor color):
00068       d(new Private)
00069     {
00070       d->color = color;
00071     }
00072     Color::Color(const Color &cObj):
00073       d(new Private)
00074     {
00075       d->color = cObj.d->color;
00076     }
00077     Color::~Color() {
00078       delete d;
00079     }
00080     void Color::enable(bool b) {
00081       Color::useColors = b;
00082     }
00083     bool Color::isEnabled() {
00084       return Color::useColors;
00085     }
00086     std::ostream& operator<< (std::ostream &stream, const Color &cObj) {
00087       if (Color::useColors) {
00088         static const char ESC = '\033';
00089         stream << ESC;
00090         switch (cObj.d->color) {
00091            case C_NO_COLOR:     stream << "[0m";    break;
00092            case C_BLUE:         stream << "[0;34m"; break;
00093            case C_GREEN:        stream << "[0;32m"; break;
00094            case C_CYAN:         stream << "[0;36m"; break;
00095            case C_RED:          stream << "[0;31m"; break;
00096            case C_PURPLE:       stream << "[0;35m"; break;
00097            case C_BROWN:        stream << "[0;33m"; break;
00098            case C_LIGHT_GRAY:   stream << "[0;37m"; break;
00099            case C_DARK_GRAY:    stream << "[1;30m"; break;
00100            case C_LIGHT_BLUE:   stream << "[1;34m"; break;
00101            case C_LIGHT_GREEN:  stream << "[1;32m"; break;
00102            case C_LIGHT_CYAN:   stream << "[1;36m"; break;
00103            case C_LIGHT_RED:    stream << "[1;31m"; break;
00104            case C_LIGHT_PURPLE: stream << "[1;35m"; break;
00105            case C_YELLOW:       stream << "[1;33m"; break;
00106            case C_WHITE:        stream << "[1;37m"; break;
00107         }
00108       }
00109       return stream;
00110     }
00111   } // namespace StreamDecorator
00112 
00113 } // namespace FastSatSolver

Generated on Wed Nov 5 22:30:21 2008 for Fast SAT Solver by  doxygen 1.5.4