CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
SaveState.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
24#ifndef _ODSAVESTATE_INCLUDED_
25#define _ODSAVESTATE_INCLUDED_
26
27#include "TD_PackPush.h"
28
38template <class T>
40{
41 T& m_val; // Variable
42 T m_oldValue; // Old value
43public:
44
51 OdSaveState( T& variable )
52 : m_val( variable )
53 {
54 m_oldValue = m_val;
55 }
56
64 OdSaveState( T& variable, const T& newValue )
65 : m_val( variable )
66 {
67 m_oldValue = m_val;
68 m_val = newValue;
69 }
70
76 {
77 m_val = m_oldValue;
78 }
79
83 operator const T&() const
84 {
85 return m_oldValue;
86 }
87};
88
89#ifdef __hpux
90#define OdSaveStateFlagDef(type, flag, name, flags) \
91 const type _##name##Flag = flag; \
92 OdSaveStateFlagImpl<type, _##name##Flag> name(flags)
93#define OdSaveStateFlag(type, flag, name, flags, newVal) \
94 const type _##name##Flag = flag; \
95 OdSaveStateFlagImpl<type, _##name##Flag> name(flags, newVal)
96#else
97#define OdSaveStateFlagDef(type, flag, name, flags) \
98 OdSaveStateFlagImpl<type, flag> name(flags)
99#define OdSaveStateFlag(type, flag, name, flags, newVal) \
100 OdSaveStateFlagImpl<type, flag> name(flags, newVal)
101#endif
102
108template <class T, T flag>
110{
111 T& m_val; // Current flag value
112 bool m_oldValue; // Old flag value
113public:
114
121 OdSaveStateFlagImpl(T& variable): m_val( variable )
122 {
123 m_oldValue = GETBIT(m_val, flag);
124 }
125
133 OdSaveStateFlagImpl(T& variable, bool bNewValue): m_val( variable )
134 {
135 m_oldValue = GETBIT(m_val, flag);
136 SETBIT(m_val, flag, bNewValue);
137 }
138
144 {
145 SETBIT(m_val, flag, m_oldValue);
146 }
147
151 operator bool() const
152 {
153 return m_oldValue;
154 }
155};
156
166template <class T, T flagsMask>
168{
169 T &m_val, m_oldValue;
170public:
177 OdSaveStateFlagsMask( T& variable )
178 : m_val(variable), m_oldValue(variable & flagsMask)
179 { }
180
188 OdSaveStateFlagsMask( T& variable, const T& newValue )
189 : m_val(variable), m_oldValue(variable & flagsMask)
190 { variable = (variable & ~flagsMask) | newValue; }
191
197 {
198 m_val = (m_val & ~flagsMask) | m_oldValue;
199 }
200
204 operator const T&() const
205 {
206 return m_oldValue;
207 }
208};
209
215template <typename ObjType, typename ValType>
217{
218public:
222 OdSaveStateFunc(ObjType* pObj, ValType(ObjType::*getFunc)() const,
223 void(ObjType::*setFunc)(ValType))
224 :m_pObj(pObj), m_getFunc(getFunc), m_setFunc(setFunc)
225 {
227 }
228
232 OdSaveStateFunc(ObjType* pObj, ValType(ObjType::*getFunc)() const,
233 void(ObjType::*setFunc)(ValType), ValType newValue)
234 :m_pObj(pObj), m_getFunc(getFunc), m_setFunc(setFunc)
235 {
237 (*m_pObj.*m_setFunc)(newValue);
238 }
239
245 {
247 }
248protected:
249 ObjType* m_pObj;
250 ValType(ObjType::*m_getFunc)() const;
251 void(ObjType::*m_setFunc)(ValType);
252 ValType m_oldValue;
253};
254
255#include "TD_PackPop.h"
256
257#endif //#ifndef _ODSAVESTATE_INCLUDED_
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:516
#define GETBIT(flags, bit)
Definition: OdaDefs.h:517
OdSaveStateFlagImpl(T &variable, bool bNewValue)
Definition: SaveState.h:133
OdSaveStateFlagImpl(T &variable)
Definition: SaveState.h:121
OdSaveStateFlagsMask(T &variable, const T &newValue)
Definition: SaveState.h:188
OdSaveStateFlagsMask(T &variable)
Definition: SaveState.h:177
OdSaveStateFunc(ObjType *pObj, ValType(ObjType::*getFunc)() const, void(ObjType::*setFunc)(ValType))
Definition: SaveState.h:222
OdSaveStateFunc(ObjType *pObj, ValType(ObjType::*getFunc)() const, void(ObjType::*setFunc)(ValType), ValType newValue)
Definition: SaveState.h:232
void(ObjType::* m_setFunc)(ValType)
Definition: SaveState.h:251
ValType m_oldValue
Definition: SaveState.h:252
ObjType * m_pObj
Definition: SaveState.h:249
ValType(ObjType::* m_getFunc)() const
Definition: SaveState.h:250
OdSaveState(T &variable)
Definition: SaveState.h:51
OdSaveState(T &variable, const T &newValue)
Definition: SaveState.h:64
~OdSaveState()
Definition: SaveState.h:75
typedef void(APIENTRYP PFNGLACTIVETEXTUREPROC)(GLenum texture)