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 struct jim_nvp yn[] = {
{ "yes", 1 },
{ "no" , 0 },
{ "yep", 1 },
{ "nope", 0 },
{ NULL, -1 },
};
struct 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];
int jim_nvp_name2value(Jim_Interp *interp, const struct jim_nvp *_p, const char *name, struct jim_nvp **result)
Definition: jim-nvp.c:71
Name Value Pairs, aka: NVP.
Definition: jim-nvp.h:60
#define NULL
Definition: usb.h:16

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

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

Field Documentation

◆ name

◆ value


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