X-Git-Url: http://git.indexdata.com/?p=yazpp-moved-to-github.git;a=blobdiff_plain;f=src%2Ftimestat.cpp;h=1ea246db60b06537b0df868013d9ec6bfc8b98cd;hp=5ea175552076e9a7d130b93e9cedcbcb9674225e;hb=82d0b6ce2accdbe9987d0b8b4e6e818514455e22;hpb=8353663886b90d762d43790780be6cb58fb93c8a diff --git a/src/timestat.cpp b/src/timestat.cpp index 5ea1755..1ea246d 100644 --- a/src/timestat.cpp +++ b/src/timestat.cpp @@ -1,5 +1,5 @@ /* This file is part of the yazpp toolkit. - * Copyright (C) 1998-2011 Index Data and Mike Taylor + * Copyright (C) Index Data * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,21 +25,35 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#if HAVE_CONFIG_H +#include +#endif #include +#include using namespace yazpp_1; +class TimeStat::Rep { + friend class TimeStat; + time_t sec; // time of most recent bucket + int *bucket; + int ptr; + int size; +}; + TimeStat::TimeStat(int sz) { - m_sec = 0; - m_size = sz; - m_bucket = new int[m_size]; - m_ptr = 0; + m_p = new Rep; + m_p->sec = 0; + m_p->size = sz; + m_p->bucket = new int[m_p->size]; + m_p->ptr = 0; } TimeStat::~TimeStat() { - delete [] m_bucket; + delete [] m_p->bucket; + delete m_p; } int TimeStat::get_total() @@ -47,8 +61,8 @@ int TimeStat::get_total() add_bytes(0); int bw = 0; int i; - for (i = 0; isize; i++) + bw += m_p->bucket[i]; return bw; } @@ -56,20 +70,20 @@ void TimeStat::add_bytes(int b) { time_t now = time(0); - if (now >= m_sec) + if (now >= m_p->sec) { - int d = now - m_sec; - if (d > m_size) - d = m_size; + int d = now - m_p->sec; + if (d > m_p->size) + d = m_p->size; while (--d >= 0) { - if (++m_ptr == m_size) - m_ptr = 0; - m_bucket[m_ptr] = 0; + if (++m_p->ptr == m_p->size) + m_p->ptr = 0; + m_p->bucket[m_p->ptr] = 0; } - m_bucket[m_ptr] += b; + m_p->bucket[m_p->ptr] += b; } - m_sec = now; + m_p->sec = now; } /*