It may be useful to use more specific error codes, such as
EX_OSERRfor a failedfork()call.In addition, your output statement can be improved. Since
fork()updatesERRNOerrnoon failure, replace your error output with just a call tostd::perror()for a more accurate one.Here's what all this would look like with these changes:
if (pid < 0) { std::perror("fork"); return EX_OSERR; }ManyWhen passing a non-native type (such as
std::string) to a function, it's preferred to pass byconst&to avoid an extra copy:bool contains(std::string const& argName);bool CommandLineOpts::contains(std::string const& argName) { return commandLineMap.count(argName); }Also regarding
const: many of your member functions don't modify data members, yet they don't haveconst. This helps to prevent accidental modification of data members (causing a compiler error) while revealing more of the function's intent to others.Here's an example using one of your member functions:
std::string path(void) const;std::string LoggerConfig::path(void) const { return get(LoggerConfig::LogPath) + "/" + get(LoggerConfig::LogName); }Another note: Unlike in C, it's unnecessary to specify
voidfor functions that don't take anyno arguments in C++. The compiler will already be aware of this.In
parseOpts(), it doesn't look like you should try to catch either anstd::exceptionor...and then throw either one as anstd::runtime_error. The specific exception you may be looking for isstd::logic_error. But this would depend on exactly which exception(s) can be thrown in this function.In
showHelp(), you don't need to do all that flushing withstd::endl, which affects performance. Instead, output a"\n"for just a newline.Since you're using C++11, you can use range-based
forloops.For For example, this can be applied to the loop in
dump():for (auto& it : configMap) { std::cout << it.first << "=" << it.second << std::endl; }
It may be useful to use more specific error codes, such as
EX_OSERRfor a failedfork()call.In addition, your output statement can be improved. Since
fork()updatesERRNOon failure, replace your error output with just a call tostd::perror()for a more accurate one.Here's what all this would look like with these changes:
if (pid < 0) { std::perror("fork"); return EX_OSERR; }Many of your member functions don't modify data members, yet they don't have
const. This helps to prevent accidental modification of data members (causing a compiler error) while revealing more of the function's intent to others.Here's an example using one of your member functions:
std::string path(void) const;std::string LoggerConfig::path(void) const { return get(LoggerConfig::LogPath) + "/" + get(LoggerConfig::LogName); }Another note: Unlike in C, it's unnecessary to specify
voidfor functions that don't take any arguments in C++. The compiler will already be aware of this.In
parseOpts(), it doesn't look like you should try to catch either anstd::exceptionor...and then throw either one as anstd::runtime_error. The specific exception you may be looking for isstd::logic_error. But this would depend on exactly which exception(s) can be thrown in this function.In
showHelp(), you don't need to do all that flushing withstd::endl, which affects performance. Instead, output a"\n"for just a newline.Since you're using C++11, you can use range-based
forloops.For example, this can be applied to the loop in
dump():for (auto& it : configMap) { std::cout << it.first << "=" << it.second << std::endl; }
It may be useful to use more specific error codes, such as
EX_OSERRfor a failedfork()call.In addition, your output statement can be improved. Since
fork()updateserrnoon failure, replace your error output with just a call tostd::perror()for a more accurate one.if (pid < 0) { std::perror("fork"); return EX_OSERR; }When passing a non-native type (such as
std::string) to a function, it's preferred to pass byconst&to avoid an extra copy:bool contains(std::string const& argName);bool CommandLineOpts::contains(std::string const& argName) { return commandLineMap.count(argName); }Also regarding
const: many of your member functions don't modify data members, yet they don't haveconst. This helps to prevent accidental modification of data members (causing a compiler error) while revealing more of the function's intent to others.std::string path(void) const;std::string LoggerConfig::path(void) const { return get(LoggerConfig::LogPath) + "/" + get(LoggerConfig::LogName); }Unlike in C, it's unnecessary to specify
voidfor functions that take no arguments. The compiler will already be aware of this.In
parseOpts(), it doesn't look like you should try to catch either anstd::exceptionor...and then throw either one as anstd::runtime_error. The specific exception you may be looking for isstd::logic_error. But this would depend on exactly which exception(s) can be thrown in this function.In
showHelp(), you don't need to do all that flushing withstd::endl, which affects performance. Instead, output a"\n"for just a newline.Since you're using C++11, you can use range-based
forloops. For example, this can be applied to the loop indump():for (auto& it : configMap) { std::cout << it.first << "=" << it.second << std::endl; }
It may be useful to use more specific error codes, such as
EX_OSERRfor a failedfork()call.In addition, your output statement can be improved. Since
fork()updatesERRNOon failure, replace your error output with just a call tostd::perror()for a more accurate one.Here's what all this would look like with these changes:
if (pid < 0) { std::perror("fork"); return EX_OSERR; }Many of your member functions don't modify data members, yet they don't have
const. This helps to prevent accidental modification of data members (causing a compiler error) while revealing more of the function's intent to others.Here's an example using one of your member functions:
std::string path(void) const;std::string LoggerConfig::path(void) const { return get(LoggerConfig::LogPath) + "/" + get(LoggerConfig::LogName); }Another note: Unlike in C, it's unnecessary to specify
voidfor functions that don't take any arguments in C++. The compiler will already be aware of this.inIn
parseOpts(), it doesn't look like you should try to catch either anstd::exceptionor...and then throw either one as anstd::runtime_error. The specific exception you may be looking for isstd::logic_error. But this would depend on exactly which exceptionsexception(s) can be thrown in this function.In
showHelp(), you don't need to do all that flushing withstd::endl, which affects performance. InsteadInstead, output a"\n"for just a newline.Since you're using C++11, you can use range-based
forloops.For example, this can be applied to the loop in
dump():for (auto& it : configMap) { std::cout << it.first << "=" << it.second << std::endl; }
It may be useful to use more specific error codes, such as
EX_OSERRfor a failedfork()call.In addition, your output statement can be improved. Since
fork()updatesERRNOon failure, replace your error output with just a call tostd::perror()for a more accurate one.Here's what all this would look like with these changes:
if (pid < 0) { std::perror("fork"); return EX_OSERR; }Many of your member functions don't modify data members, yet they don't have
const. This helps to prevent accidental modification of data members while revealing more of the function's intent to others.Here's an example using one of your member functions:
std::string path(void) const;std::string LoggerConfig::path(void) const { return get(LoggerConfig::LogPath) + "/" + get(LoggerConfig::LogName); }Another note: Unlike in C, it's unnecessary to specify
voidfor functions that don't take any arguments in C++.in
parseOpts(), it doesn't look like you should try to catch either anstd::exceptionor...and then throw either one as anstd::runtime_error. The specific exception you may be looking for isstd::logic_error. But this would depend on exactly which exceptions can be thrown in this function.In
showHelp(), you don't need to do all that flushing withstd::endl. Instead, output a"\n"for just a newline.Since you're using C++11, you can use range-based
forloops.For example, this can be applied to the loop in
dump():for (auto& it : configMap) { std::cout << it.first << "=" << it.second << std::endl; }
It may be useful to use more specific error codes, such as
EX_OSERRfor a failedfork()call.In addition, your output statement can be improved. Since
fork()updatesERRNOon failure, replace your error output with just a call tostd::perror()for a more accurate one.Here's what all this would look like with these changes:
if (pid < 0) { std::perror("fork"); return EX_OSERR; }Many of your member functions don't modify data members, yet they don't have
const. This helps to prevent accidental modification of data members (causing a compiler error) while revealing more of the function's intent to others.Here's an example using one of your member functions:
std::string path(void) const;std::string LoggerConfig::path(void) const { return get(LoggerConfig::LogPath) + "/" + get(LoggerConfig::LogName); }Another note: Unlike in C, it's unnecessary to specify
voidfor functions that don't take any arguments in C++. The compiler will already be aware of this.In
parseOpts(), it doesn't look like you should try to catch either anstd::exceptionor...and then throw either one as anstd::runtime_error. The specific exception you may be looking for isstd::logic_error. But this would depend on exactly which exception(s) can be thrown in this function.In
showHelp(), you don't need to do all that flushing withstd::endl, which affects performance. Instead, output a"\n"for just a newline.Since you're using C++11, you can use range-based
forloops.For example, this can be applied to the loop in
dump():for (auto& it : configMap) { std::cout << it.first << "=" << it.second << std::endl; }
It may be useful to use more specific error codes, such as
EX_OSERRfor a failedfork()call.In addition, your output statement can be improved. Since
fork()updatesERRNOon failure, replace your error output with just a call tostd::perror()for a more accurate one.Here's what all this would look like with these changes:
if (pid < 0) { std::perror("fork"); return EX_OSERR; }Many of your member functions don't modify data members, yet they don't have
const. This helps to prevent accidental modification of data members while revealing more of the function's intent to others.Here's an example using one of your member functions:
std::string path(void) const;std::string LoggerConfig::path(void) const { return get(LoggerConfig::LogPath) + "/" + get(LoggerConfig::LogName); }Another note: Unlike in C, it's unnecessary to specify
voidfor functions that don't take any arguments in C++.in
parseOpts(), it doesn't look like you should try to catch either anstd::exceptionor...and then throw either one as anstd::runtime_error. The specific exception you may be looking for isstd::logic_error. But this would depend on exactly which exceptions can be thrown in this function.In
showHelp(), you don't need to do all that flushing withstd::endl. Instead, output a"\n"for just a newline.Since you're using C++11, you can use range-based
forloops.For example, this can be applied to the loop in
dump():for (auto& it : configMap) { std::cout << it.first << "=" << it.second << std::endl; }