+#include <assert.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pcache.h"
+int PData_invariant(const PData *my) {
+ int retVal;
+
+ retVal = my != NULL
+ && my->name != NULL
+ && my->idx != NULL
+ && (my->type == PInt || my->type == PString || my->type == PIntArray || my->type == PStringArray);
+
+ return retVal;
+}
+
PData *newPInt(const char *name, const char *idx, unsigned long int value) {
PData *my = malloc(sizeof(PData));
- my->name = malloc(strlen(name));
+ my->name = malloc(strlen(name)+1);
strcpy(my->name, name);
- my->idx = malloc(strlen(idx));
+ my->idx = malloc(strlen(idx)+1);
strcpy(my->idx, idx);
my->type = PInt;
my->value.PInt = value;
+ assert(PData_invariant(my));
return my;
}
static int keyCompare(const PData *my, const PData *data) {
int retVal;
+ assert(PData_invariant(my));
+ assert(PData_invariant(data));
+
retVal = strcmp(my->name, data->name);
if (retVal == 0) {
retVal = strcmp(my->idx, data->idx);
}
- return retVal;
+ return retVal < 0 ? -1 : retVal > 0 ? 1 : 0;
}
PCache *insert(PCache *my, PData *data) {
+ assert(PData_invariant(data));
+
if (my == NULL) {
my = malloc(sizeof(PCache));
my->r = NULL;
PData *find(const PCache *my, const PData *data) {
PData *retVal;
+ assert(PData_invariant(data));
+
if (my == NULL) {
retVal = NULL;
} else {
}
int PCache_storeInt(PCache **my, const char *name, const char *idx, unsigned long int value) {
+
*my = insert(*my, newPInt(name, idx, value));
+
+ return 0;
}
int PCache_getInt(const PCache *my, const char *name, const char *idx, unsigned long int *value) {
-static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/rpc/rpcParam.c,v 1.7 2004-05-07 11:55:29 muench Exp $";
+static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/rpc/rpcParam.c,v 1.8 2004-05-10 11:20:30 hadaq Exp $";
#define _POSIX_C_SOURCE 199509L
#if HAVE_CONFIG_H
retVal = res.ret;
PCache_storeInt(&rpcParam->cache, name, idx, *val);
- puts("no cache");
} else {
- puts("cache");
+ *row = 1;
}
return retVal;
}