00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00028 #include <coconut_config.h>
00029 #include <writer_utils.h>
00030 #include <sstream>
00031 #include <algorithm>
00032 #include <api_exception.h>
00033 #include <infinity.h>
00034
00035 namespace coco {
00036
00037 std::string i2a(int x)
00038 {
00039 std::stringstream s;
00040 std::string t;
00041 s << x;
00042 s >> t;
00043 return std::string(s.str());
00044 }
00045
00046 std::string datetime(const struct tm *timeptr)
00047 {
00048 std::string month = i2a(timeptr->tm_mon+1);
00049 if(timeptr->tm_mon+1 < 10)
00050 month = '0'+ i2a(timeptr->tm_mon+1);
00051 else
00052 month = i2a(timeptr->tm_mon+1);
00053 std::string minute;
00054 if(timeptr->tm_min+1 < 10)
00055 minute = '0'+ i2a(timeptr->tm_min);
00056 else
00057 minute = i2a(timeptr->tm_min);
00058 std::string second;
00059 if(timeptr->tm_sec < 10)
00060 second = '0'+ i2a(timeptr->tm_sec);
00061 else
00062 second = i2a(timeptr->tm_min);
00063 return std::string("at ") + i2a(timeptr->tm_mday)+ '/' + month + '/' +
00064 i2a(1900 + timeptr->tm_year)+ ' ' + i2a(timeptr->tm_hour)+ ':' +
00065 minute + ':' + second;
00066 }
00067
00068 std::string localdatetime()
00069 {
00070 time_t rawtime;
00071 struct tm * timeinfo;
00072
00073 time ( &rawtime );
00074 timeinfo = localtime ( &rawtime );
00075 return datetime(timeinfo);
00076 }
00077
00078 std::string e2D(double x)
00079 {
00080 std::ostringstream os;
00081 os.setf(std::ios::scientific, std::ios::floatfield);
00082 os.precision(18);
00083 os << double_out(x);
00084 std::string s;
00085 s = os.str();
00086 replace(s.begin(),s.end(),'e','D');
00087 return s;
00088 }
00089
00090 #ifdef COCONUT_WINDOWS
00091 }
00092
00093 #include <cstdarg>
00094 #include <vsscanfwr.h>
00095
00096 namespace coco {
00097
00098
00099
00100 int coconut_sscanfdouble(double* d, const char* cp, const char* format, ...)
00101 {
00102 char *form = (char *) malloc(strlen(format)+7);
00103 char buf[101];
00104 int ret;
00105 if(strlen(format) > 0)
00106 {
00107 strcpy(form, format);
00108 strcat(form, " %100s");
00109 va_list args;
00110 va_start(args, format);
00111 ret = vsscanfwr(cp, form, buf, args);
00112 va_end(args);
00113 }
00114 else
00115 {
00116 strncpy(buf, cp, 100);
00117 ret = 1;
00118 }
00119 if(!strncmp(buf, "inf", 3))
00120 *d = COCO_INF;
00121 else if(!strncmp(buf, "-inf", 4))
00122 *d = -COCO_INF;
00123 else if(sscanf(buf, "%lf", d) != 1)
00124 ret--;
00125 free(form);
00126 return ret;
00127 }
00128 #endif
00129
00130 }