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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include <OSGConfig.h>
00047 #include <OSGSysFieldDataType.h>
00048
00049 #include "OSGStatTimeStampElem.h"
00050
00051 OSG_USING_NAMESPACE
00052
00053
00054
00055
00056
00057
00065
00066
00067
00068
00069
00070
00071 StatTimeStampElem::StatTimeStampElem(StatElemDescBase *desc)
00072 : StatElem(desc), _time(0)
00073 {
00074 }
00075
00076 StatElem *StatTimeStampElem::create ( StatElemDescBase *desc)
00077 {
00078 return new StatTimeStampElem(desc);
00079 }
00080
00081
00082 StatTimeStampElem::~StatTimeStampElem(void)
00083 {
00084 }
00085
00086
00087
00088 void StatTimeStampElem::putToString(std::string &str, const char *format) const
00089 {
00090 double time = getTimeStampMsecs(_time) / 1000.;
00091
00092 if(!format)
00093 {
00094 FieldDataTraits<TimeStamp>::putToString(_time, str);
00095 }
00096 else
00097 {
00098 const char *proc = strchr(format,'%');
00099 char *temp = new char [strlen(format) + 60];
00100
00101 if(proc)
00102 {
00103 if(! strncmp(proc, "%ms", 3))
00104 {
00105 std::string fcopy(format);
00106 fcopy.insert((proc - format) + 1,".2f ");
00107 sprintf(temp, fcopy.c_str(), time*1000.);
00108 }
00109 else if(! strncmp(proc, "%r", 2))
00110 {
00111 std::string fcopy(format);
00112 fcopy.erase((proc - format) + 1, 1);
00113 sprintf(temp, fcopy.c_str(), 1./time);
00114 }
00115 else
00116 {
00117 sprintf(temp, format, time);
00118 }
00119
00120 }
00121 else
00122 {
00123 sprintf(temp, format, time);
00124 }
00125
00126 str = temp;
00127 delete [] temp;
00128 }
00129 }
00130
00131 bool StatTimeStampElem::getFromString(const Char8 *&inVal)
00132 {
00133 return FieldDataTraits<TimeStamp>::getFromString(_time, inVal);
00134 }
00135
00136 Real64 StatTimeStampElem::getValue(void) const
00137 {
00138 return static_cast<Real64>(getTime());
00139 }
00140
00141 void StatTimeStampElem::reset(void)
00142 {
00143
00144 }
00145
00146
00147
00148 StatTimeStampElem& StatTimeStampElem::operator = (const StatTimeStampElem &source)
00149 {
00150 if (this == &source)
00151 return *this;
00152
00153 _time = source._time;
00154
00155 return *this;
00156 }
00157
00158
00159
00160 bool StatTimeStampElem::operator < (const StatTimeStampElem &other) const
00161 {
00162 return _time < other._time;
00163 }
00164
00165
00166
00167 StatElem *StatTimeStampElem::clone(void) const
00168 {
00169 StatTimeStampElem *e = new StatTimeStampElem(getDesc());
00170
00171 *e = *this;
00172
00173 return e;
00174 }
00175
00176
00177
00178 StatElem &StatTimeStampElem::operator += (const StatElem &other)
00179 {
00180 const StatTimeStampElem *o = dynamic_cast<const StatTimeStampElem *>(&other);
00181
00182 _time += o->_time;
00183
00184 return *this;
00185 }
00186
00187
00188
00189
00190
00191 #ifdef __sgi
00192 #pragma set woff 1174
00193 #endif
00194
00195 #ifdef OSG_LINUX_ICC
00196 #pragma warning( disable : 177 )
00197 #endif
00198
00199 namespace
00200 {
00201 static Char8 cvsid_cpp[] = "@(#)$Id: OSGStatTimeStampElem.cpp,v 1.1 2005/10/02 15:16:45 dirk Exp $";
00202 static Char8 cvsid_hpp[] = OSGSTATTIMESTAMPELEM_HEADER_CVSID;
00203 static Char8 cvsid_inl[] = OSGSTATTIMESTAMPELEM_INLINE_CVSID;
00204 }