00001 #include "kwdset.h"
00002 #include "iotools.h"
00003 #include <string.h>
00004
00005 kwdset::kwdset(const long num, const enumstr *setptr)
00006 {
00007 n = num;
00008 set = setptr;
00009 }
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 const char* kwdset::get_str(const int i) const
00024 {
00025 long j;
00026 for(j=0; j < n; j++)
00027 {
00028 if (set[j].id == i)
00029 return (set[j].alias);
00030 }
00031 print_err("Cannot convert enum integer value %d to alias string", __FILE__, __LINE__, __func__, i);
00032 return NULL;
00033 }
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 const int kwdset::get_id(const char *s) const
00048 {
00049 long j;
00050 for(j=0; j < n; j++)
00051 {
00052 if (strcmp(s, set[j].alias) == 0)
00053 return set[j].id;
00054 }
00055 print_err("Cannot convert string '%s' to enum integer value", __FILE__, __LINE__, __func__, s);
00056 return -1;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 const int kwdset::get_id(char *s) const
00072 {
00073 long j;
00074 for(j=0; j < n; j++)
00075 {
00076 if (strcmp(s, set[j].alias) == 0)
00077 return set[j].id;
00078 }
00079 print_err("Cannot convert string '%s' to enum integer value", __FILE__, __LINE__, __func__, s);
00080 return -1;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 long kwdset::check_int(int val) const
00096 {
00097 long j;
00098
00099 for(j=0; j < n; j++)
00100 {
00101 if (set[j].id == val)
00102 return 0;
00103 }
00104 return 1;
00105 }