Debian Codegraph @

Kernel/tCounter.h

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef TCOUNTER_H
21 #define TCOUNTER_H
22
23 /** define class that allows user to have an integer with restricted
24 * access (i.e. get value, increment and reset). This is useful when
25 * integral value used as a static var of some class
26 */
27 template <typename T>
28 class TCounter
29 {
30 public: // type interface
31 /// define integral type of a counter
32 typedef T IntType;
33
34 protected: // members
35 /// counter itself
36 IntType counter;
37
38 public: // interface
39 /// init c'tor
40 explicit TCounter ( const IntType n ) : counter(n) {}
41 /// copy c'tor
42 template <typename U>
43 explicit TCounter ( const TCounter<U>& copy ) : counter(copy.counter) {}
44 /// assignment
45 template <typename U>
46 TCounter& operator= ( const TCounter<U>& copy )
47 {
48 counter = copy.counter;
49 return *this;
50 }
51
52 // operators
53
54 /// get value of a counter
55 IntType val ( void ) const { return counter; }
56 /// increment value of a counter; @return new value
57 IntType inc ( void ) { return ++counter; }
58 /// set new value of a counter
59 void reset ( const IntType n ) { counter = n; }
60 }; // TCounter
61
62 #endif