struct AvgStor
{
public:
- /** The paramaters for this storage type, none for this average. */
- struct Params { };
+ /** The paramaters for this storage type */
+ struct Params
+ {
+ /**
+ * The current count. We stash this here because the current
+ * value is not a binned value.
+ */
+ T current;
+ };
private:
- /** The current count. */
- T current;
/** The total count for all cycles. */
mutable result_t total;
/** The cycle that current last changed. */
/**
* Build and initializes this stat storage.
*/
- AvgStor(const Params &) : current(T()), total(0), last(0) { }
+ AvgStor(Params &p) : total(0), last(0) { p.current = T(); }
/**
* Set the current count to the one provided, update the total and last
* @param val The new count.
* @param p The parameters for this storage.
*/
- void set(T val, const Params &p) {
- total += current * (curTick - last);
+ void set(T val, Params &p) {
+ total += p.current * (curTick - last);
last = curTick;
- current = val;
+ p.current = val;
}
+
/**
* Increment the current count by the provided value, calls set.
* @param val The amount to increment.
* @param p The parameters for this storage.
*/
- void inc(T val, const Params &p) { set(current + val, p); }
+ void inc(T val, Params &p) { set(p.current + val, p); }
+
/**
* Deccrement the current count by the provided value, calls set.
* @param val The amount to decrement.
* @param p The parameters for this storage.
*/
- void dec(T val, const Params &p) { set(current - val, p); }
+ void dec(T val, Params &p) { set(p.current - val, p); }
+
/**
* Return the current average.
* @param p The parameters for this storage.
* @return The current average.
*/
result_t val(const Params &p) const {
- total += current * (curTick - last);
+ total += p.current * (curTick - last);
last = curTick;
- return (result_t)(total + current) / (result_t)(curTick + 1);
+ return (result_t)(total + p.current) / (result_t)(curTick + 1);
}
+
/**
* Return the current count.
* @param p The parameters for this storage.
* @return The current count.
*/
- T value(const Params &p) const { return current; }
+ T value(const Params &p) const { return p.current; }
+
/**
* Reset stat value to default
*/
* Retrieve a const pointer to the storage from the bin.
* @return A const pointer to the storage object for this stat.
*/
- const storage_t *data() const {
- return (const_cast<bin_t *>(&bin))->data(params);
+ const storage_t *data() const
+ {
+ bin_t *_bin = const_cast<bin_t *>(&bin);
+ params_t *_params = const_cast<params_t *>(¶ms);
+ return _bin->data(*_params);
}
protected:
* @param index The vector index to access.
* @return A const pointer to the storage object at the given index.
*/
- const storage_t *data(int index) const {
- return (const_cast<bin_t *>(&bin))->data(index, params);
+ const storage_t *data(int index) const
+ {
+ bin_t *_bin = const_cast<bin_t *>(&bin);
+ params_t *_params = const_cast<params_t *>(¶ms);
+ return _bin->data(index, *_params);
}
protected:
* Retrieve a const pointer to the storage from the bin.
* @return A const pointer to the storage for this stat.
*/
- const storage_t *data() const { return bin->data(index, *params); }
+ const storage_t *data() const
+ {
+ bin_t *_bin = const_cast<bin_t *>(bin);
+ params_t *_params = const_cast<params_t *>(params);
+ return _bin->data(index, *_params);
+ }
public:
/**
protected:
storage_t *data(int index) { return bin.data(index, params); }
- const storage_t *data(int index) const {
- return (const_cast<bin_t *>(&bin))->data(index, params);
+ const storage_t *data(int index) const
+ {
+ bin_t *_bin = const_cast<bin_t *>(&bin);
+ params_t *_params = const_cast<params_t *>(¶ms);
+ return _bin->data(index, *_params);
}
protected:
}
const storage_t *data(int index) const {
- return (const_cast<bin_t *>(bin))->data(offset + index, *params);
+ bin_t *_bin = const_cast<bin_t *>(bin);
+ params_t *_params = const_cast<params_t *>(params);
+ return _bin->data(offset + index, *_params);
}
public:
* Retrieve a const pointer to the storage from the bin.
* @return A const pointer to the storage object for this stat.
*/
- const storage_t *data() const {
- return (const_cast<bin_t *>(&bin))->data(params);
+ const storage_t *data() const
+ {
+ bin_t *_bin = const_cast<bin_t *>(&bin);
+ params_t *_params = const_cast<params_t *>(¶ms);
+ return _bin->data(*_params);
}
protected:
protected:
storage_t *data(int index) { return bin.data(index, params); }
- const storage_t *data(int index) const {
- return (const_cast<bin_t *>(&bin))->data(index, params);
+ const storage_t *data(int index) const
+ {
+ bin_t *_bin = const_cast<bin_t *>(&bin);
+ params_t *_params = const_cast<params_t *>(¶ms);
+ return _bin->data(index, *_params);
}
protected:
int size() const { return 1; }
- Storage *data(const Params ¶ms) {
+ Storage *data(Params ¶ms) {
assert(initialized());
char *ptr = access();
char *flags = ptr + sizeof(Storage);
int size() const { return _size; }
- Storage *data(int index, const Params ¶ms) {
+ Storage *data(int index, Params ¶ms) {
assert(initialized());
assert(index >= 0 && index < size());
char *ptr = access();
new (ptr) Storage(params);
}
int size() const{ return 1; }
- Storage *data(const Params ¶ms) {
+ Storage *data(Params ¶ms) {
assert(initialized());
return reinterpret_cast<Storage *>(ptr);
}
int size() const { return _size; }
- Storage *data(int index, const Params ¶ms) {
+ Storage *data(int index, Params ¶ms) {
assert(initialized());
assert(index >= 0 && index < size());
return reinterpret_cast<Storage *>(ptr + index * sizeof(Storage));