Skip to content

Commit f0f0efe

Browse files
dbaileychessaardappel
authored andcommitted
[C++] Refactor to conform to Google C++ style guide (#5608)
* Automatic refractor of C++ headers to Google C++ style guide * Automatic refractor of C++ source to Google C++ style guide * Automatic refractor of C++ tests to Google C++ style guide * Fixed clang-format issues by running clang-format twice to correct itself. Kotlin was missing clang-format on after turning it off, so it was changed,
1 parent e837d5a commit f0f0efe

36 files changed

+3118
-3255
lines changed

include/flatbuffers/code_generators.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <map>
2121
#include <sstream>
22+
2223
#include "flatbuffers/idl.h"
2324

2425
namespace flatbuffers {
@@ -95,8 +96,7 @@ class BaseGenerator {
9596

9697
protected:
9798
BaseGenerator(const Parser &parser, const std::string &path,
98-
const std::string &file_name,
99-
std::string qualifying_start,
99+
const std::string &file_name, std::string qualifying_start,
100100
std::string qualifying_separator)
101101
: parser_(parser),
102102
path_(path),

include/flatbuffers/flatbuffers.h

Lines changed: 87 additions & 92 deletions
Large diffs are not rendered by default.

include/flatbuffers/flatc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <functional>
1818
#include <limits>
1919
#include <string>
20+
2021
#include "flatbuffers/flatbuffers.h"
2122
#include "flatbuffers/idl.h"
2223
#include "flatbuffers/util.h"

include/flatbuffers/flexbuffers.h

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ class Map : public Vector {
339339

340340
template<typename T>
341341
void AppendToString(std::string &s, T &&v, bool keys_quoted) {
342-
s += "[ ";
343-
for (size_t i = 0; i < v.size(); i++) {
344-
if (i) s += ", ";
345-
v[i].ToString(true, keys_quoted, s);
346-
}
347-
s += " ]";
342+
s += "[ ";
343+
for (size_t i = 0; i < v.size(); i++) {
344+
if (i) s += ", ";
345+
v[i].ToString(true, keys_quoted, s);
346+
}
347+
s += " ]";
348348
}
349349

350350
class Reference {
@@ -386,13 +386,17 @@ class Reference {
386386
bool IsVector() const { return type_ == FBT_VECTOR || type_ == FBT_MAP; }
387387
bool IsUntypedVector() const { return type_ == FBT_VECTOR; }
388388
bool IsTypedVector() const { return flexbuffers::IsTypedVector(type_); }
389-
bool IsFixedTypedVector() const { return flexbuffers::IsFixedTypedVector(type_); }
390-
bool IsAnyVector() const { return (IsTypedVector() || IsFixedTypedVector() || IsVector());}
389+
bool IsFixedTypedVector() const {
390+
return flexbuffers::IsFixedTypedVector(type_);
391+
}
392+
bool IsAnyVector() const {
393+
return (IsTypedVector() || IsFixedTypedVector() || IsVector());
394+
}
391395
bool IsMap() const { return type_ == FBT_MAP; }
392396
bool IsBlob() const { return type_ == FBT_BLOB; }
393397
bool AsBool() const {
394398
return (type_ == FBT_BOOL ? ReadUInt64(data_, parent_width_)
395-
: AsUInt64()) != 0;
399+
: AsUInt64()) != 0;
396400
}
397401

398402
// Reads any type as a int64_t. Never fails, does most sensible conversion.
@@ -555,7 +559,8 @@ class Reference {
555559
AppendToString<FixedTypedVector>(s, AsFixedTypedVector(), keys_quoted);
556560
} else if (IsBlob()) {
557561
auto blob = AsBlob();
558-
flatbuffers::EscapeString(reinterpret_cast<const char*>(blob.data()), blob.size(), &s, true, false);
562+
flatbuffers::EscapeString(reinterpret_cast<const char *>(blob.data()),
563+
blob.size(), &s, true, false);
559564
} else {
560565
s += "(?)";
561566
}
@@ -729,9 +734,15 @@ template<> inline int32_t Reference::As<int32_t>() const { return AsInt32(); }
729734
template<> inline int64_t Reference::As<int64_t>() const { return AsInt64(); }
730735

731736
template<> inline uint8_t Reference::As<uint8_t>() const { return AsUInt8(); }
732-
template<> inline uint16_t Reference::As<uint16_t>() const { return AsUInt16(); }
733-
template<> inline uint32_t Reference::As<uint32_t>() const { return AsUInt32(); }
734-
template<> inline uint64_t Reference::As<uint64_t>() const { return AsUInt64(); }
737+
template<> inline uint16_t Reference::As<uint16_t>() const {
738+
return AsUInt16();
739+
}
740+
template<> inline uint32_t Reference::As<uint32_t>() const {
741+
return AsUInt32();
742+
}
743+
template<> inline uint64_t Reference::As<uint64_t>() const {
744+
return AsUInt64();
745+
}
735746

736747
template<> inline double Reference::As<double>() const { return AsDouble(); }
737748
template<> inline float Reference::As<float>() const { return AsFloat(); }
@@ -920,9 +931,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
920931
Bool(b);
921932
}
922933

923-
void IndirectInt(int64_t i) {
924-
PushIndirect(i, FBT_INDIRECT_INT, WidthI(i));
925-
}
934+
void IndirectInt(int64_t i) { PushIndirect(i, FBT_INDIRECT_INT, WidthI(i)); }
926935
void IndirectInt(const char *key, int64_t i) {
927936
Key(key);
928937
IndirectInt(i);
@@ -1214,9 +1223,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
12141223
// Works on any data type.
12151224
struct Value;
12161225
Value LastValue() { return stack_.back(); }
1217-
void ReuseValue(Value v) {
1218-
stack_.push_back(v);
1219-
}
1226+
void ReuseValue(Value v) { stack_.push_back(v); }
12201227
void ReuseValue(const char *key, Value v) {
12211228
Key(key);
12221229
ReuseValue(v);
@@ -1462,7 +1469,9 @@ class Builder FLATBUFFERS_FINAL_CLASS {
14621469

14631470
Value CreateVector(size_t start, size_t vec_len, size_t step, bool typed,
14641471
bool fixed, const Value *keys = nullptr) {
1465-
FLATBUFFERS_ASSERT(!fixed || typed); // typed=false, fixed=true combination is not supported.
1472+
FLATBUFFERS_ASSERT(
1473+
!fixed ||
1474+
typed); // typed=false, fixed=true combination is not supported.
14661475
// Figure out smallest bit width we can store this vector with.
14671476
auto bit_width = (std::max)(force_min_bit_width_, WidthU(vec_len));
14681477
auto prefix_elems = 1;
@@ -1542,7 +1551,8 @@ class Builder FLATBUFFERS_FINAL_CLASS {
15421551

15431552
typedef std::pair<size_t, size_t> StringOffset;
15441553
struct StringOffsetCompare {
1545-
explicit StringOffsetCompare(const std::vector<uint8_t> &buf) : buf_(&buf) {}
1554+
explicit StringOffsetCompare(const std::vector<uint8_t> &buf)
1555+
: buf_(&buf) {}
15461556
bool operator()(const StringOffset &a, const StringOffset &b) const {
15471557
auto stra = reinterpret_cast<const char *>(
15481558
flatbuffers::vector_data(*buf_) + a.first);
@@ -1562,8 +1572,8 @@ class Builder FLATBUFFERS_FINAL_CLASS {
15621572

15631573
} // namespace flexbuffers
15641574

1565-
# if defined(_MSC_VER)
1566-
# pragma warning(pop)
1567-
# endif
1575+
#if defined(_MSC_VER)
1576+
# pragma warning(pop)
1577+
#endif
15681578

15691579
#endif // FLATBUFFERS_FLEXBUFFERS_H_

include/flatbuffers/grpc.h

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ class SliceAllocator : public Allocator {
8888
SliceAllocator(const SliceAllocator &other) = delete;
8989
SliceAllocator &operator=(const SliceAllocator &other) = delete;
9090

91-
SliceAllocator(SliceAllocator &&other)
92-
: slice_(grpc_empty_slice()) {
91+
SliceAllocator(SliceAllocator &&other) : slice_(grpc_empty_slice()) {
9392
// default-construct and swap idiom
9493
swap(other);
9594
}
@@ -164,34 +163,36 @@ class MessageBuilder : private detail::SliceAllocatorMember,
164163
public FlatBufferBuilder {
165164
public:
166165
explicit MessageBuilder(uoffset_t initial_size = 1024)
167-
: FlatBufferBuilder(initial_size, &slice_allocator_, false) {}
166+
: FlatBufferBuilder(initial_size, &slice_allocator_, false) {}
168167

169168
MessageBuilder(const MessageBuilder &other) = delete;
170169
MessageBuilder &operator=(const MessageBuilder &other) = delete;
171170

172171
MessageBuilder(MessageBuilder &&other)
173-
: FlatBufferBuilder(1024, &slice_allocator_, false) {
172+
: FlatBufferBuilder(1024, &slice_allocator_, false) {
174173
// Default construct and swap idiom.
175174
Swap(other);
176175
}
177176

178177
/// Create a MessageBuilder from a FlatBufferBuilder.
179-
explicit MessageBuilder(FlatBufferBuilder &&src, void (*dealloc)(void*, size_t) = &DefaultAllocator::dealloc)
180-
: FlatBufferBuilder(1024, &slice_allocator_, false) {
178+
explicit MessageBuilder(FlatBufferBuilder &&src,
179+
void (*dealloc)(void *,
180+
size_t) = &DefaultAllocator::dealloc)
181+
: FlatBufferBuilder(1024, &slice_allocator_, false) {
181182
src.Swap(*this);
182183
src.SwapBufAllocator(*this);
183184
if (buf_.capacity()) {
184-
uint8_t *buf = buf_.scratch_data(); // pointer to memory
185-
size_t capacity = buf_.capacity(); // size of memory
185+
uint8_t *buf = buf_.scratch_data(); // pointer to memory
186+
size_t capacity = buf_.capacity(); // size of memory
186187
slice_allocator_.slice_ = grpc_slice_new_with_len(buf, capacity, dealloc);
187-
}
188-
else {
188+
} else {
189189
slice_allocator_.slice_ = grpc_empty_slice();
190190
}
191191
}
192192

193193
/// Move-assign a FlatBufferBuilder to a MessageBuilder.
194-
/// Only FlatBufferBuilder with default allocator (basically, nullptr) is supported.
194+
/// Only FlatBufferBuilder with default allocator (basically, nullptr) is
195+
/// supported.
195196
MessageBuilder &operator=(FlatBufferBuilder &&src) {
196197
// Move construct a temporary and swap
197198
MessageBuilder temp(std::move(src));
@@ -209,10 +210,11 @@ class MessageBuilder : private detail::SliceAllocatorMember,
209210
void Swap(MessageBuilder &other) {
210211
slice_allocator_.swap(other.slice_allocator_);
211212
FlatBufferBuilder::Swap(other);
212-
// After swapping the FlatBufferBuilder, we swap back the allocator, which restores
213-
// the original allocator back in place. This is necessary because MessageBuilder's
214-
// allocator is its own member (SliceAllocatorMember). The allocator passed to
215-
// FlatBufferBuilder::vector_downward must point to this member.
213+
// After swapping the FlatBufferBuilder, we swap back the allocator, which
214+
// restores the original allocator back in place. This is necessary because
215+
// MessageBuilder's allocator is its own member (SliceAllocatorMember). The
216+
// allocator passed to FlatBufferBuilder::vector_downward must point to this
217+
// member.
216218
buf_.swap_allocator(other.buf_);
217219
}
218220

@@ -232,10 +234,10 @@ class MessageBuilder : private detail::SliceAllocatorMember,
232234
// flatbuffers-encoded region and wraps it in a `Message<T>` to handle buffer
233235
// ownership.
234236
template<class T> Message<T> GetMessage() {
235-
auto buf_data = buf_.scratch_data(); // pointer to memory
236-
auto buf_size = buf_.capacity(); // size of memory
237-
auto msg_data = buf_.data(); // pointer to msg
238-
auto msg_size = buf_.size(); // size of msg
237+
auto buf_data = buf_.scratch_data(); // pointer to memory
238+
auto buf_size = buf_.capacity(); // size of memory
239+
auto msg_data = buf_.data(); // pointer to msg
240+
auto msg_size = buf_.size(); // size of msg
239241
// Do some sanity checks on data/size
240242
FLATBUFFERS_ASSERT(msg_data);
241243
FLATBUFFERS_ASSERT(msg_size);

include/flatbuffers/hash.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,25 @@ template<typename T> T HashFnv1a(const char *input) {
5757
return hash;
5858
}
5959

60-
template <> inline uint16_t HashFnv1<uint16_t>(const char *input) {
60+
template<> inline uint16_t HashFnv1<uint16_t>(const char *input) {
6161
uint32_t hash = HashFnv1<uint32_t>(input);
6262
return (hash >> 16) ^ (hash & 0xffff);
6363
}
6464

65-
template <> inline uint16_t HashFnv1a<uint16_t>(const char *input) {
65+
template<> inline uint16_t HashFnv1a<uint16_t>(const char *input) {
6666
uint32_t hash = HashFnv1a<uint32_t>(input);
6767
return (hash >> 16) ^ (hash & 0xffff);
6868
}
6969

70-
template <typename T> struct NamedHashFunction {
70+
template<typename T> struct NamedHashFunction {
7171
const char *name;
7272

7373
typedef T (*HashFunction)(const char *);
7474
HashFunction function;
7575
};
7676

7777
const NamedHashFunction<uint16_t> kHashFunctions16[] = {
78-
{ "fnv1_16", HashFnv1<uint16_t> },
78+
{ "fnv1_16", HashFnv1<uint16_t> },
7979
{ "fnv1a_16", HashFnv1a<uint16_t> },
8080
};
8181

0 commit comments

Comments
 (0)