CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
TrVisIdGenerator.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23// GLES2 static resource ID generator
24
25#ifndef ODTRVISIDGENERATOR
26#define ODTRVISIDGENERATOR
27
28#include "TD_PackPush.h"
29
30#include "TrVisDefs.h"
31#define STL_USING_SET
32#include "OdaSTL.h"
33
37template<class T>
39{
40 typedef std::set<T> IdMap;
41 mutable IdMap m_idMap;
42 mutable T m_idMapCounter, m_idMapSearchEx;
43 protected:
44 T inc(T &counter, T &searchEx) const
45 {
46 const T NegativeId = (T)(-1);
47 if (counter == NegativeId)
48 {
49 T id = searchEx;
50 do
51 {
52 if (!findId(id))
53 return searchEx = id;
54 id++;
55 } while (id < NegativeId);
56 id = 100;
57 while (id < searchEx)
58 {
59 if (!findId(id))
60 return searchEx = id;
61 id++;
62 }
63 counter = 100;
64 }
65 return counter++;
66 }
67 public:
69 {
70 clean();
71 }
72
73 void clean()
74 {
75 m_idMap.clear();
76 m_idMapCounter = m_idMapSearchEx = 100;
77 }
78
79 T generateId() const
80 {
81 const T freeId = inc(m_idMapCounter, m_idMapSearchEx);
82 m_idMap.insert(freeId);
83 return freeId;
84 }
85
86 void killId(T id) const
87 {
88 m_idMap.erase(id);
89 }
90
91 bool findId(T id) const
92 {
93 return m_idMap.find(id) != m_idMap.end();
94 }
95};
96
101
102#include "TD_PackPop.h"
103
104#endif // ODTRVISIDGENERATOR
OdTrVisIdGeneratorImpl< OdTrVisId > OdTrVisGenericIdGenerator
T inc(T &counter, T &searchEx) const
bool findId(T id) const
void killId(T id) const