Skip to content

[ML] Reformat native code using clang-format #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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 @@ -21,34 +21,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 @@ -76,82 +72,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 @@ -20,10 +20,8 @@
#include <string>
#include <vector>

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

//! \brief Very simple command line parser.
//!
Expand All @@ -33,34 +31,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 @@ -23,8 +23,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 @@ -46,23 +46,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 @@ -77,20 +75,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 @@ -102,20 +95,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 @@ -134,8 +123,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