00001
00002 #ifndef _CKLISTSTRING_H
00003 #define _CKLISTSTRING_H
00004
00005
00006
00007
00008
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011 #include <string.h>
00012
00013 class CkListString
00014 {
00015 private:
00016 char *list;
00017 public:
00018 CkListString(): list(NULL) {}
00019 CkListString(char *s) { list = strdup(s); }
00020 ~CkListString() { if (list) free(list); }
00021 void set(char *s) { list = strdup(s); }
00022 int isEmpty() { return list == NULL; }
00023 int includes(int p) {
00024 size_t i;
00025 int ret = 0;
00026 if (list == NULL) return 1;
00027 char *dupstr = strdup(list);
00028 char *str = strtok(dupstr, ",");
00029 while (str) {
00030 int hasdash=0, hascolon=0, hasdot=0;
00031 for (i=0; i<strlen(str); i++) {
00032 if (str[i] == '-') hasdash=1;
00033 if (str[i] == ':') hascolon=1;
00034 if (str[i] == '.') hasdot=1;
00035 }
00036 int start, end, stride=1, block=1;
00037 if (hasdash) {
00038 if (hascolon) {
00039 if (hasdot) {
00040 if (sscanf(str, "%d-%d:%d.%d", &start, &end, &stride, &block) != 4)
00041 printf("Warning: Check the format of \"%s\".\n", str);
00042 }
00043 else {
00044 if (sscanf(str, "%d-%d:%d", &start, &end, &stride) != 3)
00045 printf("Warning: Check the format of \"%s\".\n", str);
00046 }
00047 }
00048 else {
00049 if (sscanf(str, "%d-%d", &start, &end) != 2)
00050 printf("Warning: Check the format of \"%s\".\n", str);
00051 }
00052 }
00053 else {
00054 sscanf(str, "%d", &start);
00055 end = start;
00056 }
00057 if (block > stride) {
00058 printf("Warning: invalid block size in \"%s\" ignored.\n", str);
00059 block=1;
00060 }
00061
00062 if (p<=end && p>=start) {
00063 if ((p-start)%stride < block) ret = 1;
00064 break;
00065 }
00066 str = strtok(NULL, ",");
00067 }
00068 free(dupstr);
00069 return ret;
00070 }
00071 };
00072
00073 #endif