Added explicit initialization for a couple variables

This commit is contained in:
Cameron Reed 2022-08-20 16:54:48 -06:00
parent fbb7a689e7
commit 53e81db0ea
3 changed files with 7 additions and 8 deletions

View File

@ -17,8 +17,7 @@ enum ERROR {
SPECIAL_CASE_HELP
};
enum OPTTYPE
{
enum OPTTYPE {
FLAG = 0,
STRING,
INT
@ -79,7 +78,6 @@ private:
private:
const char* m_program_name;
const char* m_description;
const char** m_argv;
uint16_t m_opt_index;
uint16_t m_pos_index;
std::vector<Option*> m_options;

View File

@ -52,7 +52,7 @@ test_installed:
$(CXX) test.cpp $(CXXFLAGS) -l$(LIB_NAME) -o $(BUILD_DIR)/test
-$(BUILD_DIR)/test
install:
install: all
$(CP) $(BUILD_DIR)/$(LIB_FILE_NAME) $(INSTALL_DIR)
$(CP) $(HEADERS) $(HEADER_INSTALL_DIR)
@ -63,4 +63,4 @@ uninstall:
clean:
$(RM) -r $(BUILD_DIR)
.PHONY: test install uninstall clean
.PHONY: all test install uninstall clean

View File

@ -36,7 +36,7 @@ bool Option::found()
}
PositionalArgument::PositionalArgument(const char* name, bool required, OPTTYPE type /* = STRING */)
: m_name(name), m_type(type), m_req(required)
: m_name(name), m_type(type), m_req(required), m_found(false)
{
if (type == FLAG) {
std::cout << "Warning OPTTYPE 'FLAG' is not meant to be used with positional arguments" << std::endl;
@ -51,7 +51,7 @@ bool PositionalArgument::found()
}
Parser::Parser(const char* program_name)
: m_program_name(program_name), m_description(nullptr), m_options() {}
: m_program_name(program_name), m_description(nullptr), m_options(), m_positional_args() {}
void Parser::set_description(const char* description)
{
@ -68,8 +68,9 @@ void Parser::add_positional_argument(PositionalArgument* arg)
m_positional_args.push_back(arg);
}
ERROR Parser::parse(int argc, char ** argv)
ERROR Parser::parse(int argc, char** argv)
{
m_pos_index = 0;
for (m_opt_index = 1; m_opt_index < argc; m_opt_index++)
{
if (argv[m_opt_index][0] == '-' && argv[m_opt_index][1] == '-') {