The open source OpenXR runtime
1/** @file
2 @brief A class for handling "do this every n times"
3
4 This header is maintained as a part of 'util-headers' - you can always
5 find the latest version online at https://github.com/rpavlik/util-headers
6
7 This GUID can help identify the project: d1dbc94e-e863-49cf-bc08-ab4d9f486613
8
9 This copy of the header is from the revision that Git calls
10 1a8444782d15cb9458052e3d8251c4f5b8e808d5
11
12 Commit date: "2022-03-11 12:11:32 -0600"
13
14 @date
15 2009-2010
16
17 @author
18 Rylie Pavlik
19 <rylie@ryliepavlik.com>
20 https://ryliepavlik.com/
21 Iowa State University Virtual Reality Applications Center
22 Human-Computer Interaction Graduate Program
23*/
24
25// Copyright 2009-2010, Iowa State University.
26//
27// SPDX-License-Identifier: BSL-1.0
28//
29// Distributed under the Boost Software License, Version 1.0.
30// (See accompanying file LICENSE_1_0.txt or copy at
31// http://www.boost.org/LICENSE_1_0.txt)
32
33#pragma once
34#ifndef INCLUDED_Stride_h_GUID_eaa50b9c_e526_4656_89dc_99008d82447d
35#define INCLUDED_Stride_h_GUID_eaa50b9c_e526_4656_89dc_99008d82447d
36
37// Local includes
38// - none
39
40// Library includes
41// - none
42
43// Standard includes
44// - none
45
46namespace util {
47
48/// @addtogroup Other Other Utility Classes
49/// @{
50
51/// Handle the task of "do this every n times" in an easy way.
52 class Stride {
53 public:
54 Stride(const unsigned int n) :
55 _stride(n),
56 _step(0) { }
57
58 void advance() {
59 _step = (_step + 1) % _stride;
60 }
61
62 Stride operator++() {
63 Stride temp = *this;
64 advance();
65 return temp;
66 }
67
68 Stride & operator++(int) {
69 advance();
70 return *this;
71 }
72
73 operator bool() const {
74 return _step == 0;
75 }
76
77 private:
78 unsigned int _stride;
79 unsigned int _step;
80 };
81
82/// @}
83
84} // end of util namespace
85
86#endif // INCLUDED_Stride_h_GUID_eaa50b9c_e526_4656_89dc_99008d82447d
87