ProgressPrinter.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #include "ProgressPrinter.h"
00019 #include "../thread/Timer.h"
00020 
00021 namespace oasys {
00022 
00026 ProgressPrinter::ProgressPrinter(const char* fmt, ...)
00027 {
00028     if (fmt) {
00029         va_list ap;
00030         va_start(ap, fmt);
00031         vprintf(fmt, ap);
00032         va_end(ap);
00033         fflush(stdout);
00034     }
00035     
00036     ::gettimeofday(&start_, 0);
00037 }
00038 
00042 void
00043 ProgressPrinter::start(const char* fmt, ...)
00044 {
00045     va_list ap;
00046     va_start(ap, fmt);
00047     vprintf(fmt, ap);
00048     va_end(ap);
00049     fflush(stdout);
00050     
00051     ::gettimeofday(&start_, 0);
00052 }
00053 
00058 void
00059 ProgressPrinter::done(const char* fmt, ...)
00060 {
00061     struct timeval end;
00062 
00063     va_list ap;
00064     va_start(ap, fmt);
00065     vprintf(fmt, ap);
00066     va_end(ap);
00067 
00068     ::gettimeofday(&end, 0);
00069     unsigned long elapsed = TIMEVAL_DIFF_MSEC(end, start_);
00070     
00071     printf(" (%lu.%.3lu secs)\n", elapsed / 1000, (elapsed % 1000));
00072 }
00073 
00074 } // namespace oasys
00075 

Generated on Thu Jun 7 16:56:51 2007 for DTN Reference Implementation by  doxygen 1.5.1