Skip to content

Commit 657e8fa

Browse files
authored
Merge pull request #235 from riptano/CPP-769
CPP-769 Use clang-format to fix up formatting
2 parents 0c8d1eb + 1a37d1f commit 657e8fa

575 files changed

Lines changed: 17815 additions & 21813 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
BasedOnStyle: LLVM
3+
Language: Cpp
4+
Standard: Cpp03
5+
AccessModifierOffset: -2
6+
IndentWidth: 2
7+
TabWidth: 8
8+
ColumnLimit: 100
9+
UseTab: Never
10+
IndentCaseLabels: true
11+
AlignAfterOpenBracket: true
12+
AlignEscapedNewlines: Left
13+
BreakConstructorInitializers: BeforeComma
14+
AllowShortBlocksOnASingleLine: false
15+
DerivePointerAlignment: false
16+
PointerAlignment: Left
17+
BinPackParameters: true
18+
BinPackArguments: true
19+
AllowShortIfStatementsOnASingleLine: true
20+
CompactNamespaces: true
21+
AlignOperands: true
22+
SpacesInContainerLiterals: true
23+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
24+
Cpp11BracedListStyle: false
25+
AlwaysBreakTemplateDeclarations: true
26+
BreakBeforeInheritanceComma: true
27+
...

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ list(APPEND CMAKE_MODULE_PATH ${CASS_ROOT_DIR}/cmake/modules
1717
)
1818

1919
include(CppDriver)
20+
include(ClangFormat)
2021

2122
CassInitProject(dse)
2223
CassRapidJson()

cpp-driver/.build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ build_driver() {
7373
(
7474
cd build
7575
cmake -DCMAKE_BUILD_TYPE=Release -D${driver_prefix}_BUILD_SHARED=On -D${driver_prefix}_BUILD_STATIC=On -D${driver_prefix}_BUILD_EXAMPLES=On -D${driver_prefix}_BUILD_UNIT_TESTS=On ..
76+
[[ -x $(which clang-format) ]] && make format-check
7677
make -j${PROCS}
7778
)
7879
}

