CFx SDK Documentation  2023 SP0
SaveState.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, 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 Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 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 
38 template <class T>
40 {
41  T& m_val; // Variable
42  T m_oldValue; // Old value
43 public:
46  OdSaveState( T& variable )
47  : m_val( variable )
48  {
49  m_oldValue = m_val;
50  }
53  OdSaveState( T& variable, const T& newValue )
54  : m_val( variable )
55  {
56  m_oldValue = m_val;
57  m_val = newValue;
58  }
60  {
61  m_val = m_oldValue;
62  }
66  operator const T&() const
67  {
68  return m_oldValue;
69  }
70 };
71 
72 #ifdef __hpux
73 #define OdSaveStateFlagDef(type, flag, name, flags) \
74  const type _##name##Flag = flag; \
75  OdSaveStateFlagImpl<type, _##name##Flag> name(flags)
76 #define OdSaveStateFlag(type, flag, name, flags, newVal) \
77  const type _##name##Flag = flag; \
78  OdSaveStateFlagImpl<type, _##name##Flag> name(flags, newVal)
79 #else
80 #define OdSaveStateFlagDef(type, flag, name, flags) \
81  OdSaveStateFlagImpl<type, flag> name(flags)
82 #define OdSaveStateFlag(type, flag, name, flags, newVal) \
83  OdSaveStateFlagImpl<type, flag> name(flags, newVal)
84 #endif
85 
90 template <class T, T flag>
92 {
93  T& m_val; // Variable
94  bool m_oldValue; // Old flag value
95 public:
98  OdSaveStateFlagImpl(T& variable): m_val( variable )
99  {
100  m_oldValue = GETBIT(m_val, flag);
101  }
102  OdSaveStateFlagImpl(T& variable, bool bNewValue): m_val( variable )
103  {
104  m_oldValue = GETBIT(m_val, flag);
105  SETBIT(m_val, flag, bNewValue);
106  }
108  {
109  SETBIT(m_val, flag, m_oldValue);
110  }
114  operator bool() const
115  {
116  return m_oldValue;
117  }
118 };
119 
120 #include "TD_PackPop.h"
121 
122 #endif //#ifndef _ODSAVESTATE_INCLUDED_
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:499
#define GETBIT(flags, bit)
Definition: OdaDefs.h:500
OdSaveStateFlagImpl(T &variable, bool bNewValue)
Definition: SaveState.h:102
OdSaveStateFlagImpl(T &variable)
Definition: SaveState.h:98
OdSaveState(T &variable)
Definition: SaveState.h:46
OdSaveState(T &variable, const T &newValue)
Definition: SaveState.h:53
~OdSaveState()
Definition: SaveState.h:59