OpenOCD
Jim_Nvp Struct Reference

Name Value Pairs, aka: NVP. More...

Data Fields

const char * name
 
int value
 

Detailed Description

Name Value Pairs, aka: NVP.

  • Given a string - return the associated int.
  • Given a number - return the associated string.

Very useful when the number is not a simple index into an array of known string, or there may be multiple strings (aliases) that mean then same thing.

An NVP Table is terminated with ".name = NULL".

During the 'name2value' operation, if no matching string is found the pointer to the terminal element (with p->name == NULL) is returned.

Example:

const Jim_Nvp yn[] = {
{ "yes", 1 },
{ "no" , 0 },
{ "yep", 1 },
{ "nope", 0 },
{ NULL, -1 },
};
Jim_Nvp *result
e = Jim_Nvp_name2value(interp, yn, "y", &result);
returns &yn[0];
e = Jim_Nvp_name2value(interp, yn, "n", &result);
returns &yn[1];
e = Jim_Nvp_name2value(interp, yn, "Blah", &result);
returns &yn[4];

During the number2name operation, the first matching value is returned.

Definition at line 84 of file jim-nvp.h.

Field Documentation

◆ name

◆ value


The documentation for this struct was generated from the following file: