OregonCore  revision be9e804-git
Your Favourite TBC server
UpdateMask.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __UPDATEMASK_H
19 #define __UPDATEMASK_H
20 
21 #include "UpdateFields.h"
22 #include "Errors.h"
23 
25 {
26  public:
27  UpdateMask() : mCount(0), mBlocks(0), mUpdateMask(0) { }
28  UpdateMask(const UpdateMask& mask) : mUpdateMask(0)
29  {
30  *this = mask;
31  }
32 
34  {
35  if (mUpdateMask)
36  delete [] mUpdateMask;
37  }
38 
39  void SetBit (uint32 index)
40  {
41  ((uint8*)mUpdateMask)[ index >> 3 ] |= 1 << (index & 0x7);
42  }
43 
44  void UnsetBit (uint32 index)
45  {
46  ((uint8*)mUpdateMask)[ index >> 3 ] &= (0xff ^ (1 << (index & 0x7)));
47  }
48 
49  bool GetBit (uint32 index)
50  {
51  return (((uint8*)mUpdateMask)[ index >> 3 ] & (1 << (index & 0x7))) != 0;
52  }
53 
55  {
56  return mBlocks;
57  }
59  {
60  return mBlocks << 2;
61  }
63  {
64  return mCount;
65  }
67  {
68  return (uint8*)mUpdateMask;
69  }
70 
71  void SetCount (uint32 valuesCount)
72  {
73  if (mUpdateMask)
74  delete [] mUpdateMask;
75 
76  mCount = valuesCount;
77  mBlocks = (valuesCount + 31) / 32;
78 
79  mUpdateMask = new uint32[mBlocks];
80  memset(mUpdateMask, 0, mBlocks << 2);
81  }
82 
83  void Clear()
84  {
85  if (mUpdateMask)
86  memset(mUpdateMask, 0, mBlocks << 2);
87  }
88 
90  {
91  SetCount(mask.mCount);
92  memcpy(mUpdateMask, mask.mUpdateMask, mBlocks << 2);
93 
94  return *this;
95  }
96 
97  void operator &= (const UpdateMask& mask)
98  {
99  ASSERT(mask.mCount <= mCount);
100  for (uint32 i = 0; i < mBlocks; i++)
101  mUpdateMask[i] &= mask.mUpdateMask[i];
102  }
103 
104  void operator |= (const UpdateMask& mask)
105  {
106  ASSERT(mask.mCount <= mCount);
107  for (uint32 i = 0; i < mBlocks; i++)
108  mUpdateMask[i] |= mask.mUpdateMask[i];
109  }
110 
111  UpdateMask operator & (const UpdateMask& mask) const
112  {
113  ASSERT(mask.mCount <= mCount);
114 
115  UpdateMask newmask;
116  newmask = *this;
117  newmask &= mask;
118 
119  return newmask;
120  }
121 
122  UpdateMask operator | (const UpdateMask& mask) const
123  {
124  ASSERT(mask.mCount <= mCount);
125 
126  UpdateMask newmask;
127  newmask = *this;
128  newmask |= mask;
129 
130  return newmask;
131  }
132 
133  private:
137 };
138 #endif
139 
bool GetBit(uint32 index)
Definition: UpdateMask.h:49
void Clear()
Definition: UpdateMask.h:83
UpdateMask operator|(const UpdateMask &mask) const
Definition: UpdateMask.h:122
void operator|=(const UpdateMask &mask)
Definition: UpdateMask.h:104
void operator&=(const UpdateMask &mask)
Definition: UpdateMask.h:97
uint8 * GetMask()
Definition: UpdateMask.h:66
ACE_UINT8 uint8
Definition: Define.h:73
uint32 mBlocks
Definition: UpdateMask.h:135
uint32 * mUpdateMask
Definition: UpdateMask.h:136
uint32 mCount
Definition: UpdateMask.h:134
UpdateMask & operator=(const UpdateMask &mask)
Definition: UpdateMask.h:89
uint32 GetLength()
Definition: UpdateMask.h:58
UpdateMask(const UpdateMask &mask)
Definition: UpdateMask.h:28
void SetCount(uint32 valuesCount)
Definition: UpdateMask.h:71
#define ASSERT
Definition: Errors.h:29
void UnsetBit(uint32 index)
Definition: UpdateMask.h:44
UpdateMask operator&(const UpdateMask &mask) const
Definition: UpdateMask.h:111
ACE_UINT32 uint32
Definition: Define.h:71
uint32 GetCount()
Definition: UpdateMask.h:62
void SetBit(uint32 index)
Definition: UpdateMask.h:39
uint32 GetBlockCount()
Definition: UpdateMask.h:54