cpp-driver/.clang-format

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
BasedOnStyle: LLVM
3+
Language: Cpp
4+
Standard: Cpp03
5+
AccessModifierOffset: -2
6+
IndentWidth: 2
7+
TabWidth: 8
8+
ColumnLimit: 100
9+
UseTab: Never
10+
IndentCaseLabels: true
11+
AlignAfterOpenBracket: true
12+
AlignEscapedNewlines: Left
13+
BreakConstructorInitializers: BeforeComma
14+
AllowShortBlocksOnASingleLine: false
15+
DerivePointerAlignment: false
16+
PointerAlignment: Left
17+
BinPackParameters: true
18+
BinPackArguments: true
19+
AllowShortIfStatementsOnASingleLine: true
20+
CompactNamespaces: true
21+
AlignOperands: true
22+
SpacesInContainerLiterals: true
23+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
24+
Cpp11BracedListStyle: false
25+
AlwaysBreakTemplateDeclarations: true
26+
BreakBeforeInheritanceComma: true
27+
...
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#
2+
# Format and verify formatting using clang-format
3+
#
4+
cmake_minimum_required(VERSION 2.6.4)
5+
6+
include(FindPackageHandleStandardArgs)
7+
8+
if(NOT CLANG_FORMAT_EXE_NAME)
9+
set(CLANG_FORMAT_EXE_NAME clang-format)
10+
endif()
11+
12+
if(CLANG_FORMAT_ROOT_DIR)
13+
find_program(CLANG_FORMAT_EXE
14+
NAMES ${CLANG_FORMAT_EXE_NAME}
15+
PATHS ${CLANG_FORMAT_ROOT_DIR}
16+
NO_DEFAULT_PATH)
17+
endif()
18+
19+
find_program(CLANG_FORMAT_EXE NAMES ${CLANG_FORMAT_EXE_NAME})
20+
21+
find_package_handle_standard_args(CLANG_FORMAT DEFAULT_MSG CLANG_FORMAT_EXE)
22+
23+
mark_as_advanced(CLANG_FORMAT_EXE)
24+
25+
if(CLANG_FORMAT_FOUND)
26+
set(CLANG_FORMAT_FILE_EXTENSIONS ${CLANG_FORMAT_CXX_FILE_EXTENSIONS} *.cpp *.hpp *.c *.h)
27+
file(GLOB_RECURSE CLANG_FORMAT_ALL_SOURCE_FILES ${CLANG_FORMAT_FILE_EXTENSIONS})
28+
29+
set(CLANG_FORMAT_EXCLUDE_PATTERNS ${CLANG_FORMAT_EXCLUDE_PATTERNS} "/CMakeFiles/" "cmake" "/build/" "/vendor/" "/third_party/" "cassandra.h" "dse.h")
30+
31+
foreach (SOURCE_FILE ${CLANG_FORMAT_ALL_SOURCE_FILES})
32+
foreach (EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS})
33+
string(FIND ${SOURCE_FILE} ${EXCLUDE_PATTERN} EXCLUDE_FOUND)
34+
if (NOT ${EXCLUDE_FOUND} EQUAL -1)
35+
list(REMOVE_ITEM CLANG_FORMAT_ALL_SOURCE_FILES ${SOURCE_FILE})
36+
endif ()
37+
endforeach ()
38+
endforeach ()
39+
40+
add_custom_target(format
41+
COMMENT "Format source files using clang-format"
42+
COMMAND ${CLANG_FORMAT_EXE} -i -fallback-style=none -style=file ${CLANG_FORMAT_ALL_SOURCE_FILES})
43+
44+
add_custom_target(format-check
45+
COMMENT "Verify source files formatting using clang-format"
46+
COMMAND ! ${CLANG_FORMAT_EXE} -output-replacements-xml -fallback-style=none -style=file ${CLANG_FORMAT_ALL_SOURCE_FILES} | tee replacements.xml | grep -q "replacement offset")
47+
else()
48+
message(STATUS "Unable to find clang-format. Not creating format targets.")
49+
endif()

cpp-driver/examples/async/async.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
*/
2727

2828
#include <assert.h>
29-
#include <string.h>
3029
#include <stdio.h>
3130
#include <stdlib.h>
31+
#include <string.h>
3232

3333
#include "cassandra.h"
3434

@@ -41,7 +41,6 @@ void print_error(CassFuture* future) {
4141
fprintf(stderr, "Error: %.*s\n", (int)message_length, message);
4242
}
4343

