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_BITMASKTOSTR_H__
00021 #define __CS_CSTOOL_BITMASKTOSTR_H__
00022
00027 #include "csutil/csstring.h"
00028
00036 class CS_CRYSTALSPACE_EXPORT csBitmaskToString
00037 {
00038 public:
00040 struct MaskNames
00041 {
00043 uint bits;
00045 const char* name;
00046 };
00048 CS_DECLARE_STATIC_CLASSVAR_REF(scratch, GetScratch, csString)
00057 static const char* GetStr (uint mask, const MaskNames* names)
00058 {
00059 if (mask == 0)
00060 return "0";
00061
00062 GetScratch().Clear();
00063 while (names->bits != 0)
00064 {
00065 if (mask & names->bits)
00066 {
00067 GetScratch() << " | " << names->name;
00068 mask &= ~names->bits;
00069 }
00070 names++;
00071 }
00072 if (mask != 0)
00073 {
00074 GetScratch().AppendFmt (" | %#x", mask);
00075 }
00076 return GetScratch().GetData() + 3;
00077 }
00078 };
00079
00084 #define CS_BITMASKTOSTR_MASK_TABLE_BEGIN(tableName) \
00085 static const csBitmaskToString::MaskNames tableName[] = {
00086
00090 #define CS_BITMASKTOSTR_MASK_TABLE_DEFINE(def) \
00091 {def, #def},
00092
00093 #define CS_BITMASKTOSTR_MASK_TABLE_END \
00094 {0, 0} \
00095 }
00096
00099 #endif // __CS_CSTOOL_BITMASKTOSTR_H__