Skip to content

Commit 9e76327

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 2dcbe5b commit 9e76327

File tree

1,210 files changed

+105677
-154533
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,210 files changed

+105677
-154533
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
@@ -21,33 +21,29 @@
2121

2222
#include <iostream>
2323

24-
namespace ml
25-
{
26-
namespace autoconfig
27-
{
24+
namespace ml {
25+
namespace autoconfig {
2826

29-
const std::string CCmdLineParser::DESCRIPTION =
30-
"Usage: autoconfig [options]\n"
31-
"Options";
27+
const std::string CCmdLineParser::DESCRIPTION = "Usage: autoconfig [options]\n"
28+
"Options";
3229

3330
bool CCmdLineParser::parse(int argc,
34-
const char * const *argv,
35-
std::string &logProperties,
36-
std::string &logPipe,
37-
char &delimiter,
38-
bool &lengthEncodedInput,
39-
std::string &timeField,
40-
std::string &timeFormat,
41-
std::string &configFile,
42-
std::string &inputFileName,
43-
bool &isInputFileNamedPipe,
44-
std::string &outputFileName,
45-
bool &isOutputFileNamedPipe,
46-
bool &verbose,
47-
bool &writeDetectorConfigs)
48-
{
49-
try
50-
{
31+
const char* const* argv,
32+
std::string& logProperties,
33+
std::string& logPipe,
34+
char& delimiter,
35+
bool& lengthEncodedInput,
36+
std::string& timeField,
37+
std::string& timeFormat,
38+
std::string& configFile,
39+
std::string& inputFileName,
40+
bool& isInputFileNamedPipe,
41+
std::string& outputFileName,
42+
bool& isOutputFileNamedPipe,
43+
bool& verbose,
44+
bool& writeDetectorConfigs) {
45+
try {
46+
// clang-format off
5147
boost::program_options::options_description desc(DESCRIPTION);
5248
desc.add_options()
5349
("help", "Display this information and exit")
@@ -76,82 +72,65 @@ bool CCmdLineParser::parse(int argc,
7672
("writeDetectorConfigs",
7773
"Output the detector configurations in JSON format")
7874
;
75+
// clang-format on
7976

8077
boost::program_options::variables_map vm;
8178
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
8279
boost::program_options::notify(vm);
8380

84-
if (vm.count("help") > 0)
85-
{
81+
if (vm.count("help") > 0) {
8682
std::cerr << desc << std::endl;
8783
return false;
8884
}
89-
if (vm.count("version") > 0)
90-
{
85+
if (vm.count("version") > 0) {
9186
std::cerr << ver::CBuildInfo::fullInfo() << std::endl;
9287
return false;
9388
}
94-
if (vm.count("logProperties") > 0)
95-
{
89+
if (vm.count("logProperties") > 0) {
9690
logProperties = vm["logProperties"].as<std::string>();
9791
}
98-
if (vm.count("logPipe") > 0)
99-
{
92+
if (vm.count("logPipe") > 0) {
10093
logPipe = vm["logPipe"].as<std::string>();
10194
}
102-
if (vm.count("delimiter") > 0)
103-
{
95+
if (vm.count("delimiter") > 0) {
10496
delimiter = vm["delimiter"].as<char>();
10597
}
106-
if (vm.count("lengthEncodedInput") > 0)
107-
{
98+
if (vm.count("lengthEncodedInput") > 0) {
10899
lengthEncodedInput = true;
109100
}
110-
if (vm.count("timefield") > 0)
111-
{
101+
if (vm.count("timefield") > 0) {
112102
timeField = vm["timefield"].as<std::string>();
113103
}
114-
if (vm.count("timeformat") > 0)
115-
{
104+
if (vm.count("timeformat") > 0) {
116105
timeFormat = vm["timeformat"].as<std::string>();
117106
}
118-
if (vm.count("config") > 0)
119-
{
107+
if (vm.count("config") > 0) {
120108
configFile = vm["config"].as<std::string>();
121109
}
122-
if (vm.count("input") > 0)
123-
{
110+
if (vm.count("input") > 0) {
124111
inputFileName = vm["input"].as<std::string>();
125112
}
126-
if (vm.count("inputIsPipe") > 0)
127-
{
113+
if (vm.count("inputIsPipe") > 0) {
128114
isInputFileNamedPipe = true;
129115
}
130-
if (vm.count("output") > 0)
131-
{
116+
if (vm.count("output") > 0) {
132117
outputFileName = vm["output"].as<std::string>();
133118
}
134-
if (vm.count("outputIsPipe") > 0)
135-
{
119+
if (vm.count("outputIsPipe") > 0) {
136120
isOutputFileNamedPipe = true;
137121
}
138-
if (vm.count("verbose") > 0)
139-
{
122+
if (vm.count("verbose") > 0) {
140123
verbose = true;
141124
}
142-
if (vm.count("writeDetectorConfigs") > 0)
143-
{
125+
if (vm.count("writeDetectorConfigs") > 0) {
144126
writeDetectorConfigs = true;
145127
}
146-
}
147-
catch (std::exception &e)
148-
{
128+
} catch (std::exception& e) {
149129
std::cerr << "Error processing command line: " << e.what() << std::endl;
150130
return false;
151131
}
152132

153133
return true;
154134
}
155-
156135
}
157136
}

bin/autoconfig/CCmdLineParser.h

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
#include <string>
2121
#include <vector>
2222

23-
namespace ml
24-
{
25-
namespace autoconfig
26-
{
23+
namespace ml {
24+
namespace autoconfig {
2725

2826
//! \brief Very simple command line parser.
2927
//!
@@ -33,34 +31,31 @@ namespace autoconfig
3331
//! IMPLEMENTATION DECISIONS:\n
3432
//! Put in a class rather than main to allow testing.
3533
//!
36-
class CCmdLineParser
37-
{
38-
public:
39-
using TStrVec = std::vector<std::string>;
40-
41-
public:
42-
//! Parse the arguments and return options if appropriate.
43-
static bool parse(int argc,
44-
const char * const *argv,
45-
std::string &logProperties,
46-
std::string &logPipe,
47-
char &delimiter,
48-
bool &lengthEncodedInput,
49-
std::string &timeField,
50-
std::string &timeFormat,
51-
std::string &configFile,
52-
std::string &inputFileName,
53-
bool &isInputFileNamedPipe,
54-
std::string &outputFileName,
55-
bool &isOutputFileNamedPipe,
56-
bool &verbose,
57-
bool &writeDetectorConfigs);
58-
59-
private:
60-
static const std::string DESCRIPTION;
34+
class CCmdLineParser {
35+
public:
36+
using TStrVec = std::vector<std::string>;
37+
38+
public:
39+
//! Parse the arguments and return options if appropriate.
40+
static bool parse(int argc,
41+
const char* const* argv,
42+
std::string& logProperties,
43+
std::string& logPipe,
44+
char& delimiter,
45+
bool& lengthEncodedInput,
46+
std::string& timeField,
47+
std::string& timeFormat,
48+
std::string& configFile,
49+
std::string& inputFileName,
50+
bool& isInputFileNamedPipe,
51+
std::string& outputFileName,
52+
bool& isOutputFileNamedPipe,
53+
bool& verbose,
54+
bool& writeDetectorConfigs);
55+
56+
private:
57+
static const std::string DESCRIPTION;
6158
};
62-
63-
6459
}
6560
}
6661

bin/autoconfig/Main.cc

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
//! Standalone program.
2424
//!
2525
#include <core/CLogger.h>
26-
#include <core/CoreTypes.h>
2726
#include <core/CProcessPriority.h>
27+
#include <core/CoreTypes.h>
2828

2929
#include <ver/CBuildInfo.h>
3030

@@ -46,23 +46,21 @@
4646

4747
#include <stdlib.h>
4848

49-
50-
int main(int argc, char **argv)
51-
{
49+
int main(int argc, char** argv) {
5250
// Read command line options
5351
std::string logProperties;
5452
std::string logPipe;
55-
char delimiter(',');
56-
bool lengthEncodedInput(false);
53+
char delimiter(',');
54+
bool lengthEncodedInput(false);
5755
std::string timeField("time");
5856
std::string timeFormat;
5957
std::string configFile;
6058
std::string inputFileName;
61-
bool isInputFileNamedPipe(false);
59+
bool isInputFileNamedPipe(false);
6260
std::string outputFileName;
63-
bool isOutputFileNamedPipe(false);
64-
bool verbose(false);
65-
bool writeDetectorConfigs(false);
61+
bool isOutputFileNamedPipe(false);
62+
bool verbose(false);
63+
bool writeDetectorConfigs(false);
6664
if (ml::autoconfig::CCmdLineParser::parse(argc,
6765
argv,
6866
logProperties,
@@ -77,20 +75,15 @@ int main(int argc, char **argv)
7775
outputFileName,
7876
isOutputFileNamedPipe,
7977
verbose,
80-
writeDetectorConfigs) == false)
81-
{
78+
writeDetectorConfigs) == false) {
8279
return EXIT_FAILURE;
8380
}
8481

8582
// Construct the IO manager before reconfiguring the logger, as it performs
8683
// std::ios actions that only work before first use
87-
ml::api::CIoManager ioMgr(inputFileName,
88-
isInputFileNamedPipe,
89-
outputFileName,
90-
isOutputFileNamedPipe);
84+
ml::api::CIoManager ioMgr(inputFileName, isInputFileNamedPipe, outputFileName, isOutputFileNamedPipe);
9185

92-
if (ml::core::CLogger::instance().reconfigure(logPipe, logProperties) == false)
93-
{
86+
if (ml::core::CLogger::instance().reconfigure(logPipe, logProperties) == false) {
9487
LOG_FATAL("Could not reconfigure logging");
9588
return EXIT_FAILURE;
9689
}
@@ -102,20 +95,16 @@ int main(int argc, char **argv)
10295

10396
ml::core::CProcessPriority::reducePriority();
10497

105-
if (ioMgr.initIo() == false)
106-
{
98+
if (ioMgr.initIo() == false) {
10799
LOG_FATAL("Failed to initialise IO");
108100
return EXIT_FAILURE;
109101
}
110102

111103
typedef boost::scoped_ptr<ml::api::CInputParser> TScopedInputParserP;
112104
TScopedInputParserP inputParser;
113-
if (lengthEncodedInput)
114-
{
105+
if (lengthEncodedInput) {
115106
inputParser.reset(new ml::api::CLengthEncodedInputParser(ioMgr.inputStream()));
116-
}
117-
else
118-
{
107+
} else {
119108
inputParser.reset(new ml::api::CCsvInputParser(ioMgr.inputStream(), delimiter));
120109
}
121110

@@ -134,8 +123,7 @@ int main(int argc, char **argv)
134123
0, // no persistence at present
135124
*inputParser,
136125
configurer);
137-
if (skeleton.ioLoop() == false)
138-
{
126+
if (skeleton.ioLoop() == false) {
139127
LOG_FATAL("Ml autoconfig failed");
140128
return EXIT_FAILURE;
141129
}

0 commit comments

Comments
 (0)