Skip to content

Commit

Permalink
[ML] Reformat native code using clang-format (#15)
Browse files Browse the repository at this point in the history
[ML] Reformat native code using clang-format

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.
  • Loading branch information
edsavage authored Apr 4, 2018
1 parent 36fd5a1 commit 2945e2b
Show file tree
Hide file tree
Showing 1,195 changed files with 105,256 additions and 153,775 deletions.
24 changes: 24 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BasedOnStyle: LLVM
AccessModifierOffset: -4
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: InlineOnly
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 140
ConstructorInitializerAllOnOneLineOrOnePerLine: true
FixNamespaceComments: false
IndentCaseLabels: false
IndentWidth: 4
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 4
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 2
PenaltyBreakString: 1000000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
TabWidth: 4
SpaceAfterTemplateKeyword: false
ReflowComments: false
95 changes: 37 additions & 58 deletions bin/autoconfig/CCmdLineParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,30 @@

#include <iostream>

namespace ml
{
namespace autoconfig
{
namespace ml {
namespace autoconfig {

const std::string CCmdLineParser::DESCRIPTION =
"Usage: autoconfig [options]\n"
"Options";
const std::string CCmdLineParser::DESCRIPTION = "Usage: autoconfig [options]\n"
"Options";

bool CCmdLineParser::parse(int argc,
const char * const *argv,
std::string &logProperties,
std::string &logPipe,
char &delimiter,
bool &lengthEncodedInput,
std::string &timeField,
std::string &timeFormat,
std::string &configFile,
std::string &inputFileName,
bool &isInputFileNamedPipe,
std::string &outputFileName,
bool &isOutputFileNamedPipe,
bool &verbose,
bool &writeDetectorConfigs)
{
try
{
const char* const* argv,
std::string& logProperties,
std::string& logPipe,
char& delimiter,
bool& lengthEncodedInput,
std::string& timeField,
std::string& timeFormat,
std::string& configFile,
std::string& inputFileName,
bool& isInputFileNamedPipe,
std::string& outputFileName,
bool& isOutputFileNamedPipe,
bool& verbose,
bool& writeDetectorConfigs) {
try {
boost::program_options::options_description desc(DESCRIPTION);
// clang-format off
desc.add_options()
("help", "Display this information and exit")
("version", "Display version information and exit")
Expand Down Expand Up @@ -67,82 +63,65 @@ bool CCmdLineParser::parse(int argc,
("writeDetectorConfigs",
"Output the detector configurations in JSON format")
;
// clang-format on

boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);

if (vm.count("help") > 0)
{
if (vm.count("help") > 0) {
std::cerr << desc << std::endl;
return false;
}
if (vm.count("version") > 0)
{
if (vm.count("version") > 0) {
std::cerr << ver::CBuildInfo::fullInfo() << std::endl;
return false;
}
if (vm.count("logProperties") > 0)
{
if (vm.count("logProperties") > 0) {
logProperties = vm["logProperties"].as<std::string>();
}
if (vm.count("logPipe") > 0)
{
if (vm.count("logPipe") > 0) {
logPipe = vm["logPipe"].as<std::string>();
}
if (vm.count("delimiter") > 0)
{
if (vm.count("delimiter") > 0) {
delimiter = vm["delimiter"].as<char>();
}
if (vm.count("lengthEncodedInput") > 0)
{
if (vm.count("lengthEncodedInput") > 0) {
lengthEncodedInput = true;
}
if (vm.count("timefield") > 0)
{
if (vm.count("timefield") > 0) {
timeField = vm["timefield"].as<std::string>();
}
if (vm.count("timeformat") > 0)
{
if (vm.count("timeformat") > 0) {
timeFormat = vm["timeformat"].as<std::string>();
}
if (vm.count("config") > 0)
{
if (vm.count("config") > 0) {
configFile = vm["config"].as<std::string>();
}
if (vm.count("input") > 0)
{
if (vm.count("input") > 0) {
inputFileName = vm["input"].as<std::string>();
}
if (vm.count("inputIsPipe") > 0)
{
if (vm.count("inputIsPipe") > 0) {
isInputFileNamedPipe = true;
}
if (vm.count("output") > 0)
{
if (vm.count("output") > 0) {
outputFileName = vm["output"].as<std::string>();
}
if (vm.count("outputIsPipe") > 0)
{
if (vm.count("outputIsPipe") > 0) {
isOutputFileNamedPipe = true;
}
if (vm.count("verbose") > 0)
{
if (vm.count("verbose") > 0) {
verbose = true;
}
if (vm.count("writeDetectorConfigs") > 0)
{
if (vm.count("writeDetectorConfigs") > 0) {
writeDetectorConfigs = true;
}
}
catch (std::exception &e)
{
} catch (std::exception& e) {
std::cerr << "Error processing command line: " << e.what() << std::endl;
return false;
}

return true;
}

}
}
57 changes: 26 additions & 31 deletions bin/autoconfig/CCmdLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
#include <string>
#include <vector>

namespace ml
{
namespace autoconfig
{
namespace ml {
namespace autoconfig {

//! \brief Very simple command line parser.
//!
Expand All @@ -24,34 +22,31 @@ namespace autoconfig
//! IMPLEMENTATION DECISIONS:\n
//! Put in a class rather than main to allow testing.
//!
class CCmdLineParser
{
public:
using TStrVec = std::vector<std::string>;

public:
//! Parse the arguments and return options if appropriate.
static bool parse(int argc,
const char * const *argv,
std::string &logProperties,
std::string &logPipe,
char &delimiter,
bool &lengthEncodedInput,
std::string &timeField,
std::string &timeFormat,
std::string &configFile,
std::string &inputFileName,
bool &isInputFileNamedPipe,
std::string &outputFileName,
bool &isOutputFileNamedPipe,
bool &verbose,
bool &writeDetectorConfigs);

private:
static const std::string DESCRIPTION;
class CCmdLineParser {
public:
using TStrVec = std::vector<std::string>;

public:
//! Parse the arguments and return options if appropriate.
static bool parse(int argc,
const char* const* argv,
std::string& logProperties,
std::string& logPipe,
char& delimiter,
bool& lengthEncodedInput,
std::string& timeField,
std::string& timeFormat,
std::string& configFile,
std::string& inputFileName,
bool& isInputFileNamedPipe,
std::string& outputFileName,
bool& isOutputFileNamedPipe,
bool& verbose,
bool& writeDetectorConfigs);

private:
static const std::string DESCRIPTION;
};


}
}

Expand Down
42 changes: 15 additions & 27 deletions bin/autoconfig/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//! Standalone program.
//!
#include <core/CLogger.h>
#include <core/CoreTypes.h>
#include <core/CProcessPriority.h>
#include <core/CoreTypes.h>

#include <ver/CBuildInfo.h>

Expand All @@ -37,23 +37,21 @@

#include <stdlib.h>


int main(int argc, char **argv)
{
int main(int argc, char** argv) {
// Read command line options
std::string logProperties;
std::string logPipe;
char delimiter(',');
bool lengthEncodedInput(false);
char delimiter(',');
bool lengthEncodedInput(false);
std::string timeField("time");
std::string timeFormat;
std::string configFile;
std::string inputFileName;
bool isInputFileNamedPipe(false);
bool isInputFileNamedPipe(false);
std::string outputFileName;
bool isOutputFileNamedPipe(false);
bool verbose(false);
bool writeDetectorConfigs(false);
bool isOutputFileNamedPipe(false);
bool verbose(false);
bool writeDetectorConfigs(false);
if (ml::autoconfig::CCmdLineParser::parse(argc,
argv,
logProperties,
Expand All @@ -68,20 +66,15 @@ int main(int argc, char **argv)
outputFileName,
isOutputFileNamedPipe,
verbose,
writeDetectorConfigs) == false)
{
writeDetectorConfigs) == false) {
return EXIT_FAILURE;
}

// Construct the IO manager before reconfiguring the logger, as it performs
// std::ios actions that only work before first use
ml::api::CIoManager ioMgr(inputFileName,
isInputFileNamedPipe,
outputFileName,
isOutputFileNamedPipe);
ml::api::CIoManager ioMgr(inputFileName, isInputFileNamedPipe, outputFileName, isOutputFileNamedPipe);

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

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

if (ioMgr.initIo() == false)
{
if (ioMgr.initIo() == false) {
LOG_FATAL("Failed to initialise IO");
return EXIT_FAILURE;
}

typedef boost::scoped_ptr<ml::api::CInputParser> TScopedInputParserP;
TScopedInputParserP inputParser;
if (lengthEncodedInput)
{
if (lengthEncodedInput) {
inputParser.reset(new ml::api::CLengthEncodedInputParser(ioMgr.inputStream()));
}
else
{
} else {
inputParser.reset(new ml::api::CCsvInputParser(ioMgr.inputStream(), delimiter));
}

Expand All @@ -125,8 +114,7 @@ int main(int argc, char **argv)
0, // no persistence at present
*inputParser,
configurer);
if (skeleton.ioLoop() == false)
{
if (skeleton.ioLoop() == false) {
LOG_FATAL("Ml autoconfig failed");
return EXIT_FAILURE;
}
Expand Down
Loading

0 comments on commit 2945e2b

Please sign in to comment.