AGX Dynamics 2.42.2.1
Loading...
Searching...
No Matches
BitState.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGX_BITSTATE_H
18#define AGX_BITSTATE_H
19
20#include <agx/Integer.h>
21
24
26
27namespace agx
28{
47 template< typename EnumT, typename BitT = agx::Int64 >
48 class BitState
49 {
50 public:
51 typedef BitT BitType;
52 typedef EnumT EnumType;
53
54 public:
55 BitState()
56 : m_bitState( BitType( 0 ) )
57 {
58 }
59
60 explicit BitState( BitType initialState )
61 : m_bitState( initialState )
62 {
63 }
64
65 ~BitState() = default;
66
67 agx::Bool operator== ( EnumType state ) const
68 {
69 return m_bitState == BitType( state );
70 }
71
72 agx::Bool operator!= ( EnumType state ) const
73 {
74 return !( *this == state );
75 }
76
77 agx::Bool empty() const
78 {
79 return m_bitState == BitType( 0 );
80 }
81
82 BitT get() const
83 {
84 return m_bitState;
85 }
86
87 BitState& set( BitType state )
88 {
89 m_bitState = state;
90 return *this;
91 }
92
93 BitState& update( EnumType state, agx::Bool enable )
94 {
95 if ( enable ) return add( state );
96 else return remove( state );
97 }
98
99 BitState& add( EnumType state )
100 {
101 m_bitState |= (BitType)state;
102 return *this;
103 }
104
105 BitState& remove( EnumType state )
106 {
107 m_bitState = (BitType)( m_bitState & ~state );
108 return *this;
109 }
110
111 BitState& toggle( EnumType state )
112 {
113 return update( state, !Is( state ) );
114 }
115
116 agx::Bool Is( BitType state ) const
117 {
118 return ( m_bitState & state ) != 0;
119 }
120
121 agx::Bool Not( BitType state ) const
122 {
123 return ( m_bitState & state ) == 0;
124 }
125
126 void store( agxStream::OutputArchive& out ) const { out << agxStream::out( "bitState", m_bitState ); }
127 void restore( agxStream::InputArchive& in ) { in >> agxStream::in( "bitState", m_bitState ); }
128
129 private:
130 BitType m_bitState;
131 };
132}
133
135
136#endif
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:401
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool Bool
Definition: Integer.h:40