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"
28 UpdateMask( ) : mCount( 0 ), mBlocks( 0 ), mUpdateMask( 0 ) { }
29 UpdateMask( const UpdateMask
& mask
) : mUpdateMask( 0 ) { *this = mask
; }
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
)
60 delete [] mUpdateMask
;
63 mBlocks
= (valuesCount
+ 31) / 32;
65 mUpdateMask
= new uint32
[mBlocks
];
66 memset(mUpdateMask
, 0, mBlocks
<< 2);
72 memset(mUpdateMask
, 0, mBlocks
<< 2);
75 UpdateMask
& operator = ( const UpdateMask
& mask
)
77 SetCount(mask
.mCount
);
78 memcpy(mUpdateMask
, mask
.mUpdateMask
, mBlocks
<< 2);
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
);
108 UpdateMask
operator | ( const UpdateMask
& mask
) const
110 ASSERT(mask
.mCount
<= mCount
);