Initial community commit
This commit is contained in:
parent
537bcbc862
commit
fc06254474
16440 changed files with 4239995 additions and 2 deletions
51
Src/replicant/nu/SafeSize.h
Normal file
51
Src/replicant/nu/SafeSize.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
|
||||
class SafeSize
|
||||
{
|
||||
public:
|
||||
SafeSize()
|
||||
{
|
||||
value = 0;
|
||||
overflow = false;
|
||||
}
|
||||
|
||||
void Add(size_t add)
|
||||
{
|
||||
if (!overflow)
|
||||
{
|
||||
value += add;
|
||||
if (value < add)
|
||||
overflow=true;
|
||||
}
|
||||
}
|
||||
|
||||
void AddN(size_t size, size_t count)
|
||||
{
|
||||
if (!overflow)
|
||||
{
|
||||
size_t total = size * count;
|
||||
if (total < size)
|
||||
{
|
||||
overflow = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Add(total);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Overflowed() const
|
||||
{
|
||||
return overflow;
|
||||
}
|
||||
|
||||
operator size_t ()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t value;
|
||||
bool overflow;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue