strintmap.h

00001 
00002 //
00003 // Copyright (c) 2000-2003 Intel Corporation 
00004 // All rights reserved. 
00005 //
00006 // Redistribution and use in source and binary forms, with or without 
00007 // modification, are permitted provided that the following conditions are met: 
00008 //
00009 // * Redistributions of source code must retain the above copyright notice, 
00010 // this list of conditions and the following disclaimer. 
00011 // * Redistributions in binary form must reproduce the above copyright notice, 
00012 // this list of conditions and the following disclaimer in the documentation 
00013 // and/or other materials provided with the distribution. 
00014 // * Neither name of Intel Corporation nor the names of its contributors 
00015 // may be used to endorse or promote products derived from this software 
00016 // without specific prior written permission.
00017 // 
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 
00022 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
00025 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
00026 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
00028 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00031 
00032 #ifndef GENLIB_UTIL_STRINTMAP_H
00033 #define GENLIB_UTIL_STRINTMAP_H
00034 
00035 #include <stdlib.h>
00036 #include "util.h"
00037 
00038 // Util to map from a string to an integer and vice versa
00039 
00040 typedef struct // str_int_entry
00041 {
00042         char *name;             // a value in string form
00043         int  id;                // same value in integer form
00044 } str_int_entry;
00045 
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049 
00050 /************************************************************************
00051 *       Function :      map_str_to_int
00052 *
00053 *       Parameters :
00054 *               IN const char* name ;   string containing the name to be matched
00055 *               IN size_t name_len ;    size of the string to be matched
00056 *               IN str_int_entry* table ;       table of entries that need to be 
00057 *                                       matched.
00058 *               IN int num_entries ; number of entries in the table that need 
00059 *                                       to be searched.
00060 *               IN xboolean case_sensitive ; whether the case should be case
00061 *                                       sensitive or not
00062 *
00063 *       Description : Match the given name with names from the entries in the 
00064 *               table. Returns the index of the table when the entry is found.
00065 *
00066 *       Return : int ;
00067 *               index - On Success
00068 *               -1 - On failure
00069 *
00070 *       Note :
00071 ************************************************************************/
00072 int map_str_to_int( IN const char* name, IN size_t name_len,
00073                 IN str_int_entry* table, IN int num_entries, 
00074                 IN xboolean case_sensitive );
00075 
00076 
00077 /************************************************************************
00078 *       Function :      map_int_to_str
00079 *
00080 *       Parameters :
00081 *               IN int id ;     ID to be matched
00082 *               IN str_int_entry* table ;       table of entries that need to be 
00083 *                                       matched.
00084 *               IN int num_entries ; number of entries in the table that need 
00085 *                                       to be searched.
00086 *
00087 *       Description : Returns the index from the table where the id matches 
00088 *               the entry from the table.
00089 *
00090 *       Return : int ;
00091 *
00092 *       Note :
00093 ************************************************************************/
00094 int map_int_to_str( IN int id, IN str_int_entry* table,
00095                 IN int num_entries );
00096 
00097 #ifdef __cplusplus
00098 } // extern C
00099 #endif
00100 
00101 
00102 #endif // GENLIB_UTIL_STRINTMAP_H