00001 /* 00002 * This file is part of Micole Architecture 00003 * 00004 * Copyright (C) 2007 Micole partners 00005 * 00006 * Micole Architecture is free software: you can redistribute it 00007 * and/or modify it under the terms of the GNU Lesser General 00008 * Public License as published by the Free Software Foundation, 00009 * either version 3 of the License, or (at your option) any 00010 * later version. 00011 * 00012 * Micole Architecture is distributed in the hope that it will be 00013 * useful, * but WITHOUT ANY WARRANTY; without even the implied 00014 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00015 * PURPOSE. See the GNU Lesser General Public License for more 00016 * details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Micole Architecture. If not, see 00020 * <http://www.gnu.org/licenses/>. 00021 */ 00022 00023 #include "stdafx.h" 00024 00025 #include <cmath> 00026 00027 #include "MicoleStringStream.h" 00028 00029 00030 MicoleStringStream::MicoleStringStream() 00031 { 00032 _data = string(""); 00033 } 00034 00035 MicoleStringStream::MicoleStringStream(const MicoleStringStream &mss) 00036 { 00037 _data = mss._data; 00038 } 00039 00040 MicoleStringStream::~MicoleStringStream() 00041 { 00042 } 00043 00044 string MicoleStringStream::getString() const 00045 { 00046 return _data; 00047 } 00048 00049 string MicoleStringStream::str() const 00050 { 00051 return _data; 00052 } 00053 00054 void MicoleStringStream::flush() 00055 { 00056 _data = ""; 00057 } 00058 00059 MicoleStringStream & MicoleStringStream::operator= (const MicoleStringStream &mss) 00060 { 00061 if (this == &mss) 00062 { 00063 return *this; 00064 } 00065 _data = mss._data; 00066 return *this; 00067 } 00068 00069 MicoleStringStream & MicoleStringStream::operator<< (const string &pStr) 00070 { 00071 _data = _data + pStr; 00072 return *this; 00073 } 00074 00075 MicoleStringStream & MicoleStringStream::operator<< (int i) 00076 { 00077 int nbchars; 00078 //1 for the \0 and 1 for the - possible 00079 if (i == 0) 00080 nbchars = 3; 00081 else 00082 nbchars = int(floor(log10(fabs(static_cast<float>(i))))) + 3; 00083 char *buffer = new char[nbchars]; 00084 00085 _itoa_s (i, buffer, nbchars, 10); 00086 00087 _data = _data + string(buffer); 00088 delete []buffer; 00089 return *this; 00090 } 00091 00092 MicoleStringStream & MicoleStringStream::operator<< (double f) 00093 { 00094 //1 for the \0 and 1 for the - possible, 1 for the possible . 00095 // and 10 decimals max 00096 int nbchars; 00097 if (fabs(f) <= 1) 00098 nbchars = 20; 00099 else 00100 nbchars = int(floor(log10(fabs(f)))) + 20; 00101 char *buffer = new char[nbchars]; 00102 00103 //gcvt (f,8,buffer); 00104 //int nbdecim, sign; 00105 //_ecvt_s(buffer, nbchars, f, 10, &nbdecim, &sign); 00106 _gcvt_s(buffer, nbchars, f, 10); 00107 00108 _data = _data + string(buffer); 00109 delete []buffer; 00110 return *this; 00111 }