Skip to content

Commit

Permalink
Fix formating
Browse files Browse the repository at this point in the history
  • Loading branch information
cosin15 committed Jan 12, 2025
1 parent 3031239 commit 13e8caa
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions src/util/pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ class Buffer
Buffer(unsigned int size)
{
m_size = size;
if(size != 0) {
if (size != 0) {
data = new T[size];
}
else {
} else {
data = nullptr;
}
}
Expand All @@ -51,25 +50,24 @@ class Buffer
Buffer(Buffer &&buffer)
{
m_size = buffer.m_size;
if(m_size != 0)
{
if (m_size != 0) {
data = buffer.data;
buffer.data = nullptr;
buffer.m_size = 0;
}
else
} else {
data = nullptr;
}
}
// Copies whole buffer
Buffer(const T *t, unsigned int size)
{
m_size = size;
if(size != 0) {
if (size != 0) {
data = new T[size];
memcpy(data, t, sizeof(T) * size);
}
else
} else {
data = nullptr;
}
}

~Buffer()
Expand All @@ -79,16 +77,16 @@ class Buffer

Buffer& operator=(Buffer &&buffer)
{
if(this == &buffer)
if (this == &buffer) {
return *this;
}
drop();
m_size = buffer.m_size;
if(m_size != 0) {
if (m_size != 0) {
data = buffer.data;
buffer.data = nullptr;
buffer.m_size = 0;
}
else {
} else {
data = nullptr;
}
return *this;
Expand Down Expand Up @@ -122,8 +120,9 @@ class Buffer

operator std::string_view() const
{
if (!data)
if (!data) {
return std::string_view();
}
return std::string_view(reinterpret_cast<char*>(data), m_size);
}

Expand Down Expand Up @@ -157,10 +156,9 @@ class SharedBuffer
SharedBuffer(unsigned int size)
{
m_size = size;
if(m_size != 0) {
if (m_size != 0) {
data = new T[m_size];
}
else {
} else {
data = nullptr;
}

Expand All @@ -177,7 +175,7 @@ class SharedBuffer
}
SharedBuffer & operator=(const SharedBuffer & buffer)
{
if(this == &buffer) {
if (this == &buffer) {
return *this;
}

Expand All @@ -194,11 +192,10 @@ class SharedBuffer
SharedBuffer(const T *t, unsigned int size)
{
m_size = size;
if(m_size != 0) {
if (m_size != 0) {
data = new T[m_size];
memcpy(data, t, sizeof(T) * m_size);
}
else {
} else {
data = nullptr;
}
refcount = new unsigned int;
Expand All @@ -207,14 +204,13 @@ class SharedBuffer
/*
Copies whole buffer
*/
SharedBuffer(const Buffer<T> &buffer)
SharedBuffer(const Buffer<T> &buffer) : SharedBuffer(*buffer, buffer.getSize())
{
m_size = buffer.getSize();
if (m_size != 0) {
data = new T[m_size];
memcpy(data, *buffer, sizeof(T) * m_size);
}
else {
} else {
data = nullptr;
}

Expand Down Expand Up @@ -247,8 +243,7 @@ class SharedBuffer
{
assert((*refcount) > 0);
(*refcount)--;
if(*refcount == 0)
{
if (*refcount == 0) {
delete[] data;
delete refcount;
}
Expand Down

0 comments on commit 13e8caa

Please sign in to comment.