/src/ogre/OgreMain/include/OgreNameGenerator.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #ifndef __NameGenerator_H__ |
29 | | #define __NameGenerator_H__ |
30 | | |
31 | | #include "OgreString.h" |
32 | | #include "OgreHeaderPrefix.h" |
33 | | |
34 | | #include "Threading/OgreThreadHeaders.h" |
35 | | |
36 | | namespace Ogre { |
37 | | /** \addtogroup Core |
38 | | * @{ |
39 | | */ |
40 | | /** \addtogroup General |
41 | | * @{ |
42 | | */ |
43 | | |
44 | | /// Utility class to generate a sequentially numbered series of names |
45 | | class _OgreExport NameGenerator |
46 | | { |
47 | | private: |
48 | | String mPrefix; |
49 | | unsigned long long int mNext; |
50 | | OGRE_AUTO_MUTEX; |
51 | | public: |
52 | | NameGenerator(const NameGenerator& rhs) |
53 | 0 | : mPrefix(rhs.mPrefix), mNext(rhs.mNext) {} |
54 | | |
55 | 6 | NameGenerator(const String& prefix) : mPrefix(prefix), mNext(1) {} |
56 | | |
57 | | /// Generate a new name |
58 | | String generate() |
59 | 0 | { |
60 | 0 | OGRE_LOCK_AUTO_MUTEX; |
61 | 0 | return StringUtil::format("%s%llu", mPrefix.c_str(), mNext++); |
62 | 0 | } |
63 | | |
64 | | /// Reset the internal counter |
65 | | void reset() |
66 | 0 | { |
67 | 0 | OGRE_LOCK_AUTO_MUTEX; |
68 | 0 | mNext = 1ULL; |
69 | 0 | } |
70 | | |
71 | | /// Manually set the internal counter (use caution) |
72 | | void setNext(unsigned long long int val) |
73 | 0 | { |
74 | 0 | OGRE_LOCK_AUTO_MUTEX; |
75 | 0 | mNext = val; |
76 | 0 | } |
77 | | |
78 | | /// Get the internal counter |
79 | | unsigned long long int getNext() const |
80 | 0 | { |
81 | 0 | // lock even on get because 64-bit may not be atomic read |
82 | 0 | OGRE_LOCK_AUTO_MUTEX; |
83 | 0 | return mNext; |
84 | 0 | } |
85 | | }; |
86 | | |
87 | | /** @} */ |
88 | | /** @} */ |
89 | | } |
90 | | |
91 | | #include "OgreHeaderSuffix.h" |
92 | | |
93 | | #endif |