Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phTimeInterval.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission :
00003         Realtime Vision Processing System
00004 
00005     Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008 
00009     This file is part of Phission.
00010 
00011     Phission is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU Lesser General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     Phission is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU Lesser General Public License for more details.
00020 
00021     You should have received a copy of the GNU Lesser General Public License
00022     along with Phission; if not, write to the Free Software
00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 
00025  ---------------------------------------------------------------------------*/
00026 #ifdef HAVE_CONFIG_H
00027     #include <phissionconfig.h>
00028 #endif
00029 
00030 #include <phStandard.h>
00031 
00032 #include <phObject.h>
00033 #include <phMutex.h>
00034 #include <phList.h>
00035 #include <phTimeStamp.h>
00036 
00037 #include <phTimeInterval.h>
00038 
00039 #include <phError.h>
00040 #include <phMemory.h>
00041 #include <phPrint.h>
00042 
00043 /* ------------------------------------------------------------------------ */
00044 phTimeInterval::phTimeInterval( char *label )
00045 {
00046     phFUNCTION("phTimeInterval::phTimeInterval")
00047     int locked = 0;
00048 
00049     phTHIS_LOOSE_LOCK(locked);
00050 
00051     this->setName("phTimeInterval");
00052 
00053     this->m_stopped = 1;
00054 
00055     this->m_elapsed.clear();
00056     this->m_last_elapsed.clear();
00057     
00058     this->m_label = NULL;
00059     this->m_labelLength = 0;
00060     this->setLabel(label);
00061     
00062     phTHIS_LOOSE_UNLOCK(locked);
00063 }
00064 
00065 /* ------------------------------------------------------------------------ */
00066 phTimeInterval::~phTimeInterval()
00067 {
00068     phFUNCTION("phTimeInterval::~phTimeInterval")
00069     int locked = 0;
00070     
00071     phTHIS_LOOSE_LOCK(locked);
00072     
00073     phFree(this->m_label);
00074     this->m_labelLength = 0;
00075     this->m_start.clear();
00076     this->m_stop.clear();
00077     this->m_elapsed.clear();
00078     this->m_last_elapsed.clear();
00079 }
00080 
00081 /* ------------------------------------------------------------------------ */
00082 void phTimeInterval::start()
00083 {
00084     phFUNCTION("phTimeInterval::start")
00085     int locked = 0;
00086     
00087     phTHIS_LOOSE_LOCK(locked);
00088 
00089     if (this->m_stopped == 1)
00090     {
00091         this->m_stopped = 0;
00092         this->m_stop.clear();
00093         this->m_elapsed.clear();
00094         this->m_start.stamp();
00095     }
00096     
00097     phTHIS_LOOSE_UNLOCK(locked);
00098 }
00099 
00100 /* ------------------------------------------------------------------------ */
00101 void phTimeInterval::stop()
00102 {
00103     phFUNCTION("phTimeInterval::stop")
00104     int locked = 0;
00105     /* this will stamp in the constructor, thus setting the value 
00106      * for the time as the entry time into this function */
00107     phTimeStamp stamp;
00108     
00109     phTHIS_LOOSE_LOCK(locked);
00110 
00111     if (this->m_stopped == 0)
00112     {
00113         this->m_stop = stamp;
00114         if (this->m_stop > this->m_start)
00115         {
00116             phTimeStamp elapsed;
00117             elapsed = (this->m_stop - this->m_start);
00118             this->m_last_elapsed = this->m_elapsed = elapsed;
00119         }
00120         else
00121         {
00122             this->m_elapsed.clear();
00123         }
00124         this->m_stopped = 1;
00125     }
00126     
00127     phTHIS_LOOSE_UNLOCK(locked);
00128 }
00129 
00130 /* ------------------------------------------------------------------------ */
00131 void phTimeInterval::clear()
00132 {
00133     phFUNCTION("phTimeInterval::clear")
00134     int locked = 0;
00135     
00136     phTHIS_LOOSE_LOCK(locked);
00137 
00138     this->m_stopped = 1;
00139     this->m_stop.clear();
00140     this->m_elapsed.clear();
00141     this->m_last_elapsed.clear();
00142     this->m_start.clear();
00143     
00144     phTHIS_LOOSE_UNLOCK(locked);
00145 }
00146 
00147 /* ------------------------------------------------------------------------ */
00148 int phTimeInterval::setLabel(char *label)
00149 {
00150     phFUNCTION("phTimeInterval::setLabel")
00151     int locked = 0;
00152     
00153     phTHIS_LOOSE_LOCK(locked);
00154  
00155     uint32_t length = ((label != NULL) ? strlen(label) : 255);
00156     
00157     if (this->m_label == NULL)
00158     {
00159         this->m_label = (char *)phCalloc((length+1),sizeof(char));
00160         phCHECK_NULLPTR(this->m_label,"phCalloc","phCalloc failed");
00161         
00162         this->m_labelLength = length;
00163     }
00164     else if (length > this->m_labelLength)
00165     {
00166         this->m_label = (char *)phRealloc(this->m_label,(length+1)* sizeof(char));
00167         phCHECK_NULLPTR(this->m_label,"phRealloc","phRealloc failed");        
00168         
00169         this->m_labelLength = length;
00170     }
00171     sprintf(this->m_label,"%s",((label != NULL)? label : "phTimeInterval"));    
00172     
00173     phTHIS_LOOSE_UNLOCK(locked);
00174 
00175     return phSUCCESS;
00176 error:
00177     return phFAIL;
00178 }
00179 
00180 /* ------------------------------------------------------------------------ */
00181 phTimeStamp phTimeInterval::elapsed()
00182 {
00183     phFUNCTION("phTimeInterval::elapsed")
00184     int locked = 0;
00185     phTimeStamp temp;
00186     
00187     phTHIS_LOOSE_LOCK(locked);
00188     
00189     temp = this->m_elapsed;
00190     
00191     phTHIS_LOOSE_UNLOCK(locked);
00192 
00193     return temp;
00194 }
00195 
00196 /* ------------------------------------------------------------------------ */
00197 phTimeStamp phTimeInterval::lastElapsed()
00198 {
00199     phFUNCTION("phTimeInterval::lastElapsed")
00200     int locked = 0;
00201     phTimeStamp temp;
00202     
00203     phTHIS_LOOSE_LOCK(locked);
00204     
00205     temp = this->m_last_elapsed;
00206     
00207     phTHIS_LOOSE_UNLOCK(locked);
00208 
00209     return temp;
00210 }
00211 
00212 /* ------------------------------------------------------------------------ */
00213 void phTimeInterval::report(char *label,
00214                             FILE *file_desc )
00215 {
00216     phFUNCTION("phTimeInterval::report")
00217     int locked = 0;
00218 
00219     phTHIS_LOOSE_LOCK(locked);
00220 
00221     if (file_desc == NULL) file_desc = stdout;
00222     fprintf(file_desc,
00223             ((label == NULL) ? "" : "(%17s)"),
00224             ((label == NULL) ? "" : label)
00225             );
00226     this->m_elapsed.report(this->m_label,file_desc);
00227     
00228     phTHIS_LOOSE_UNLOCK(locked);
00229 }
00230 
00231 /* ------------------------------------------------------------------------ */
00232 /* Assignment operator */
00233 phTimeInterval &phTimeInterval::operator =( const phTimeInterval &right )
00234 {
00235     phFUNCTION("phTimeInterval::operator =")
00236     
00237     if (&right != this)
00238     {
00239         this->m_start       = right.m_start;
00240         this->m_stop        = right.m_stop;
00241         this->m_elapsed     = right.m_elapsed;
00242         this->m_last_elapsed= right.m_last_elapsed;
00243         this->m_stopped     = right.m_stopped;
00244         this->setLabel(right.m_label);
00245     }
00246 
00247     return *this;
00248 }
00249 
00250 /* ------------------------------------------------------------------------ */
00251 phTimeInterval *phTimeInterval::getNextInterval() 
00252 { 
00253     return (phTimeInterval*)this->getNext(); 
00254 }
00255 
00256 /* ------------------------------------------------------------------------ */
00257 phTimeInterval *phTimeInterval::getPreviousInterval() 
00258 { 
00259     return (phTimeInterval*)this->getPrevious(); 
00260 }




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:03 2007 for phission by  doxygen 1.4.4