Skip to content

[ML] Reformat code with Java brace style #10

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

Closed
wants to merge 6 commits into from
Closed
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
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions .astyle_options
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
indent=spaces=4 # indent using 4 spaces per indent (default)
style=java # brackets attached in all cases (Java style)
indent-classes # classes are indented
indent-switches # as are switches
keep-one-line-blocks # don't break one-line blocks
max-continuation-indent=100 # indent a max number of 100 spaces in a continuation line
min-conditional-indent=0 # no minimal indent for continuation of conditionals
suffix=none # don't keep file backups
2 changes: 2 additions & 0 deletions .astyle_project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--recursive
--exclude=3rd_party # when recursing skip the 3rd_party stuff
115 changes: 47 additions & 68 deletions bin/autoconfig/CCmdLineParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@

#include <iostream>

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

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

bool CCmdLineParser::parse(int argc,
const char * const *argv,
Expand All @@ -44,108 +42,89 @@ bool CCmdLineParser::parse(int argc,
std::string &outputFileName,
bool &isOutputFileNamedPipe,
bool &verbose,
bool &writeDetectorConfigs)
{
try
{
bool &writeDetectorConfigs) {
try {
boost::program_options::options_description desc(DESCRIPTION);
desc.add_options()
("help", "Display this information and exit")
("version", "Display version information and exit")
("logProperties", boost::program_options::value<std::string>(),
"Optional logger properties file")
("logPipe", boost::program_options::value<std::string>(),
"Optional log to named pipe")
("delimiter", boost::program_options::value<char>(),
"Optional delimiter character for delimited data formats - default is ',' (comma separated)")
("lengthEncodedInput",
"Take input in length encoded binary format - default is delimited")
("timefield", boost::program_options::value<std::string>(),
"Optional name of the field containing the timestamp - default is 'time'")
("timeformat", boost::program_options::value<std::string>(),
"Optional format of the date in the time field in strptime code - default is the epoch time in seconds")
("config", boost::program_options::value<std::string>(),
"Optional configuration file")
("input", boost::program_options::value<std::string>(),
"Optional file to read input from - not present means read from STDIN")
("inputIsPipe", "Specified input file is a named pipe")
("output", boost::program_options::value<std::string>(),
"Optional file to write output to - not present means write to STDOUT")
("outputIsPipe", "Specified output file is a named pipe")
("verbose", "Output information about all detectors including those that have been discarded")
("writeDetectorConfigs",
"Output the detector configurations in JSON format")
("help", "Display this information and exit")
("version", "Display version information and exit")
("logProperties", boost::program_options::value<std::string>(),
"Optional logger properties file")
("logPipe", boost::program_options::value<std::string>(),
"Optional log to named pipe")
("delimiter", boost::program_options::value<char>(),
"Optional delimiter character for delimited data formats - default is ',' (comma separated)")
("lengthEncodedInput",
"Take input in length encoded binary format - default is delimited")
("timefield", boost::program_options::value<std::string>(),
"Optional name of the field containing the timestamp - default is 'time'")
("timeformat", boost::program_options::value<std::string>(),
"Optional format of the date in the time field in strptime code - default is the epoch time in seconds")
("config", boost::program_options::value<std::string>(),
"Optional configuration file")
("input", boost::program_options::value<std::string>(),
"Optional file to read input from - not present means read from STDIN")
("inputIsPipe", "Specified input file is a named pipe")
("output", boost::program_options::value<std::string>(),
"Optional file to write output to - not present means write to STDOUT")
("outputIsPipe", "Specified output file is a named pipe")
("verbose", "Output information about all detectors including those that have been discarded")
("writeDetectorConfigs",
"Output the detector configurations in JSON format")
;

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;
}
Expand Down
9 changes: 3 additions & 6 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,8 +31,7 @@ namespace autoconfig
//! IMPLEMENTATION DECISIONS:\n
//! Put in a class rather than main to allow testing.
//!
class CCmdLineParser
{
class CCmdLineParser {
public:
typedef std::vector<std::string> TStrVec;

Expand Down
22 changes: 7 additions & 15 deletions bin/autoconfig/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
#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;
Expand Down Expand Up @@ -77,8 +76,7 @@ int main(int argc, char **argv)
outputFileName,
isOutputFileNamedPipe,
verbose,
writeDetectorConfigs) == false)
{
writeDetectorConfigs) == false) {
return EXIT_FAILURE;
}

Expand All @@ -89,8 +87,7 @@ int main(int argc, char **argv)
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 +99,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 +127,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