Skip to content

Commit 466150f

Browse files
committed
[ML] Reformat native code using clang-format (#15)
Provided a script - dev-tools/clang-format.sh to reformat source code according to the agreed configuration in $CPP_SRC_HOME/.clang-format Key points to note: Java style braces Setting the maximum line length to be 140 characters in order to be in agreement with the elasticsearch Java development style guide.
1 parent 7ff132d commit 466150f

File tree

1,192 files changed

+105236
-153819
lines changed

Some content is hidden

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

1,192 files changed

+105236
-153819
lines changed

.clang-format

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
BasedOnStyle: LLVM
2+
AccessModifierOffset: -4
3+
AllowAllParametersOfDeclarationOnNextLine: false
4+
AllowShortBlocksOnASingleLine: true
5+
AllowShortFunctionsOnASingleLine: InlineOnly
6+
AlwaysBreakTemplateDeclarations: true
7+
BinPackArguments: false
8+
BinPackParameters: false
9+
ColumnLimit: 140
10+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
11+
FixNamespaceComments: false
12+
IndentCaseLabels: false
13+
IndentWidth: 4
14+
PenaltyBreakAssignment: 2
15+
PenaltyBreakBeforeFirstCallParameter: 4
16+
PenaltyBreakComment: 300
17+
PenaltyBreakFirstLessLess: 2
18+
PenaltyBreakString: 1000000
19+
PenaltyExcessCharacter: 1000000
20+
PenaltyReturnTypeOnItsOwnLine: 60
21+
PointerAlignment: Left
22+
TabWidth: 4
23+
SpaceAfterTemplateKeyword: false
24+
ReflowComments: false

bin/autoconfig/CCmdLineParser.cc

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,29 @@
1212

1313
#include <iostream>
1414

15-
namespace ml
16-
{
17-
namespace autoconfig
18-
{
15+
namespace ml {
16+
namespace autoconfig {
1917

20-
const std::string CCmdLineParser::DESCRIPTION =
21-
"Usage: autoconfig [options]\n"
22-
"Options";
18+
const std::string CCmdLineParser::DESCRIPTION = "Usage: autoconfig [options]\n"
19+
"Options";
2320

2421
bool CCmdLineParser::parse(int argc,
25-
const char * const *argv,
26-
std::string &logProperties,
27-
std::string &logPipe,
28-
char &delimiter,
29-
bool &lengthEncodedInput,
30-
std::string &timeField,
31-
std::string &timeFormat,
32-
std::string &configFile,
33-
std::string &inputFileName,
34-
bool &isInputFileNamedPipe,
35-
std::string &outputFileName,
36-
bool &isOutputFileNamedPipe,
37-
bool &verbose,
38-
bool &writeDetectorConfigs)
39-
{
40-
try
41-
{
22+
const char* const* argv,
23+
std::string& logProperties,
24+
std::string& logPipe,
25+
char& delimiter,
26+
bool& lengthEncodedInput,
27+
std::string& timeField,
28+
std::string& timeFormat,
29+
std::string& configFile,
30+
std::string& inputFileName,
31+
bool& isInputFileNamedPipe,
32+
std::string& outputFileName,
33+
bool& isOutputFileNamedPipe,
34+
bool& verbose,
35+
bool& writeDetectorConfigs) {
36+
try {
37+
// clang-format off
4238
boost::program_options::options_description desc(DESCRIPTION);
4339
desc.add_options()
4440
("help", "Display this information and exit")
@@ -67,82 +63,65 @@ bool CCmdLineParser::parse(int argc,
6763
("writeDetectorConfigs",
6864
"Output the detector configurations in JSON format")
6965
;
66+
// clang-format on
7067

7168
boost::program_options::variables_map vm;
7269
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
7370
boost::program_options::notify(vm);
7471

75-
if (vm.count("help") > 0)
76-
{
72+
if (vm.count("help") > 0) {
7773
std::cerr << desc << std::endl;
7874
return false;
7975
}
80-
if (vm.count("version") > 0)
81-
{
76+
if (vm.count("version") > 0) {
8277
std::cerr << ver::CBuildInfo::fullInfo() << std::endl;
8378
return false;
8479
}
85-
if (vm.count("logProperties") > 0)
86-
{
80+
if (vm.count("logProperties") > 0) {
8781
logProperties = vm["logProperties"].as<std::string>();
8882
}
89-
if (vm.count("logPipe") > 0)
90-
{
83+
if (vm.count("logPipe") > 0) {
9184
logPipe = vm["logPipe"].as<std::string>();
9285
}
93-
if (vm.count("delimiter") > 0)
94-
{
86+
if (vm.count("delimiter") > 0) {
9587
delimiter = vm["delimiter"].as<char>();
9688
}
97-
if (vm.count("lengthEncodedInput") > 0)
98-
{
89+
if (vm.count("lengthEncodedInput") > 0) {
9990
lengthEncodedInput = true;
10091
}
101-
if (vm.count("timefield") > 0)
102-
{
92+
if (vm.count("timefield") > 0) {
10393
timeField = vm["timefield"].as<std::string>();
10494
}
105-
if (vm.count("timeformat") > 0)
106-
{
95+
if (vm.count("timeformat") > 0) {
10796
timeFormat = vm["timeformat"].as<std::string>();
10897
}
109-
if (vm.count("config") > 0)
110-
{
98+
if (vm.count("config") > 0) {
11199
configFile = vm["config"].as<std::string>();
112100
}
113-
if (vm.count("input") > 0)
114-
{
101+
if (vm.count("input") > 0) {
115102
inputFileName = vm["input"].as<std::string>();
116103
}
117-
if (vm.count("inputIsPipe") > 0)
118-
{
104+
if (vm.count("inputIsPipe") > 0) {
119105
isInputFileNamedPipe = true;
120106
}
121-
if (vm.count("output") > 0)
122-
{
107+
if (vm.count("output") > 0) {
123108
outputFileName = vm["output"].as<std::string>();
124109
}
125-
if (vm.count("outputIsPipe") > 0)
126-
{
110+
if (vm.count("outputIsPipe") > 0) {
127111
isOutputFileNamedPipe = true;
128112
}
129-
if (vm.count("verbose") > 0)
130-
{
113+
if (vm.count("verbose") > 0) {
131114
verbose = true;
132115
}
133-
if (vm.count("writeDetectorConfigs") > 0)
134-
{
116+
if (vm.count("writeDetectorConfigs") > 0) {
135117
writeDetectorConfigs = true;
136118
}
137-
}
138-
catch (std::exception &e)
139-
{
119+
} catch (std::exception& e) {
140120
std::cerr << "Error processing command line: " << e.what() << std::endl;
141121
return false;
142122
}
143123

144124
return true;
145125
}
146-
147126
}
148127
}

bin/autoconfig/CCmdLineParser.h

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
#include <string>
1212
#include <vector>
1313

14-
namespace ml
15-
{
16-
namespace autoconfig
17-
{
14+
namespace ml {
15+
namespace autoconfig {
1816

1917
//! \brief Very simple command line parser.
2018
//!
@@ -24,34 +22,31 @@ namespace autoconfig
2422
//! IMPLEMENTATION DECISIONS:\n
2523
//! Put in a class rather than main to allow testing.
2624
//!
27-
class CCmdLineParser
28-
{
29-
public:
30-
using TStrVec = std::vector<std::string>;
31-
32-
public:
33-
//! Parse the arguments and return options if appropriate.
34-
static bool parse(int argc,
35-
const char * const *argv,
36-
std::string &logProperties,
37-
std::string &logPipe,
38-
char &delimiter,
39-
bool &lengthEncodedInput,
40-
std::string &timeField,
41-
std::string &timeFormat,
42-
std::string &configFile,
43-
std::string &inputFileName,
44-
bool &isInputFileNamedPipe,
45-
std::string &outputFileName,
46-
bool &isOutputFileNamedPipe,
47-
bool &verbose,
48-
bool &writeDetectorConfigs);
49-
50-
private:
51-
static const std::string DESCRIPTION;
25+
class CCmdLineParser {
26+
public:
27+
using TStrVec = std::vector<std::string>;
28+
29+
public:
30+
//! Parse the arguments and return options if appropriate.
31+
static bool parse(int argc,
32+
const char* const* argv,
33+
std::string& logProperties,
34+
std::string& logPipe,
35+
char& delimiter,
36+
bool& lengthEncodedInput,
37+
std::string& timeField,
38+
std::string& timeFormat,
39+
std::string& configFile,
40+
std::string& inputFileName,
41+
bool& isInputFileNamedPipe,
42+
std::string& outputFileName,
43+
bool& isOutputFileNamedPipe,
44+
bool& verbose,
45+
bool& writeDetectorConfigs);
46+
47+
private:
48+
static const std::string DESCRIPTION;
5249
};
53-
54-
5550
}
5651
}
5752

bin/autoconfig/Main.cc

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
//! Standalone program.
1515
//!
1616
#include <core/CLogger.h>
17-
#include <core/CoreTypes.h>
1817
#include <core/CProcessPriority.h>
18+
#include <core/CoreTypes.h>
1919

2020
#include <ver/CBuildInfo.h>
2121

@@ -37,23 +37,21 @@
3737

3838
#include <stdlib.h>
3939

40-
41-
int main(int argc, char **argv)
42-
{
40+
int main(int argc, char** argv) {
4341
// Read command line options
4442
std::string logProperties;
4543
std::string logPipe;
46-
char delimiter(',');
47-
bool lengthEncodedInput(false);
44+
char delimiter(',');
45+
bool lengthEncodedInput(false);
4846
std::string timeField("time");
4947
std::string timeFormat;
5048
std::string configFile;
5149
std::string inputFileName;
52-
bool isInputFileNamedPipe(false);
50+
bool isInputFileNamedPipe(false);
5351
std::string outputFileName;
54-
bool isOutputFileNamedPipe(false);
55-
bool verbose(false);
56-
bool writeDetectorConfigs(false);
52+
bool isOutputFileNamedPipe(false);
53+
bool verbose(false);
54+
bool writeDetectorConfigs(false);
5755
if (ml::autoconfig::CCmdLineParser::parse(argc,
5856
argv,
5957
logProperties,
@@ -68,20 +66,15 @@ int main(int argc, char **argv)
6866
outputFileName,
6967
isOutputFileNamedPipe,
7068
verbose,
71-
writeDetectorConfigs) == false)
72-
{
69+
writeDetectorConfigs) == false) {
7370
return EXIT_FAILURE;
7471
}
7572

7673
// Construct the IO manager before reconfiguring the logger, as it performs
7774
// std::ios actions that only work before first use
78-
ml::api::CIoManager ioMgr(inputFileName,
79-
isInputFileNamedPipe,
80-
outputFileName,
81-
isOutputFileNamedPipe);
75+
ml::api::CIoManager ioMgr(inputFileName, isInputFileNamedPipe, outputFileName, isOutputFileNamedPipe);
8276

83-
if (ml::core::CLogger::instance().reconfigure(logPipe, logProperties) == false)
84-
{
77+
if (ml::core::CLogger::instance().reconfigure(logPipe, logProperties) == false) {
8578
LOG_FATAL("Could not reconfigure logging");
8679
return EXIT_FAILURE;
8780
}
@@ -93,20 +86,16 @@ int main(int argc, char **argv)
9386

9487
ml::core::CProcessPriority::reducePriority();
9588

96-
if (ioMgr.initIo() == false)
97-
{
89+
if (ioMgr.initIo() == false) {
9890
LOG_FATAL("Failed to initialise IO");
9991
return EXIT_FAILURE;
10092
}
10193

10294
typedef boost::scoped_ptr<ml::api::CInputParser> TScopedInputParserP;
10395
TScopedInputParserP inputParser;
104-
if (lengthEncodedInput)
105-
{
96+
if (lengthEncodedInput) {
10697
inputParser.reset(new ml::api::CLengthEncodedInputParser(ioMgr.inputStream()));
107-
}
108-
else
109-
{
98+
} else {
11099
inputParser.reset(new ml::api::CCsvInputParser(ioMgr.inputStream(), delimiter));
111100
}
112101

@@ -125,8 +114,7 @@ int main(int argc, char **argv)
125114
0, // no persistence at present
126115
*inputParser,
127116
configurer);
128-
if (skeleton.ioLoop() == false)
129-
{
117+
if (skeleton.ioLoop() == false) {
130118
LOG_FATAL("Ml autoconfig failed");
131119
return EXIT_FAILURE;
132120
}

0 commit comments

Comments
 (0)