[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / UpdateMask.h
blob5b844ad54ac3165b9ad6815bc8e4ead1c86fbaa1
1 /*
2 * Copyright (C) 2005-2009 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 void SetBit (uint32 index)
39 ( (uint8 *)mUpdateMask )[ index >> 3 ] |= 1 << ( index & 0x7 );
42 void UnsetBit (uint32 index)
44 ( (uint8 *)mUpdateMask )[ index >> 3 ] &= (0xff ^ (1 << ( index & 0x7 ) ) );
47 bool GetBit (uint32 index) const
49 return ( ( (uint8 *)mUpdateMask)[ index >> 3 ] & ( 1 << ( index & 0x7 ) )) != 0;
52 uint32 GetBlockCount() const { return mBlocks; }
53 uint32 GetLength() const { return mBlocks << 2; }
54 uint32 GetCount() const { return mCount; }
55 uint8* GetMask() { return (uint8*)mUpdateMask; }
57 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 void Clear()
71 if (mUpdateMask)
72 memset(mUpdateMask, 0, mBlocks << 2);
75 UpdateMask& operator = ( const UpdateMask& mask )
77 SetCount(mask.mCount);
78 memcpy(mUpdateMask, mask.mUpdateMask, mBlocks << 2);
80 return *this;
83 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 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 UpdateMask operator & ( const UpdateMask& mask ) const
99 ASSERT(mask.mCount <= mCount);
101 UpdateMask newmask;
102 newmask = *this;
103 newmask &= mask;
105 return newmask;
108 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