1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2000-2003 Intel Corporation
4
// All rights reserved.
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are met:
9
// * Redistributions of source code must retain the above copyright notice,
10
// this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above copyright notice,
12
// this list of conditions and the following disclaimer in the documentation
13
// and/or other materials provided with the distribution.
14
// * Neither name of Intel Corporation nor the names of its contributors
15
// may be used to endorse or promote products derived from this software
16
// without specific prior written permission.
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
22
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
///////////////////////////////////////////////////////////////////////////
32
#ifndef GENLIB_UTIL_STRINTMAP_H
33
#define GENLIB_UTIL_STRINTMAP_H
38
// Util to map from a string to an integer and vice versa
40
typedef struct // str_int_entry
42
char *name; // a value in string form
43
int id; // same value in integer form
50
/************************************************************************
51
* Function : map_str_to_int
54
* IN const char* name ; string containing the name to be matched
55
* IN size_t name_len ; size of the string to be matched
56
* IN str_int_entry* table ; table of entries that need to be
58
* IN int num_entries ; number of entries in the table that need
60
* IN xboolean case_sensitive ; whether the case should be case
63
* Description : Match the given name with names from the entries in the
64
* table. Returns the index of the table when the entry is found.
71
************************************************************************/
72
int map_str_to_int( IN const char* name, IN size_t name_len,
73
IN str_int_entry* table, IN int num_entries,
74
IN xboolean case_sensitive );
77
/************************************************************************
78
* Function : map_int_to_str
81
* IN int id ; ID to be matched
82
* IN str_int_entry* table ; table of entries that need to be
84
* IN int num_entries ; number of entries in the table that need
87
* Description : Returns the index from the table where the id matches
88
* the entry from the table.
93
************************************************************************/
94
int map_int_to_str( IN int id, IN str_int_entry* table,
102
#endif // GENLIB_UTIL_STRINTMAP_H