use of Google Style (clang-format)

Summary: use of Google Style (clang-format)

Test Plan: manual

Reviewers: sale

Reviewed By: sale

Subscribers: buda

Differential Revision: https://phabricator.memgraph.io/D39
This commit is contained in:
Marko Budiselic 2017-01-23 12:02:11 +01:00
parent 9fcd324eca
commit 28ad69b536
5 changed files with 89 additions and 190 deletions

View File

@ -1,89 +1,6 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 1
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: "C++11"
TabWidth: 4
UseTab: Never
Language: Cpp
BasedOnStyle: Google
Standard: "C++11"
UseTab: Never
...

View File

@ -1,5 +1,5 @@
#include <iostream>
#include <signal.h>
#include <iostream>
#include "communication/bolt/v1/server/server.hpp"
#include "communication/bolt/v1/server/worker.hpp"
@ -20,74 +20,69 @@ Logger logger;
// TODO: load from config
static constexpr const char *interface = "0.0.0.0";
static constexpr const char *port = "7687";
static constexpr const char *port = "7687";
void throw_and_stacktace(std::string message)
{
Stacktrace stacktrace;
logger.info(stacktrace.dump());
void throw_and_stacktace(std::string message) {
Stacktrace stacktrace;
logger.info(stacktrace.dump());
}
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
// logging init
#ifdef SYNC_LOGGER
logging::init_sync();
logging::init_sync();
#else
logging::init_async();
logging::init_async();
#endif
logging::log->pipe(std::make_unique<Stdout>());
logging::log->pipe(std::make_unique<Stdout>());
// get logger
logger = logging::log->logger("Main");
logger.info("{}", logging::log->type());
// get logger
logger = logging::log->logger("Main");
logger.info("{}", logging::log->type());
// unhandled exception handler init
std::set_terminate(&terminate_handler);
// unhandled exception handler init
std::set_terminate(&terminate_handler);
// signal handling init
SignalHandler::register_handler(Signal::SegmentationFault, []() {
log_stacktrace("SegmentationFault signal raised");
std::exit(EXIT_FAILURE);
});
SignalHandler::register_handler(Signal::Terminate, []() {
log_stacktrace("Terminate signal raised");
std::exit(EXIT_FAILURE);
});
SignalHandler::register_handler(Signal::Abort, []() {
log_stacktrace("Abort signal raised");
std::exit(EXIT_FAILURE);
});
// signal handling init
SignalHandler::register_handler(Signal::SegmentationFault, []() {
log_stacktrace("SegmentationFault signal raised");
std::exit(EXIT_FAILURE);
});
SignalHandler::register_handler(Signal::Terminate, []() {
log_stacktrace("Terminate signal raised");
std::exit(EXIT_FAILURE);
});
SignalHandler::register_handler(Signal::Abort, []() {
log_stacktrace("Abort signal raised");
std::exit(EXIT_FAILURE);
});
// register args
CONFIG_REGISTER_ARGS(argc, argv);
// register args
CONFIG_REGISTER_ARGS(argc, argv);
// initialize socket
io::Socket socket;
try
{
socket = io::Socket::bind(interface, port);
}
catch (io::NetworkError e)
{
logger.error("Cannot bind to socket on {} at {}", interface, port);
logger.error("{}", e.what());
std::exit(EXIT_FAILURE);
}
socket.set_non_blocking();
socket.listen(1024);
logger.info("Listening on {} at {}", interface, port);
// initialize socket
io::Socket socket;
try {
socket = io::Socket::bind(interface, port);
} catch (io::NetworkError e) {
logger.error("Cannot bind to socket on {} at {}", interface, port);
logger.error("{}", e.what());
std::exit(EXIT_FAILURE);
}
socket.set_non_blocking();
socket.listen(1024);
logger.info("Listening on {} at {}", interface, port);
// initialize server
bolt::Server<bolt::Worker> server(std::move(socket));
serverptr = &server;
// initialize server
bolt::Server<bolt::Worker> server(std::move(socket));
serverptr = &server;
// server start with N threads
// TODO: N should be configurable
auto N = std::thread::hardware_concurrency();
logger.info("Starting {} workers", N);
server.start(N);
// server start with N threads
// TODO: N should be configurable
auto N = std::thread::hardware_concurrency();
logger.info("Starting {} workers", N);
server.start(N);
logger.info("Shutting down...");
return EXIT_SUCCESS;
logger.info("Shutting down...");
return EXIT_SUCCESS;
}

View File

@ -2,43 +2,37 @@
#include <iterator>
namespace utils
{
namespace utils {
namespace fs = std::experimental::filesystem;
Text read_text(const fs::path &path)
{
std::ifstream in(path, std::ios::in | std::ios::binary);
Text read_text(const fs::path &path) {
std::ifstream in(path, std::ios::in | std::ios::binary);
if (in)
return Text(std::string(std::istreambuf_iterator<char>(in),
std::istreambuf_iterator<char>()));
if (in)
return Text(std::string(std::istreambuf_iterator<char>(in),
std::istreambuf_iterator<char>()));
auto error_message = fmt::format("{0}{1}", "Fail to read: ", path.c_str());
throw std::runtime_error(error_message);
auto error_message = fmt::format("{0}{1}", "Fail to read: ", path.c_str());
throw std::runtime_error(error_message);
}
std::vector<std::string> read_lines(const fs::path &path)
{
std::vector<std::string> lines;
std::vector<std::string> read_lines(const fs::path &path) {
std::vector<std::string> lines;
std::ifstream stream(path.c_str());
std::string line;
while (std::getline(stream, line))
{
lines.emplace_back(line);
}
std::ifstream stream(path.c_str());
std::string line;
while (std::getline(stream, line)) {
lines.emplace_back(line);
}
return lines;
return lines;
}
void write(const Text &text, const fs::path &path)
{
std::ofstream stream;
stream.open(path.c_str());
stream << text.str();
stream.close();
void write(const Text &text, const fs::path &path) {
std::ofstream stream;
stream.open(path.c_str());
stream << text.str();
stream.close();
}
}

View File

@ -1,14 +1,12 @@
#include "utils/string/join.hpp"
namespace utils
{
namespace utils {
std::string join(const std::vector<std::string>& strings, const char *separator)
{
std::ostringstream oss;
std::copy(strings.begin(), strings.end(),
std::ostream_iterator<std::string>(oss, separator));
return oss.str();
std::string join(const std::vector<std::string>& strings,
const char* separator) {
std::ostringstream oss;
std::copy(strings.begin(), strings.end(),
std::ostream_iterator<std::string>(oss, separator));
return oss.str();
}
}

View File

@ -1,17 +1,12 @@
#include "utils/string/transform.hpp"
namespace utils
{
namespace utils {
// TODO CPPCheck -> function never used
void str_tolower(std::string& s)
{
// en_US.utf8 localization
std::transform(s.begin(), s.end(), s.begin(),
[](unsigned char c) {
return std::tolower(c, std::locale("en_US.utf8"));
}
);
void str_tolower(std::string& s) {
// en_US.utf8 localization
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) {
return std::tolower(c, std::locale("en_US.utf8"));
});
}
}