summaryrefslogtreecommitdiff
path: root/core/ring_buffer.h
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /core/ring_buffer.h
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
Diffstat (limited to 'core/ring_buffer.h')
-rw-r--r--core/ring_buffer.h52
1 files changed, 25 insertions, 27 deletions
diff --git a/core/ring_buffer.h b/core/ring_buffer.h
index a4da0086e0..3c13cb8d1e 100644
--- a/core/ring_buffer.h
+++ b/core/ring_buffer.h
@@ -39,31 +39,30 @@ class RingBuffer {
int write_pos;
int size_mask;
- inline int inc(int& p_var, int p_size) {
+ inline int inc(int &p_var, int p_size) {
int ret = p_var;
p_var += p_size;
- p_var = p_var&size_mask;
+ p_var = p_var & size_mask;
return ret;
};
public:
-
T read() {
ERR_FAIL_COND_V(space_left() < 1, T());
return data[inc(read_pos, 1)];
};
- int read(T* p_buf, int p_size, bool p_advance=true) {
+ int read(T *p_buf, int p_size, bool p_advance = true) {
int left = data_left();
p_size = MIN(left, p_size);
int pos = read_pos;
int to_read = p_size;
int dst = 0;
- while(to_read) {
+ while (to_read) {
int end = pos + to_read;
end = MIN(end, size());
int total = end - pos;
- for (int i=0; i<total; i++) {
+ for (int i = 0; i < total; i++) {
p_buf[dst++] = data[pos + i];
};
to_read -= total;
@@ -75,24 +74,24 @@ public:
return p_size;
};
- int copy(T* p_buf, int p_offset, int p_size) {
+ int copy(T *p_buf, int p_offset, int p_size) {
int left = data_left();
- if ((p_offset+p_size)>left) {
- p_size-=left-p_offset;
- if (p_size<=0)
+ if ((p_offset + p_size) > left) {
+ p_size -= left - p_offset;
+ if (p_size <= 0)
return 0;
}
p_size = MIN(left, p_size);
int pos = read_pos;
- inc(pos,p_offset);
+ inc(pos, p_offset);
int to_read = p_size;
int dst = 0;
- while(to_read) {
+ while (to_read) {
int end = pos + to_read;
end = MIN(end, size());
int total = end - pos;
- for (int i=0; i<total; i++) {
+ for (int i = 0; i < total; i++) {
p_buf[dst++] = data[pos + i];
};
to_read -= total;
@@ -107,13 +106,13 @@ public:
return p_n;
};
- Error write(const T& p_v) {
- ERR_FAIL_COND_V( space_left() < 1, FAILED);
+ Error write(const T &p_v) {
+ ERR_FAIL_COND_V(space_left() < 1, FAILED);
data[inc(write_pos, 1)] = p_v;
return OK;
};
- int write(const T* p_buf, int p_size) {
+ int write(const T *p_buf, int p_size) {
int left = space_left();
p_size = MIN(left, p_size);
@@ -127,8 +126,8 @@ public:
end = MIN(end, size());
int total = end - pos;
- for (int i=0; i<total; i++) {
- data[pos+i] = p_buf[src++];
+ for (int i = 0; i < total; i++) {
+ data[pos + i] = p_buf[src++];
};
to_write -= total;
pos = 0;
@@ -144,9 +143,9 @@ public:
return size() + left - 1;
};
if (left == 0) {
- return size()-1;
+ return size() - 1;
};
- return left -1;
+ return left - 1;
};
inline int data_left() {
return size() - space_left() - 1;
@@ -159,17 +158,16 @@ public:
inline void clear() {
read_pos = 0;
write_pos = 0;
-
}
void resize(int p_power) {
int old_size = size();
- int new_size = 1<<p_power;
+ int new_size = 1 << p_power;
int mask = new_size - 1;
- data.resize(1<<p_power);
+ data.resize(1 << p_power);
if (old_size < new_size && read_pos > write_pos) {
- for (int i=0; i<write_pos; i++) {
- data[(old_size + i)&mask] = data[i];
+ for (int i = 0; i < write_pos; i++) {
+ data[(old_size + i) & mask] = data[i];
};
write_pos = (old_size + write_pos) & mask;
} else {
@@ -180,12 +178,12 @@ public:
size_mask = mask;
};
- RingBuffer<T>(int p_power=0) {
+ RingBuffer<T>(int p_power = 0) {
read_pos = 0;
write_pos = 0;
resize(p_power);
};
- ~RingBuffer<T>() {};
+ ~RingBuffer<T>(){};
};
#endif