Skip to content

Commit e9487f7

Browse files
committed
.clang-format; format all codes
1 parent 7d7e7a3 commit e9487f7

15 files changed

Lines changed: 487 additions & 336 deletions

.clang-format

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Language: Cpp
2+
AccessModifierOffset: -4
3+
AlignEscapedNewlinesLeft: true
4+
AlignTrailingComments: true
5+
AllowAllParametersOfDeclarationOnNextLine: true
6+
AllowShortBlocksOnASingleLine: false
7+
AllowShortFunctionsOnASingleLine: Inline
8+
AllowShortIfStatementsOnASingleLine: false
9+
AllowShortLoopsOnASingleLine: false
10+
AlwaysBreakBeforeMultilineStrings: true
11+
AlwaysBreakTemplateDeclarations: true
12+
BinPackParameters: true
13+
BreakBeforeBinaryOperators: false
14+
BreakBeforeBraces: Linux
15+
BreakBeforeTernaryOperators: true
16+
BreakConstructorInitializersBeforeComma: false
17+
ColumnLimit: 0
18+
CommentPragmas: ''
19+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
20+
ConstructorInitializerIndentWidth: 4
21+
ContinuationIndentWidth: 4
22+
DerivePointerAlignment: false
23+
DisableFormat: false
24+
ExperimentalAutoDetectBinPacking: false
25+
IndentCaseLabels: true
26+
IndentWidth: 4
27+
IndentWrappedFunctionNames: false
28+
IndentFunctionDeclarationAfterType: false
29+
MaxEmptyLinesToKeep: 1
30+
KeepEmptyLinesAtTheStartOfBlocks: false
31+
NamespaceIndentation: None
32+
PenaltyBreakBeforeFirstCallParameter: 1
33+
PenaltyBreakComment: 300
34+
PenaltyBreakString: 1000
35+
PenaltyBreakFirstLessLess: 120
36+
PenaltyExcessCharacter: 1
37+
PenaltyReturnTypeOnItsOwnLine: 1000
38+
PointerAlignment: Right
39+
SpaceBeforeAssignmentOperators: true
40+
SpaceBeforeParens: ControlStatements
41+
SpaceInEmptyParentheses: false
42+
SpacesBeforeTrailingComments: 1
43+
SpacesInAngles: false
44+
SpacesInCStyleCastParentheses: false
45+
SpacesInContainerLiterals: true
46+
SpacesInParentheses: false
47+
Cpp11BracedListStyle: true
48+
Standard: Cpp11
49+
TabWidth: 4
50+
UseTab: Never

bdict.cc

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
#include <string>
2-
#include "bitem.h"
31
#include "bdict.h"
2+
#include "bint.h"
3+
#include "bitem.h"
44
#include "blist.h"
55
#include "bstr.h"
6-
#include "bint.h"
76
#include "zend_container.h"
7+
#include <string>
88

