mrfioc2
2.3.0
|
Hardware link parsing and storage. More...
#include <shareLib.h>
#include <dbDefs.h>
#include <epicsTypes.h>
Go to the source code of this file.
Classes | |
struct | linkOptionEnumType |
struct | linkOptionDef |
Macros | |
#define | linkInt32(Struct, Member, Name, Req, Over) {Name, linkOptionInt32, Req, Over, OFFSET(Struct, Member), sizeof( ((Struct*)0)->Member ), NULL} |
#define | linkDouble(Struct, Member, Name, Req, Over) {Name, linkOptionDouble, Req, Over, OFFSET(Struct, Member), sizeof( ((Struct*)0)->Member ), NULL} |
#define | linkString(Struct, Member, Name, Req, Over) {Name, linkOptionString, Req, Over, OFFSET(Struct, Member), sizeof( ((Struct*)0)->Member ), NULL} |
#define | linkEnum(Struct, Member, Name, Req, Over, Enums) {Name, linkOptionEnum, Req, Over, OFFSET(Struct, Member), sizeof( ((Struct*)0)->Member ), Enums} |
#define | linkOptionEnd {0,linkOptionInvalid,0,0,0,0,NULL} |
#define | LINKOPTIONDEBUG 1 |
Typedefs | |
typedef enum linkOption | linkOption |
typedef struct linkOptionEnumType | linkOptionEnumType |
typedef struct linkOptionDef | linkOptionDef |
Enumerations | |
enum | linkOption { linkOptionInvalid =0, linkOptionInt32, linkOptionDouble, linkOptionString, linkOptionEnum } |
Functions | |
epicsShareFunc int epicsShareAPI | linkOptionsStore (const linkOptionDef *opts, void *user, const char *str, int options) |
Parse a string a store the result. More... | |
epicsShareFunc const char *epicsShareAPI | linkOptionsEnumString (const linkOptionEnumType *Enums, int i, const char *def) |
Return the string associated with Enum 'i'. More... | |
Hardware link parsing and storage.
Utility to parse a macLib style string ('key=val, key2=val2') and store the results directly into a user supplied struture after appropriate type conversion.
Before calling linkOptionsStore() a linkOptionDef structure must be defined for the user structure.
For example:
typedef struct myStruct { ... other stuff epicsUInt32 ival; double dval; epicsUInt32 ival2; int enumval; char strval[20]; } myStruct;
static const linkOptionEnumType colorEnum[] = { {"Red",1}, {"Green",2}, {"Blue",3}, {NULL,0} };
static const linkOptionDef myStructDef[] = { linkInt32 (myStruct, ival, "Integer" , 0, 0), linkInt32 (myStruct, ival2, "Second" , 1, 0), linkDouble(myStruct, dval, "Double" , 1, 0), linkString(myStruct, strval , "String" , 1, 0), linkEnum (myStruct, enumval, "Color" , 1, 0, colorEnum), linkOptionEnd };
Note: The 4th argument is required (1) or optional (0), the 5th whether later definitions override previous ones (1), or are an error (0).
void someFunc(const char *arg) { myStruct mine;
memset(&mine, 0, sizeof(myStruct)); // set defaults
if (linkOptionsStore(myStructDef, &mine, arg, 0)) goto error;
printf("Second=%d\n",mine->ival2); }
Would parse the string 'Second=17, Color=Green, String=Hello world, Double=4.2' and assign ival2=17, dval=4.2, enumval=2, strval="Hello world". ival is not required and since 'Integer' was not specified would not remain unchanged.
Definition in file linkoptions.h.
#define linkDouble | ( | Struct, | |
Member, | |||
Name, | |||
Req, | |||
Over | |||
) | {Name, linkOptionDouble, Req, Over, OFFSET(Struct, Member), sizeof( ((Struct*)0)->Member ), NULL} |
Definition at line 102 of file linkoptions.h.
#define linkEnum | ( | Struct, | |
Member, | |||
Name, | |||
Req, | |||
Over, | |||
Enums | |||
) | {Name, linkOptionEnum, Req, Over, OFFSET(Struct, Member), sizeof( ((Struct*)0)->Member ), Enums} |
Definition at line 108 of file linkoptions.h.
#define linkInt32 | ( | Struct, | |
Member, | |||
Name, | |||
Req, | |||
Over | |||
) | {Name, linkOptionInt32, Req, Over, OFFSET(Struct, Member), sizeof( ((Struct*)0)->Member ), NULL} |
Definition at line 99 of file linkoptions.h.
#define LINKOPTIONDEBUG 1 |
Definition at line 114 of file linkoptions.h.
#define linkOptionEnd {0,linkOptionInvalid,0,0,0,0,NULL} |
Definition at line 111 of file linkoptions.h.
#define linkString | ( | Struct, | |
Member, | |||
Name, | |||
Req, | |||
Over | |||
) | {Name, linkOptionString, Req, Over, OFFSET(Struct, Member), sizeof( ((Struct*)0)->Member ), NULL} |
Definition at line 105 of file linkoptions.h.
typedef enum linkOption linkOption |
typedef struct linkOptionDef linkOptionDef |
typedef struct linkOptionEnumType linkOptionEnumType |
enum linkOption |
Enumerator | |
---|---|
linkOptionInvalid | |
linkOptionInt32 | |
linkOptionDouble | |
linkOptionString | |
linkOptionEnum |
Definition at line 76 of file linkoptions.h.
epicsShareFunc const char* epicsShareAPI linkOptionsEnumString | ( | const linkOptionEnumType * | Enums, |
int | i, | ||
const char * | def | ||
) |
Return the string associated with Enum 'i'.
Enums | A null-terminated array of string/integer pairs |
i | An Enum index |
def | String to be returned in 'i' isn't a valid Enum index. |
Definition at line 226 of file linkoptions.c.
epicsShareFunc int epicsShareAPI linkOptionsStore | ( | const linkOptionDef * | opts, |
void * | user, | ||
const char * | str, | ||
int | options | ||
) |
Parse a string a store the result.
Takes the string 'str', parses it according to 'opts', then sorts the result in 'user'.
opts | A null-terminated array of options. |
user | Pointer to a structure whos member offsets are given in 'opts' |
str | The string to parse |
options | Some modifiers for the parsing process or 0. The only option is LINKOPTIONDEBUG. |
Definition at line 135 of file linkoptions.c.