[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / UpdateMask.h
blob14a31f2acdac7c9cf192ad7d812d0b8a927cea3f
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef __UPDATEMASK_H
20 #define __UPDATEMASK_H
22 #include "UpdateFields.h"
23 #include "Errors.h"
25 class UpdateMask
27 public:
28 UpdateMask( ) : mCount( 0 ), mBlocks( 0 ), mUpdateMask( 0 ) { }
29 UpdateMask( const UpdateMask& mask ) : mUpdateMask( 0 ) { *this = mask; }
31 ~UpdateMask( )
33 if(mUpdateMask)
34 delete [] mUpdateMask;
37 inline void SetBit (uint32 index)
39 ( (uint8 *)mUpdateMask )[ index >> 3 ] |= 1 << ( index & 0x7 );
42 inline void UnsetBit (uint32 index)
44 ( (uint8 *)mUpdateMask )[ index >> 3 ] &= (0xff ^ (1 << ( index & 0x7 ) ) );
47 inline bool GetBit (uint32 index)
49 return ( ( (uint8 *)mUpdateMask)[ index >> 3 ] & ( 1 << ( index & 0x7 ) )) != 0;
52 inline uint32 GetBlockCount() { return mBlocks; }
53 inline uint32 GetLength() { return mBlocks << 2; }
54 inline uint32 GetCount() { return mCount; }
55 inline uint8* GetMask() { return (uint8*)mUpdateMask; }
57 inline void SetCount (uint32 valuesCount)
59 if(mUpdateMask)
60 delete [] mUpdateMask;
62 mCount = valuesCount;
63 mBlocks = (valuesCount + 31) / 32;
65 mUpdateMask = new uint32[mBlocks];
66 memset(mUpdateMask, 0, mBlocks << 2);
69 inline void Clear()
71 if (mUpdateMask)
72 memset(mUpdateMask, 0, mBlocks << 2);
75 inline UpdateMask& operator = ( const UpdateMask& mask )
77 SetCount(mask.mCount);
78 memcpy(mUpdateMask, mask.mUpdateMask, mBlocks << 2);
80 return *this;
83 inline void operator &= ( const UpdateMask& mask )
85 ASSERT(mask.mCount <= mCount);
86 for (uint32 i = 0; i < mBlocks; i++)
87 mUpdateMask[i] &= mask.mUpdateMask[i];
90 inline void operator |= ( const UpdateMask& mask )
92 ASSERT(mask.mCount <= mCount);
93 for (uint32 i = 0; i < mBlocks; i++)
94 mUpdateMask[i] |= mask.mUpdateMask[i];
97 inline UpdateMask operator & ( const UpdateMask& mask ) const
99 ASSERT(mask.mCount <= mCount);
101 UpdateMask newmask;
102 newmask = *this;
103 newmask &= mask;
105 return newmask;
108 inline UpdateMask operator | ( const UpdateMask& mask ) const
110 ASSERT(mask.mCount <= mCount);
112 UpdateMask newmask;
113 newmask = *this;
114 newmask |= mask;
116 return newmask;
119 private:
120 uint32 mCount;
121 uint32 mBlocks;
122 uint32 *mUpdateMask;
124 #endif