9-
bdict::bdict() : bitem() {
9+
bdict::bdict()
10+
: bitem()
11+
{
1012
ALLOC_HASHTABLE(_data);
1113
zend_hash_init(_data, 0, NULL, ZVAL_PTR_DTOR, 0);
1214
}
1315

14-
bdict::bdict(const bdict *that) : bitem() {
16+
bdict::bdict(const bdict *that)
17+
: bitem()
18+
{
1519
ALLOC_HASHTABLE(_data);
1620
zend_hash_init(_data, 0, NULL, ZVAL_PTR_DTOR, 0);
1721
//zend_hash_copy(_data, that->_data, (copy_ctor_func_t) ZVAL_COPY_CTOR);
18-
for(zend_hash_internal_pointer_reset(that->_data);
19-
zend_hash_has_more_elements(that->_data) == SUCCESS;
20-
zend_hash_move_forward(that->_data)) {
22+
for (zend_hash_internal_pointer_reset(that->_data);
23+
zend_hash_has_more_elements(that->_data) == SUCCESS;
24+
zend_hash_move_forward(that->_data)) {
2125
zval *tmp = new zval();
2226
ZVAL_OBJ(tmp, zend_container::bnode_object_clone(zend_hash_get_current_data(that->_data)));
2327
zend_string *_str_index;
@@ -27,35 +31,40 @@ bdict::bdict(const bdict *that) : bitem() {
2731
}
2832
}
2933

30-
bdict::~bdict() {
34+
bdict::~bdict()
35+
{
3136
zend_hash_destroy(_data);
3237
FREE_HASHTABLE(_data);
3338
}
3439

35-
std::string bdict::get_type() const {
40+
std::string bdict::get_type() const
41+
{
3642
return "bdict";
3743
}
3844

39-
zval * bdict::get(const std::string &key) const {
45+
zval *bdict::get(const std::string &key) const
46+
{
4047
if (!zend_hash_str_exists(_data, key.c_str(), key.length())) {
4148
return bitem::get_zval_bool(false);
4249
}
4350
return zend_hash_str_find(_data, key.c_str(), key.length());
4451
}
4552

46-
bool bdict::has(const std::string &key) const {
53+
bool bdict::has(const std::string &key) const
54+
{
4755
if (zend_hash_str_exists(_data, key.c_str(), key.length())) {
4856
return true;
4957
} else {
5058
return false;
5159
}
5260
}
5361

54-
void bdict::set(const std::string &key, zval *value) {
62+
void bdict::set(const std::string &key, zval *value)
63+
{
5564
std::string class_name = zend_container::bnode_object_get_class_name(value);
5665
zend_object *clone_object = NULL;
5766
if (class_name == "bdict" || class_name == "blist" ||
58-
class_name == "bstr" || class_name == "bint") {
67+
class_name == "bstr" || class_name == "bint") {
5968
clone_object = zend_container::bnode_object_clone(value);
6069
} else {
6170
return;
@@ -69,15 +78,17 @@ void bdict::set(const std::string &key, zval *value) {
6978
}
7079
}
7180

72-
bool bdict::del(const std::string &key) {
81+
bool bdict::del(const std::string &key)
82+
{
7383
if (zend_hash_str_del(_data, key.c_str(), key.length()) == SUCCESS) {
7484
return true;
7585
} else {
7686
return false;
7787
}
7888
}
7989

80-
zval * bdict::get_path(const std::string &key, size_t &pt) const {
90+
zval *bdict::get_path(const std::string &key, size_t &pt) const
91+
{
8192
std::string current_key = bitem::get_current_key(key, pt);
8293
if (!zend_hash_str_exists(_data, current_key.c_str(), current_key.length())) {
8394
return bitem::get_zval_bool(false);
@@ -97,10 +108,11 @@ zval * bdict::get_path(const std::string &key, size_t &pt) const {
97108
}
98109
}
99110

100-
void bdict::set_path(const std::string &key, size_t &pt, zval *value) {
111+
void bdict::set_path(const std::string &key, size_t &pt, zval *value)
112+
{
101113
std::string class_name = zend_container::bnode_object_get_class_name(value);
102114
if (!(class_name == "bdict" || class_name == "blist" ||
103-
class_name == "bstr" || class_name == "bint")) {
115+
class_name == "bstr" || class_name == "bint")) {
104116
bitem::throw_general_exception("Unsupported node given");
105117
return;
106118
}
@@ -152,7 +164,8 @@ void bdict::set_path(const std::string &key, size_t &pt, zval *value) {
152164
}
153165
}
154166

155-
bool bdict::del_path(const std::string &key, size_t &pt) {
167+
bool bdict::del_path(const std::string &key, size_t &pt)
168+
{
156169
std::string current_key = bitem::get_current_key(key, pt);
157170
if (!zend_hash_str_exists(_data, current_key.c_str(), current_key.length())) {
158171
return false;
@@ -172,15 +185,18 @@ bool bdict::del_path(const std::string &key, size_t &pt) {
172185
}
173186
}
174187

175-
size_t bdict::length() const {
188+
size_t bdict::length() const
189+
{
176190
return (encode().length() / sizeof(char));
177191
}
178192

179-
size_t bdict::count() const {
193+
size_t bdict::count() const
194+
{
180195
return zend_array_count(_data);
181196
}
182197

183-
zval * bdict::parse(const std::string &ben, size_t &pt) {
198+
zval *bdict::parse(const std::string &ben, size_t &pt)
199+
{
184200
if (ben[pt] != 'd')
185201
return bitem::throw_general_exception("Error parsing bdict");
186202
zval *zv = new zval();
@@ -192,7 +208,8 @@ zval * bdict::parse(const std::string &ben, size_t &pt) {
192208

193209
while (ben[pt] != 'e') {
194210
size_t start = pt;
195-
while (isdigit(ben[pt])) ++pt;
211+
while (isdigit(ben[pt]))
212+
++pt;
196213
std::string key_len = ben.substr(start, pt - start);
197214
++pt;
198215
std::string key = ben.substr(pt, std::stoull(key_len));
@@ -217,30 +234,32 @@ zval * bdict::parse(const std::string &ben, size_t &pt) {
217234
return zv;
218235
}
219236

220-
std::string bdict::encode() const {
237+
std::string bdict::encode() const
238+
{
221239
std::string result = "d";
222-
for(zend_hash_internal_pointer_reset(_data);
223-
zend_hash_has_more_elements(_data) == SUCCESS;
224-
zend_hash_move_forward(_data)) {
240+
for (zend_hash_internal_pointer_reset(_data);
241+
zend_hash_has_more_elements(_data) == SUCCESS;
242+
zend_hash_move_forward(_data)) {
225243
zend_string *_str_index;
226244
zend_ulong num_index;
227245
zend_hash_get_current_key(_data, &_str_index, &num_index);
228246
zval *value = zend_hash_get_current_data(_data);
229247
std::string str_index(ZSTR_VAL(_str_index), ZSTR_LEN(_str_index));
230248

231-
result += std::to_string(str_index.length()) + ":" + str_index
232-
+ zend_container::bnode_fetch_object_data(Z_OBJ_P(value))->encode();
249+
result += std::to_string(str_index.length()) + ":" + str_index +
250+
zend_container::bnode_fetch_object_data(Z_OBJ_P(value))->encode();
233251
}
234252
return result + "e";
235253
}
236254

237-
zval * bdict::to_array(const bool include_meta) const {
255+
zval *bdict::to_array(const bool include_meta) const
256+
{
238257
zval *zv = new zval();
239258
array_init(zv);
240259

241-
for(zend_hash_internal_pointer_reset(_data);
242-
zend_hash_has_more_elements(_data) == SUCCESS;
243-
zend_hash_move_forward(_data)) {
260+
for (zend_hash_internal_pointer_reset(_data);
261+
zend_hash_has_more_elements(_data) == SUCCESS;
262+
zend_hash_move_forward(_data)) {
244263
zend_string *str_index;
245264
zend_ulong num_index;
246265
zend_hash_get_current_key(_data, &str_index, &num_index);
@@ -260,16 +279,17 @@ zval * bdict::to_array(const bool include_meta) const {
260279
return zv;
261280
}
262281

263-
zval * bdict::search(const std::string &needle, const long &mode, const std::string path) const {
282+
zval *bdict::search(const std::string &needle, const long &mode, const std::string path) const
283+
{
264284
if (mode < 0 || mode > 1)
265285
bitem::throw_general_exception("Illegal search mode");
266286

267287
zval *zv = new zval();
268288
array_init(zv);
269289

270-
for(zend_hash_internal_pointer_reset(_data);
271-
zend_hash_has_more_elements(_data) == SUCCESS;
272-
zend_hash_move_forward(_data)) {
290+
for (zend_hash_internal_pointer_reset(_data);
291+
zend_hash_has_more_elements(_data) == SUCCESS;
292+
zend_hash_move_forward(_data)) {
273293
zend_string *_str_index;
274294
zend_ulong num_index;
275295
zend_hash_get_current_key(_data, &_str_index, &num_index);

bdict.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,33 @@ extern "C" {
66
#include "zend_exceptions.h"
77
}
88

9-
#include <string>
109
#include "bitem.h"
10+
#include <string>
1111

12-
class bdict : public bitem {
13-
public:
14-
HashTable *_data;
12+
class bdict : public bitem
13+
{
14+
public:
15+
HashTable *_data;
1516

16-
bdict();
17-
bdict(const bdict *that);
18-
~bdict();
17+
bdict();
18+
bdict(const bdict *that);
19+
~bdict();
1920

20-
std::string get_type() const;
21-
zval * get(const std::string &key) const;
22-
bool has(const std::string &key) const;
23-
void set(const std::string &key, zval *value);
24-
bool del(const std::string &key);
25-
zval * get_path(const std::string &key, size_t &pt) const;
26-
void set_path(const std::string &key, size_t &pt, zval *value);
27-
bool del_path(const std::string &key, size_t &pt);
28-
size_t length() const;
29-
size_t count() const;
21+
std::string get_type() const;
22+
zval *get(const std::string &key) const;
23+
bool has(const std::string &key) const;
24+
void set(const std::string &key, zval *value);
25+
bool del(const std::string &key);
26+
zval *get_path(const std::string &key, size_t &pt) const;
27+
void set_path(const std::string &key, size_t &pt, zval *value);
28+
bool del_path(const std::string &key, size_t &pt);
29+
size_t length() const;
30+
size_t count() const;
3031

31-
static zval * parse(const std::string &ben, size_t &pt);
32-
std::string encode() const;
33-
zval * to_array(const bool include_meta) const;
34-
zval * search(const std::string &needle, const long &mode, const std::string path) const;
32+
static zval *parse(const std::string &ben, size_t &pt);
33+
std::string encode() const;
34+
zval *to_array(const bool include_meta) const;
35+
zval *search(const std::string &needle, const long &mode, const std::string path) const;
3536
};
3637

3738
#endif

0 commit comments

Comments
 (0)