25 #ifndef STA_COMMON_ERROR_H
26 #define STA_COMMON_ERROR_H
43 #ifdef _SUPPORT_MATLAB_
44 #define sta_assert( S ) \
48 std::stringstream s; \
49 s<<"Assertion \""<<#S<<"\" failed (line "<<__LINE__<<" in "<<__FILE__<<")";\
50 mexErrMsgTxt(s.str().c_str()); \
54 #define sta_assert( S ) \
74 :_message(message),_error_code(error_code)
78 :_error_code(error_code)
79 {_message=errortostring(error_code);}
85 std::ostringstream os;
93 _error_code=error_code;
111 return _message.c_str();
115 std::string _message;
126 std::string startevent;
127 std::list<std::string> event_names;
128 std::list<double> event_times;
129 std::list<double> event_all_times;
136 struct timeval _Time;
137 gettimeofday(&_Time,NULL);
138 _startSecond=_Time.tv_sec + 0.000001*_Time.tv_usec;
142 _lastSecond=_startSecond;
145 addEvent(startevent);
159 void addEvent(std::string event)
162 struct timeval currentTime;
163 gettimeofday(¤tTime,NULL);
164 double currentSeconds=currentTime.tv_sec + 0.000001*currentTime.tv_usec;
166 double currentSeconds=0;
169 event_times.push_back(currentSeconds-_lastSecond);
170 event_all_times.push_back(currentSeconds-_startSecond);
171 event_names.push_back(event);
172 _lastSecond=currentSeconds;
176 void printEvents(
int precision=3)
178 printf(
"\n computation time (summary):\n");
179 printf(
" all step\n");
180 std::list<std::string>::iterator iter2=event_names.begin();
181 std::list<double>::iterator iter3=event_all_times.begin();
182 for (std::list<double>::iterator iter=event_times.begin();
183 iter!=event_times.end();iter++,iter2++,iter3++)
186 s<<std::fixed<<std::setprecision(precision)<<*iter3<<
" sec. | "<<*iter<<
" sec. |\t("<<*iter2<<
")";
187 printf(
"%s\n",s.str().c_str());
Definition: sta_error.h:120
the STA error class
Definition: sta_error.h:68
std::string str() const
Definition: sta_error.h:102
STA_RESULT
function return value
Definition: stensor.h:124
const char * what() const
Definition: sta_error.h:109
The STA-ImageAnalysisToolkit namespace.
Definition: stafield.h:55