00001 // Write utilities implementation -*- C++ -*- 00002 00003 // $Id: writer_utils.h 877 2009-02-18 14:18:02Z dferi $ 00004 // Copyright (C) 2001-2003 Hermann Schichl, Oleg Shcherbina 00005 // 00006 // This file is part of the COCONUT API. This library 00007 // is free software; you can redistribute it and/or modify it under the 00008 // terms of the Library GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // Library GNU General Public License for more details. 00016 00017 // As a special exception, you may use this file as part of a free software 00018 // library without restriction. Specifically, if other files instantiate 00019 // templates or use macros or inline functions from this file, or you compile 00020 // this file and link it with other files to produce an executable, this 00021 // file does not by itself cause the resulting executable to be covered by 00022 // the Library GNU General Public License. This exception does not however 00023 // invalidate any other reasons why the executable file might be covered by 00024 // the Library GNU General Public License. 00025 00028 #ifndef __WRITER_UTILS_H__ 00029 #define __WRITER_UTILS_H__ 00030 00031 #include <string> 00032 #include <ctime> 00033 #include <sstream> 00034 #include <infinity.h> 00035 00036 namespace coco { 00037 00039 00044 template <class _TH> 00045 inline std::string convert_to_str(const _TH& _h) 00046 { 00047 std::string bla; 00048 std::ostringstream o; 00049 o << _h; 00050 return o.str(); 00051 } 00052 00054 00055 std::string i2a(int x); 00056 00058 00059 std::string localdatetime(); 00060 00062 00063 std::string datetime(const struct tm *timeptr); 00064 00066 00068 std::string e2D(double d); 00069 00070 #ifdef COCONUT_WINDOWS 00071 inline std::string double_out(double d) 00072 { 00073 if(d == COCO_INF) 00074 return std::string("inf"); 00075 else if(d == -COCO_INF) 00076 return std::string("-inf"); 00077 else 00078 return coco::convert_to_str(d); 00079 } 00080 00081 // I HATE WINDOWS FOR THAT (AND FOR OTHER THINGS, AS WELL) 00082 // very stupid hack required for @@=))$//(=!"§/(="!§ windows to read in ***doubles*** properly! 00083 int coconut_sscanfdouble(double* d, const char* cp, const char* format, ...); 00084 #else 00085 #define double_out(d) (d) 00086 #define coconut_sscanfdouble(D, S, F, ...) sscanf(S, F " %lf", ## __VA_ARGS__, D) 00087 #endif 00088 00089 } // namespace coco 00090 00091 #endif /* __WRITER_UTILS_H__ */