library/src/blockclass/subclasses/BP_CommandLineOptionParser.cc
// utility routine that will retrieve the current set value of the selected token, and store it within the local class
// token_current_value_as_string member value.  If the value is already set in the class,
// it is automatically freed, nullified, and overwritten.  This is simply for convienence.
utility routine that will retrieve the current set value of the selected token, and store it within the local class
token_current_value_as_string member value.  If the value is already set in the class,
it is automatically freed, nullified, and overwritten.  This is simply for convienence.
utility routine that will retrieve the current set value of the selected token and store it within the local class token_current_value_as_string member value . If the value is already set in the class it is automatically freed nullified and overwritten . This is simply for convienence .
BP_ERROR_T BP_CommandLineOptionParser::getCurrentValueAsCharString(char * option_value)
{
	if(!option_value)
		return ERR_FAILURE;
	P_BP_COMMAND_LINE_PARSER_TOKENS token_lookup = NULL;
	token_lookup = this->optionLookup(option_value);
	if(!token_lookup)
		return ERR_FAILURE;
	if(!token_lookup->value_has_been_set_ok)
		return ERR_FAILURE;
	if(this->token_current_value_as_string)
	{
		tq_free(this->tq, this->token_current_value_as_string);
		this->token_current_value_as_string = NULL;
	}
	char tmp_buff[BP_KILOBYTE/2];
	BP_ZERO_STACK(tmp_buff);
	switch(token_lookup->value_type)
	{
		case BP_COMMAND_LINE_ARGUMENT_UNSET:
			return ERR_FAILURE;
		case BP_COMMAND_LINE_ARGUMENT_STAND_ALONE_TOGGLE:
			this->token_current_value_as_string = tq_strdup(this->tq, token_lookup->parsed_value_as_toggle ? (char *) "On" :(char *)  "Off", BPLN);
			return ERR_SUCCESS;
		case BP_COMMAND_LINE_ARGUMENT_CHAR_STRING:
			this->token_current_value_as_string = tq_strdup(this->tq, (char *) token_lookup->parsed_value_as_string ? token_lookup->parsed_value_as_string : (char *) "Unset", BPLN);
			return ERR_SUCCESS;
		case BP_COMMAND_LINE_ARGUMENT_SIZE_T:
			sprintf(tmp_buff, "%zu", token_lookup->parsed_value_as_size_t);
			this->token_current_value_as_string = tq_strdup(this->tq, tmp_buff, BPLN);
			return ERR_SUCCESS;
		case BP_COMMAND_LINE_ARGUMENT_SIGNED_INT:
			sprintf(tmp_buff, "%i", token_lookup->parsed_value_as_int);
			this->token_current_value_as_string = tq_strdup(this->tq, tmp_buff, BPLN);
			return ERR_SUCCESS;
		case BP_COMMAND_LINE_ARGUMENT_URL:
			this->token_current_value_as_string = tq_strdup(this->tq, token_lookup->parsed_value_as_string ?(char *)  "Unset" : token_lookup->parsed_value_as_string, BPLN);
			return ERR_SUCCESS;
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_CommandLineOptionParser :: getCurrentValueAsCharString ( char * option_value ) { if ( ! option_value ) return ERR_FAILURE ; P_BP_COMMAND_LINE_PARSER_TOKENS token_lookup = NULL ; token_lookup = this -> optionLookup ( option_value ) ; if ( ! token_lookup ) return ERR_FAILURE ; if ( ! token_lookup -> value_has_been_set_ok ) return ERR_FAILURE ; if ( this -> token_current_value_as_string ) { tq_free ( this -> tq , this -> token_current_value_as_string ) ; this -> token_current_value_as_string = NULL ; } char tmp_buff [ BP_KILOBYTE / 2 ] ; BP_ZERO_STACK ( tmp_buff ) ; switch ( token_lookup -> value_type ) { case BP_COMMAND_LINE_ARGUMENT_UNSET : return ERR_FAILURE ; case BP_COMMAND_LINE_ARGUMENT_STAND_ALONE_TOGGLE : this -> token_current_value_as_string = tq_strdup ( this -> tq , token_lookup -> parsed_value_as_toggle ? ( char * ) " " : ( char * ) " " , BPLN ) ; return ERR_SUCCESS ; case BP_COMMAND_LINE_ARGUMENT_CHAR_STRING : this -> token_current_value_as_string = tq_strdup ( this -> tq , ( char * ) token_lookup -> parsed_value_as_string ? token_lookup -> parsed_value_as_string : ( char * ) " " , BPLN ) ; return ERR_SUCCESS ; case BP_COMMAND_LINE_ARGUMENT_SIZE_T : sprintf ( tmp_buff , " " , token_lookup -> parsed_value_as_size_t ) ; this -> token_current_value_as_string = tq_strdup ( this -> tq , tmp_buff , BPLN ) ; return ERR_SUCCESS ; case BP_COMMAND_LINE_ARGUMENT_SIGNED_INT : sprintf ( tmp_buff , " " , token_lookup -> parsed_value_as_int ) ; this -> token_current_value_as_string = tq_strdup ( this -> tq , tmp_buff , BPLN ) ; return ERR_SUCCESS ; case BP_COMMAND_LINE_ARGUMENT_URL : this -> token_current_value_as_string = tq_strdup ( this -> tq , token_lookup -> parsed_value_as_string ? ( char * ) " " : token_lookup -> parsed_value_as_string , BPLN ) ; return ERR_SUCCESS ; } return ERR_SUCCESS ; }
utility routine that will retrieve the current set value of the selected token, and store it within the local class
token_current_value_as_string member value.
utility routine that will retrieve the current set value of the selected token and store it within the local class token_current_value_as_string member value .
// ensure we have an option value // option for local lookup // run option lookup // retrieving current values requires a successful parse // destroy value if it's set // temporary buffer used for building int/size_t values // create buffer by checking type and creating appropriate buffer // return indicating success (should technically never get here)