1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Copyright (c) 2009 The Chromium Authors. All rights reserved.
2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file.
4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef CHROME_BROWSER_SYNC_UTIL_DBGQ_H_
6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define CHROME_BROWSER_SYNC_UTIL_DBGQ_H_
73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once
8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/basictypes.h"  // for COMPILE_ASSERT
10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// A circular queue that is designed to be easily inspectable in a debugger. It
12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// puts the elements into the array in reverse, so you can just look at the i_
13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// pointer for a recent history.
14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochtemplate <typename T, size_t size>
15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass DebugQueue {
16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  COMPILE_ASSERT(size > 0, DebugQueue_size_must_be_greater_than_zero);
17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DebugQueue() : i_(array_) { }
19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void Push(const T& t) {
20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    i_ = (array_ == i_ ? array_ + size - 1 : i_ - 1);
21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    *i_ = t;
22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  }
23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch protected:
24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  T* i_;  // Points to the newest element in the queue.
25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  T array_[size];
26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif  // CHROME_BROWSER_SYNC_UTIL_DBGQ_H_
29