Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_CSTOOL_IDENTSTRINGS_H__
00021 #define __CS_CSTOOL_IDENTSTRINGS_H__
00022
00023 #include "csutil/csstring.h"
00024
00032 class csIdentStrings
00033 {
00034 public:
00035 struct csIdentString
00036 {
00037 int ident;
00038 const char* str;
00039 };
00040 protected:
00041 const csIdentString* strings;
00042 size_t stringCount;
00043 csString* scratch;
00044 public:
00045 csIdentStrings (const csIdentString* str, csString* scratch, size_t cnt) :
00046 strings(str), stringCount(cnt), scratch(scratch) { }
00052 const char* StringForIdent (int ident)
00053 {
00054 size_t l = 0, r = stringCount;
00055 while (l < r)
00056 {
00057 size_t m = (l+r) / 2;
00058 if (strings[m].ident == ident)
00059 {
00060 return strings[m].str;
00061 }
00062 else if (strings[m].ident < ident)
00063 {
00064 l = m + 1;
00065 }
00066 else
00067 {
00068 r = m;
00069 }
00070 }
00071 scratch->Format ("%d", ident);
00072 return scratch->GetData();
00073 }
00074 };
00075
00092 #define CS_IDENT_STRING_LIST(ListName) \
00093 static const csIdentStrings::csIdentString ListName##_strings[] = {
00094
00098 #define CS_IDENT_STRING(Ident) {Ident, #Ident},
00099
00103 #define CS_IDENT_STRING_EXPLICIT(Ident, Str) {Ident, str},
00104
00107 #define CS_IDENT_STRING_LIST_END(ListName) \
00108 {0, 0} \
00109 }; \
00110 CS_IMPLEMENT_STATIC_VAR(Get##ListName##Scratch, csString, ()) \
00111 static csIdentStrings ListName (ListName##_strings, \
00112 Get##ListName##Scratch(), \
00113 (sizeof (ListName##_strings) / sizeof (csIdentStrings::csIdentString)) - 1);
00114
00115 #endif // __CS_CSTOOL_IDENTSTRINGS_H__