Skip to content

Commit b1cb544

Browse files
Formatted code
1 parent 32b0438 commit b1cb544

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

include/builder/static_var.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class static_var {
5757

5858
template <typename T>
5959
class static_var<T[]> {
60-
public:
60+
public:
6161
static_assert(std::is_same<T, short int>::value || std::is_same<T, unsigned short int>::value ||
6262
std::is_same<T, int>::value || std::is_same<T, unsigned int>::value ||
6363
std::is_same<T, long int>::value || std::is_same<T, unsigned long int>::value ||
@@ -68,41 +68,43 @@ class static_var<T[]> {
6868
static_assert(sizeof(T) < MAX_TRACKING_VAR_SIZE, "Currently builder::static_var supports variables of max size "
6969
"= " TOSTRING(MAX_TRACKING_VARIABLE_SIZE));
7070
// Disable copy-assignment and initialization
71-
static_var(const static_var& x) = delete;
72-
static_var& operator= (const static_var& x) = delete;
73-
T* val = nullptr;
74-
75-
T& operator[] (size_t index) {
71+
static_var(const static_var &x) = delete;
72+
static_var &operator=(const static_var &x) = delete;
73+
T *val = nullptr;
74+
75+
T &operator[](size_t index) {
7676
return val[index];
7777
}
78-
const T& operator[] (size_t index) const {
78+
const T &operator[](size_t index) const {
7979
return val[index];
8080
}
8181
static_var() {
8282
assert(builder_context::current_builder_context != nullptr);
8383
// This val _should_ not be used. But we will insert it to hold place
8484
// for this static var in the list of tuples, otherwise destructor order will be weird
8585
val = new T[1];
86-
86+
8787
builder_context::current_builder_context->static_var_tuples.push_back(
88-
tracking_tuple((unsigned char*)val, 1));
88+
tracking_tuple((unsigned char *)val, 1));
8989
}
9090
static_var(const std::initializer_list<T> &list) {
9191
assert(builder_context::current_builder_context != nullptr);
9292
val = new T[list.size()];
9393
builder_context::current_builder_context->static_var_tuples.push_back(
94-
tracking_tuple((unsigned char*)val, sizeof(T) * list.size()));
94+
tracking_tuple((unsigned char *)val, sizeof(T) * list.size()));
9595
for (int i = 0; i < list.size(); i++) {
9696
val[i] = list[i];
9797
}
9898
}
9999
void resize(size_t s) {
100-
T* new_ptr = new T[s];
100+
T *new_ptr = new T[s];
101101
assert(builder_context::current_builder_context != nullptr);
102102
assert(builder_context::current_builder_context->static_var_tuples.size() > 0);
103103
for (size_t i = 0; i < builder_context::current_builder_context->static_var_tuples.size(); i++) {
104-
if (builder_context::current_builder_context->static_var_tuples[i].ptr == (unsigned char*)val) {
105-
builder_context::current_builder_context->static_var_tuples[i] = tracking_tuple((unsigned char*)new_ptr, sizeof(T) * s);
104+
if (builder_context::current_builder_context->static_var_tuples[i].ptr ==
105+
(unsigned char *)val) {
106+
builder_context::current_builder_context->static_var_tuples[i] =
107+
tracking_tuple((unsigned char *)new_ptr, sizeof(T) * s);
106108
break;
107109
}
108110
}
@@ -114,7 +116,7 @@ class static_var<T[]> {
114116
assert(builder_context::current_builder_context->static_var_tuples.size() > 0);
115117
assert(builder_context::current_builder_context->static_var_tuples.back().ptr == (unsigned char *)val);
116118
builder_context::current_builder_context->static_var_tuples.pop_back();
117-
delete[] val;
119+
delete[] val;
118120
}
119121
};
120122
} // namespace builder

samples/sample47.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "builder/static_var.h"
2-
#include "builder/dyn_var.h"
31
#include "blocks/c_code_generator.h"
2+
#include "builder/dyn_var.h"
3+
#include "builder/static_var.h"
44

55
using builder::dyn_var;
66
using builder::static_var;
@@ -12,7 +12,7 @@ static void foo(void) {
1212
for (states[1] = 0; states[1] < 2; states[1]++) {
1313
for (states[2] = 0; states[2] < 2; states[2]++) {
1414
for (states[3] = 0; states[3] < 2; states[3]++) {
15-
dyn_var<int> c = 0;
15+
dyn_var<int> c = 0;
1616
}
1717
}
1818
}

0 commit comments

Comments
 (0)