strintmap.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*******************************************************************************
  2. *
  3. * Copyright (c) 2000-2003 Intel Corporation
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  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.
  17. *
  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.
  29. *
  30. ******************************************************************************/
  31. #ifndef GENLIB_UTIL_STRINTMAP_H
  32. #define GENLIB_UTIL_STRINTMAP_H
  33. #include <stdlib.h>
  34. #include "upnputil.h"
  35. /* Util to map from a string to an integer and vice versa */
  36. typedef struct /* str_int_entry */
  37. {
  38. const char *name; /* a value in string form */
  39. int id; /* same value in integer form */
  40. } str_int_entry;
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /************************************************************************
  45. * Function : map_str_to_int
  46. *
  47. * Parameters :
  48. * IN const char* name ; string containing the name to be matched
  49. * IN size_t name_len ; size of the string to be matched
  50. * IN str_int_entry* table ; table of entries that need to be
  51. * matched.
  52. * IN int num_entries ; number of entries in the table that need
  53. * to be searched.
  54. * IN int case_sensitive ; whether the case should be case
  55. * sensitive or not
  56. *
  57. * Description : Match the given name with names from the entries in the
  58. * table. Returns the index of the table when the entry is found.
  59. *
  60. * Return : int ;
  61. * index - On Success
  62. * -1 - On failure
  63. *
  64. * Note :
  65. ************************************************************************/
  66. int map_str_to_int( IN const char* name, IN size_t name_len,
  67. IN str_int_entry* table, IN int num_entries,
  68. IN int case_sensitive );
  69. /************************************************************************
  70. * Function : map_int_to_str
  71. *
  72. * Parameters :
  73. * IN int id ; ID to be matched
  74. * IN str_int_entry* table ; table of entries that need to be
  75. * matched.
  76. * IN int num_entries ; number of entries in the table that need
  77. * to be searched.
  78. *
  79. * Description : Returns the index from the table where the id matches
  80. * the entry from the table.
  81. *
  82. * Return : int ;
  83. *
  84. * Note :
  85. ************************************************************************/
  86. int map_int_to_str( IN int id, IN str_int_entry* table,
  87. IN int num_entries );
  88. #ifdef __cplusplus
  89. } /* extern C */
  90. #endif
  91. #endif /* GENLIB_UTIL_STRINTMAP_H */