MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/mpm/fmtnum.h
Go to the documentation of this file.
00001 /************************************************************************
00002  * MechSys - Open Library for Mechanical Systems                        *
00003  * Copyright (C) 2005 Dorival M. Pedroso                                *
00004  *                                                                      *
00005  * This program is free software: you can redistribute it and/or modify *
00006  * it under the terms of the GNU General Public License as published by *
00007  * the Free Software Foundation, either version 3 of the License, or    *
00008  * any later version.                                                   *
00009  *                                                                      *
00010  * This program is distributed in the hope that it will be useful,      *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         *
00013  * GNU General Public License for more details.                         *
00014  *                                                                      *
00015  * You should have received a copy of the GNU General Public License    *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>  *
00017  ************************************************************************/
00018 
00019 /* FmtNum - Copyright (C) 2007 Dorival de Moraes Pedroso */
00020 
00021 #ifndef MPM_FMTNUM_H
00022 #define MPM_FMTNUM_H
00023 
00024 // STL
00025 #include <iostream>
00026 #include <iomanip>
00027 
00028 namespace MPM {
00029 
00031 struct FmtNum
00032 {
00033     bool BoolAlpha;  
00034     bool Integer;    
00035     bool Scientific; 
00036     int  Width;      
00037     int  Precision;  
00038 };
00039 
00040 //                 bool  integ  scien   w   p
00041 FmtNum _a     = {  true, false, false,  0,  0 }; 
00042 FmtNum _3     = { false,  true, false,  3,  0 }; 
00043 FmtNum _4     = { false,  true, false,  4,  0 }; 
00044 FmtNum _6     = { false,  true, false,  6,  0 }; 
00045 FmtNum _8     = { false,  true, false,  8,  0 }; 
00046 FmtNum _3s    = { false, false,  true,  0,  3 }; 
00047 FmtNum _8s    = { false, false,  true,  0,  8 }; 
00048 FmtNum _4_2   = { false, false, false,  4,  2 }; 
00049 FmtNum _6_3   = { false, false, false,  6,  3 }; 
00050 FmtNum _12_6  = { false, false, false, 12,  6 }; 
00051 FmtNum _20_15 = { false, false, false, 20, 15 }; 
00052 
00054 std::ostream & operator<< (std::ostream & os, FmtNum const & FN)
00055 {
00056          if (FN.BoolAlpha)  { os<<" "<<std::setw(6)<<std::boolalpha; return os; }
00057     else if (FN.Integer)    { os<<" "<<std::setw(FN.Width); return os; }
00058     else if (FN.Scientific) { os<<" "<<std::setw(FN.Precision+9)<<std::scientific<<std::setprecision(FN.Precision); return os; } // add 9
00059     else                    { os<<" "<<std::setw(FN.Width+1)<<std::fixed<<std::setprecision(FN.Precision); return os; } // add 1 (for sign)
00060 }
00061 
00062 }; // namespace MPM
00063 
00064 #endif // MPM_FMTNUM_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines