cipra: counter.hpp Source File

| cipra 1.2.1 A C++11 Unit Testing Framework based on Test::More

- Main Page
- Related Pages
- Namespaces
- Classes

All Classes Namespaces Functions Variables Typedefs Pages
counter.hpp
1 // -*- c++ -*-
2 /* This file is a part of the cipra Unit Testing Framework.
3 * Copyright (C) 2012, Patrick M. Niedzielski.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 *
18 * 3. The names of its contributors may not be used to endorse or
19 * promote products derived from this software without specific
20 * prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 * OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #ifndef CIPRA_COUNTER_HPP
37 #define CIPRA_COUNTER_HPP
38
39 #include <type_traits>
40 #include <atomic>
41
42 namespace cipra {
43
59 template <typename integralT = int>
60 class counter {
61 public:
62 static_assert(std::is_integral<integralT>::value,
63 "Counter type is not integral.");
64
68 typedef typename std::make_unsigned<integralT>::type
69 index_type;
70
78 inline counter();
79
90 inline index_type new_test_number();
91
92 private:
94 std::atomic<index_type> count;
95 };
96 }
97
98 #include "counter.ipp"
99
100 #endif // #ifdef CIPRA_COUNTER_HPP
cipra::counter
Manages the test numbers in test output.
Definition: counter.hpp:60
cipra::counter::counter
counter()
Initializes the atomic counter.
cipra::counter::new_test_number
index_type new_test_number()
Returns a unique test number.
cipra::counter::index_type
std::make_unsigned< integralT >::type index_type
The index type of the counter. The actual index type is going to be the unsigned counterpart of the t...
Definition: counter.hpp:63