44-
4544
CassCluster* create_cluster(const char* hosts) {
4645
CassCluster* cluster = cass_cluster_new();
4746
cass_cluster_set_contact_points(cluster, hosts);
@@ -90,7 +89,7 @@ void insert_into_async(CassSession* session, const char* key) {
9089

9190
size_t i;
9291
for (i = 0; i < NUM_CONCURRENT_REQUESTS; ++i) {
93-
char key_buffer[64];
92+
char key_buffer[64];
9493
statement = cass_statement_new(query, 6);
9594

9695
sprintf(key_buffer, "%s%u", key, (unsigned int)i);
@@ -135,13 +134,10 @@ int main(int argc, char* argv[]) {
135134
return -1;
136135
}
137136

138-
execute_query(session,
139-
"CREATE KEYSPACE examples WITH replication = { \
137+
execute_query(session, "CREATE KEYSPACE examples WITH replication = { \
140138
'class': 'SimpleStrategy', 'replication_factor': '3' };");
141139

142-
143-
execute_query(session,
144-
"CREATE TABLE examples.async (key text, \
140+
execute_query(session, "CREATE TABLE examples.async (key text, \
145141
bln boolean, \
146142
flt float, dbl double,\
147143
i32 int, i64 bigint, \

cpp-driver/examples/auth/auth.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ typedef struct Credentials_ {
3535
const char* username;
3636
} Credentials;
3737

38-
void on_auth_initial(CassAuthenticator* auth,
39-
void* data) {
38+
void on_auth_initial(CassAuthenticator* auth, void* data) {
4039
/*
4140
* This callback is used to initiate a request to begin an authentication
4241
* exchange. Required resources can be acquired and initialized here.
@@ -52,7 +51,7 @@ void on_auth_initial(CassAuthenticator* auth,
5251
* authentication callbacks were set and is available to all
5352
* authentication exchanges.
5453
*/
55-
const Credentials* credentials = (const Credentials *)data;
54+
const Credentials* credentials = (const Credentials*)data;
5655

5756
size_t username_size = strlen(credentials->username);
5857
size_t password_size = strlen(credentials->password);
@@ -68,20 +67,14 @@ void on_auth_initial(CassAuthenticator* auth,
6867
memcpy(response + username_size + 2, credentials->password, password_size);
6968
}
7069

71-
void on_auth_challenge(CassAuthenticator* auth,
72-
void* data,
73-
const char* token,
74-
size_t token_size) {
70+
void on_auth_challenge(CassAuthenticator* auth, void* data, const char* token, size_t token_size) {
7571
/*
7672
* Not used for plain text authentication, but this is to be used
7773
* for handling an authentication challenge initiated by the server.
7874
*/
7975
}
8076

81-
void on_auth_success(CassAuthenticator* auth,
82-
void* data,
83-
const char* token,
84-
size_t token_size ) {
77+
void on_auth_success(CassAuthenticator* auth, void* data, const char* token, size_t token_size) {
8578
/*
8679
* Not used for plain text authentication, but this is to be used
8780
* for handling the success phase of an exchange.
@@ -104,17 +97,10 @@ int main(int argc, char* argv[]) {
10497
char* hosts = "127.0.0.1,127.0.0.2,127.0.0.3";
10598

10699
/* Setup authentication callbacks and credentials */
107-
CassAuthenticatorCallbacks auth_callbacks = {
108-
on_auth_initial,
109-
on_auth_challenge,
110-
on_auth_success,
111-
on_auth_cleanup
112-
};
113-
114-
Credentials credentials = {
115-
"cassandra",
116-
"cassandra"
117-
};
100+
CassAuthenticatorCallbacks auth_callbacks = { on_auth_initial, on_auth_challenge, on_auth_success,
101+
on_auth_cleanup };
102+
103+
Credentials credentials = { "cassandra", "cassandra" };
118104

119105
/* Add contact points */
120106
if (argc > 1) {
@@ -123,10 +109,7 @@ int main(int argc, char* argv[]) {
123109
cass_cluster_set_contact_points(cluster, hosts);
124110

125111
/* Set custom authentication callbacks and credentials */
126-
cass_cluster_set_authenticator_callbacks(cluster,
127-
&auth_callbacks,
128-
NULL,
129-
&credentials);
112+
cass_cluster_set_authenticator_callbacks(cluster, &auth_callbacks, NULL, &credentials);
130113

131114
/* Provide the cluster object as configuration to connect the session */
132115
connect_future = cass_session_connect(session, cluster);
@@ -138,8 +121,7 @@ int main(int argc, char* argv[]) {
138121
const char* message;
139122
size_t message_length;
140123
cass_future_error_message(connect_future, &message, &message_length);
141-
fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length,
142-
message);
124+
fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length, message);
143125
}
144126

145127
cass_future_free(connect_future);

cpp-driver/examples/basic/basic.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
*/
2727

2828
#include <assert.h>
29-
#include <string.h>
3029
#include <stdio.h>
3130
#include <stdlib.h>
31+
#include <string.h>
3232

3333
#include "cassandra.h"
3434

@@ -92,7 +92,8 @@ CassError insert_into_basic(CassSession* session, const char* key, const Basic*
9292
CassError rc = CASS_OK;
9393
CassStatement* statement = NULL;
9494
CassFuture* future = NULL;
95-
const char* query = "INSERT INTO examples.basic (key, bln, flt, dbl, i32, i64) VALUES (?, ?, ?, ?, ?, ?);";
95+
const char* query =
96+
"INSERT INTO examples.basic (key, bln, flt, dbl, i32, i64) VALUES (?, ?, ?, ?, ?, ?);";
9697

9798
statement = cass_statement_new(query, 6);
9899

@@ -175,13 +176,10 @@ int main(int argc, char* argv[]) {
175176
return -1;
176177
}
177178

178-
execute_query(session,
179-
"CREATE KEYSPACE examples WITH replication = { \
179+
execute_query(session, "CREATE KEYSPACE examples WITH replication = { \
180180
'class': 'SimpleStrategy', 'replication_factor': '3' };");
181181

182-
183-
execute_query(session,
184-
"CREATE TABLE examples.basic (key text, \
182+
execute_query(session, "CREATE TABLE examples.basic (key text, \
185183
bln boolean, \
186184
flt float, dbl double,\
187185
i32 int, i64 bigint, \

cpp-driver/examples/batch/batch.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
*/
2727

2828
#include <assert.h>
29-
#include <string.h>
3029
#include <stdio.h>
3130
#include <stdlib.h>
31+
#include <string.h>
3232

3333
#include "cassandra.h"
3434

3535
struct Pair_ {
36-
const char* key;
37-
const char* value;
36+
const char* key;
37+
const char* value;
3838
};
3939

4040
typedef struct Pair_ Pair;
@@ -105,7 +105,8 @@ CassError prepare_insert_into_batch(CassSession* session, const CassPrepared** p
105105
return rc;
106106
}
107107

108-
CassError insert_into_batch_with_prepared(CassSession* session, const CassPrepared* prepared, const Pair* pairs) {
108+
CassError insert_into_batch_with_prepared(CassSession* session, const CassPrepared* prepared,
109+
const Pair* pairs) {
109110
CassError rc = CASS_OK;
110111
CassFuture* future = NULL;
111112
CassBatch* batch = cass_batch_new(CASS_BATCH_TYPE_LOGGED);
@@ -120,13 +121,15 @@ CassError insert_into_batch_with_prepared(CassSession* session, const CassPrepar
120121
}
121122

122123
{
123-
CassStatement* statement = cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES ('c', '3')", 0);
124+
CassStatement* statement =
125+
cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES ('c', '3')", 0);
124126
cass_batch_add_statement(batch, statement);
125127
cass_statement_free(statement);
126128
}
127129

128130
{
129-
CassStatement* statement = cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES (?, ?)", 2);
131+
CassStatement* statement =
132+
cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES (?, ?)", 2);
130133
cass_statement_bind_string(statement, 0, "d");
131134
cass_statement_bind_string(statement, 1, "4");
132135
cass_batch_add_statement(batch, statement);
@@ -147,14 +150,13 @@ CassError insert_into_batch_with_prepared(CassSession* session, const CassPrepar
147150
return rc;
148151
}
149152

150-
151153
int main(int argc, char* argv[]) {
152154
CassCluster* cluster = NULL;
153155
CassSession* session = cass_session_new();
154156
const CassPrepared* prepared = NULL;
155157
char* hosts = "127.0.0.1";
156158

157-
Pair pairs[] = { {"a", "1"}, {"b", "2"}, { NULL, NULL} };
159+
Pair pairs[] = { { "a", "1" }, { "b", "2" }, { NULL, NULL } };
158160

159161
if (argc > 1) {
160162
hosts = argv[1];
@@ -167,13 +169,10 @@ int main(int argc, char* argv[]) {
167169
return -1;
168170
}
169171

170-
execute_query(session,
171-
"CREATE KEYSPACE examples WITH replication = { \
172+
execute_query(session, "CREATE KEYSPACE examples WITH replication = { \
172173
'class': 'SimpleStrategy', 'replication_factor': '3' };");
173174

174-
175-
execute_query(session,
176-
"CREATE TABLE examples.pairs (key text, \
175+
execute_query(session, "CREATE TABLE examples.pairs (key text, \
177176
value text, \
178177
PRIMARY KEY (key));");
179178

0 commit comments

Comments
 (0)