lp-type-lookup.c 1.54 KB
Newer Older
1
/*
Philip Carns's avatar
Philip Carns committed
2
 * Copyright (C) 2013 University of Chicago.
3
 * See COPYRIGHT notice in top-level directory.
Philip Carns's avatar
Philip Carns committed
4
 *
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 */

#include <string.h>
#include <assert.h>

#include "ross.h"
#include "codes/lp-type-lookup.h"

#define MAX_LP_TYPES 64

struct lp_name_mapping
{
    const char* name;
    const tw_lptype* type;
19
    const st_event_collect* ev_type;
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
};

static struct lp_name_mapping map_array[MAX_LP_TYPES];
static int map_array_size = 0;

void lp_type_register(const char* name, const tw_lptype* type)
{
    map_array[map_array_size].name = strdup(name);
    assert(map_array[map_array_size].name);
    map_array[map_array_size].type = type;
    map_array_size++;

    return;
}

const tw_lptype* lp_type_lookup(const char* name)
{
    int i;

    for(i=0; i<map_array_size; i++)
    {
        if(strcmp(name, map_array[i].name) == 0)
        {
            return(map_array[i].type);
        }
    }

    return(NULL);
}

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
// needs to be called after lp_type_register()
void ev_type_register(const char* name, const st_event_collect* type)
{
    int i;

    for(i=0; i<map_array_size; i++)
    {
        if(strcmp(name, map_array[i].name) == 0)
        {
            map_array[i].ev_type = type;
        }
    }
}

const st_event_collect* evcol_type_lookup(const char* name)
{
    int i;

    for(i=0; i<map_array_size; i++)
    {
        if(strcmp(name, map_array[i].name) == 0)
        {
            return(map_array[i].ev_type);
        }
    }

    return(NULL);
}

79 80 81 82 83 84 85 86
/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ft=c ts=8 sts=4 sw=4 expandtab
 */