Skip to content

Commit

Permalink
Made all C++ files clang-formatted.
Browse files Browse the repository at this point in the history
Also added missing generated files.

Change-Id: Ifd22a643a08e3f2edfce92812ed57b87fc0e1875
  • Loading branch information
aardappel committed Dec 21, 2017
1 parent 5d9930a commit 89711c9
Show file tree
Hide file tree
Showing 43 changed files with 5,743 additions and 5,885 deletions.
10 changes: 8 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
---
Language: Cpp
BasedOnStyle: Google
Language: Cpp
BasedOnStyle: Google
DerivePointerAlignment: false
PointerAlignment: Right
IndentPPDirectives: AfterHash
Cpp11BracedListStyle: false
AlwaysBreakTemplateDeclarations: false
AllowShortCaseLabelsOnASingleLine: true
SpaceAfterTemplateKeyword: false
AllowShortBlocksOnASingleLine: true
...

4 changes: 2 additions & 2 deletions grpc/src/compiler/schema_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
#include <vector>

#ifndef GRPC_CUSTOM_STRING
#include <string>
#define GRPC_CUSTOM_STRING std::string
# include <string>
# define GRPC_CUSTOM_STRING std::string
#endif

namespace grpc {
Expand Down
64 changes: 33 additions & 31 deletions grpc/tests/grpctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,48 @@

#include <grpc++/grpc++.h>

#include "monster_test_generated.h"
#include "monster_test.grpc.fb.h"
#include "monster_test_generated.h"

using namespace MyGame::Example;

// The callback implementation of our server, that derives from the generated
// code. It implements all rpcs specified in the FlatBuffers schema.
class ServiceImpl final : public MyGame::Example::MonsterStorage::Service {
virtual ::grpc::Status Store(::grpc::ServerContext* context,
const flatbuffers::grpc::Message<Monster> *request,
flatbuffers::grpc::Message<Stat> *response)
override {
virtual ::grpc::Status Store(
::grpc::ServerContext *context,
const flatbuffers::grpc::Message<Monster> *request,
flatbuffers::grpc::Message<Stat> *response) override {
// Create a response from the incoming request name.
fbb_.Clear();
auto stat_offset = CreateStat(fbb_, fbb_.CreateString("Hello, " +
request->GetRoot()->name()->str()));
auto stat_offset = CreateStat(
fbb_, fbb_.CreateString("Hello, " + request->GetRoot()->name()->str()));
fbb_.Finish(stat_offset);
// Transfer ownership of the message to gRPC
*response = fbb_.ReleaseMessage<Stat>();
return grpc::Status::OK;
}
virtual ::grpc::Status Retrieve(::grpc::ServerContext *context,
const flatbuffers::grpc::Message<Stat> *request,
::grpc::ServerWriter< flatbuffers::grpc::Message<Monster>>* writer)
override {

for (int i=0; i<10; i++) {
fbb_.Clear();
// Create 10 monsters for resposne.
auto monster_offset =
CreateMonster(fbb_, 0, 0, 0, fbb_.CreateString(
request->GetRoot()->id()->str() + " No." + std::to_string(i)));
fbb_.Finish(monster_offset);

flatbuffers::grpc::Message<Monster> monster = fbb_.ReleaseMessage<Monster>();

// Send monster to client using streaming.
writer->Write(monster);
}
return grpc::Status::OK;
virtual ::grpc::Status Retrieve(
::grpc::ServerContext *context,
const flatbuffers::grpc::Message<Stat> *request,
::grpc::ServerWriter<flatbuffers::grpc::Message<Monster>> *writer)
override {
for (int i = 0; i < 10; i++) {
fbb_.Clear();
// Create 10 monsters for resposne.
auto monster_offset =
CreateMonster(fbb_, 0, 0, 0,
fbb_.CreateString(request->GetRoot()->id()->str() +
" No." + std::to_string(i)));
fbb_.Finish(monster_offset);

flatbuffers::grpc::Message<Monster> monster =
fbb_.ReleaseMessage<Monster>();

// Send monster to client using streaming.
writer->Write(monster);
}
return grpc::Status::OK;
}

private:
Expand Down Expand Up @@ -90,7 +92,7 @@ void RunServer() {
server_instance->Wait();
}

int main(int /*argc*/, const char * /*argv*/[]) {
int main(int /*argc*/, const char * /*argv*/ []) {
// Launch server.
std::thread server_thread(RunServer);

Expand All @@ -103,7 +105,6 @@ int main(int /*argc*/, const char * /*argv*/[]) {
grpc::InsecureChannelCredentials());
auto stub = MyGame::Example::MonsterStorage::NewStub(channel);


flatbuffers::grpc::MessageBuilder fbb;
{
grpc::ClientContext context;
Expand Down Expand Up @@ -138,7 +139,7 @@ int main(int /*argc*/, const char * /*argv*/[]) {
}
}

#if !FLATBUFFERS_GRPC_DISABLE_AUTO_VERIFICATION
#if !FLATBUFFERS_GRPC_DISABLE_AUTO_VERIFICATION
{
// Test that an invalid request errors out correctly
grpc::ClientContext context;
Expand All @@ -149,9 +150,10 @@ int main(int /*argc*/, const char * /*argv*/[]) {
// matches the protobuf gRPC status code for an unparseable message.
assert(!status.ok());
assert(status.error_code() == ::grpc::StatusCode::INTERNAL);
assert(strcmp(status.error_message().c_str(), "Message verification failed") == 0);
assert(strcmp(status.error_message().c_str(),
"Message verification failed") == 0);
}
#endif
#endif

server_instance->Shutdown();

Expand Down
1 change: 1 addition & 0 deletions include/flatbuffers/base.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef FLATBUFFERS_BASE_H_
#define FLATBUFFERS_BASE_H_

// clang-format off
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
defined(_MSC_VER) && defined(_DEBUG)
#define _CRTDBG_MAP_ALLOC
Expand Down
8 changes: 3 additions & 5 deletions include/flatbuffers/code_generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CodeWriter {
// Associates a key with a value. All subsequent calls to operator+=, where
// the specified key is contained in {{ and }} delimiters will be replaced by
// the given value.
void SetValue(const std::string& key, const std::string& value) {
void SetValue(const std::string &key, const std::string &value) {
value_map_[key] = value;
}

Expand All @@ -71,8 +71,7 @@ class BaseGenerator {
public:
virtual bool generate() = 0;

static std::string NamespaceDir(const Parser &parser,
const std::string &path,
static std::string NamespaceDir(const Parser &parser, const std::string &path,
const Namespace &ns);

protected:
Expand Down Expand Up @@ -128,8 +127,7 @@ struct CommentConfig {
};

extern void GenComment(const std::vector<std::string> &dc,
std::string *code_ptr,
const CommentConfig *config,
std::string *code_ptr, const CommentConfig *config,
const char *prefix = "");

} // namespace flatbuffers
Expand Down
Loading

0 comments on commit 89711c9

Please sign in to comment.