CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

identstrings.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004 by Jorrit Tyberghein
00003               (C) 2004 by Frank Richter
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */      
00019 
00020 #ifndef __CS_CSTOOL_IDENTSTRINGS_H__
00021 #define __CS_CSTOOL_IDENTSTRINGS_H__
00022 
00030 class csIdentStrings
00031 {
00032 public:
00033   struct csIdentString
00034   {
00035     int ident;
00036     const char* str;
00037   };
00038 protected:
00039   const csIdentString* strings;
00040   size_t stringCount;
00041 public:
00042   csIdentStrings (const csIdentString* str, size_t cnt) :
00043     strings(str), stringCount(cnt) { }
00045   const char* StringForIdent (int ident)
00046   {
00047     size_t l = 0, r = stringCount;
00048     while (l < r)
00049     {
00050       size_t m = (l+r) / 2;
00051       if (strings[m].ident == ident)
00052       {
00053         return strings[m].str;
00054       }
00055       else if (strings[m].ident < ident)
00056       {
00057         l = m + 1;
00058       }
00059       else
00060       {
00061         r = m;
00062       }
00063     }
00064     return 0;
00065   }
00066 };
00067 
00084 #define CS_IDENT_STRING_LIST(ListName)                                  \
00085   static csIdentStrings::csIdentString ListName##_strings[] = {
00086 
00090 #define CS_IDENT_STRING(Ident)                          {Ident, #Ident},
00091 
00095 #define CS_IDENT_STRING_EXPLICIT(Ident, Str)            {Ident, str},
00096 
00099 #define CS_IDENT_STRING_LIST_END(ListName)                              \
00100     {0, 0}                                                              \
00101   };                                                                    \
00102   static csIdentStrings ListName (ListName##_strings,                   \
00103     (sizeof (ListName##_strings) / sizeof (csIdentStrings::csIdentString)) - 1);
00104 
00105 #endif // __CS_CSTOOL_IDENTSTRINGS_H__

Generated for Crystal Space by doxygen 1.3.9.1