CrystalSpace

Public API Reference

cstool/bitmasktostr.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2005 by Jorrit Tyberghein
00003               (C) 2005 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_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},
00093 #define CS_BITMASKTOSTR_MASK_TABLE_END                        \
00094     {0, 0}                                                    \
00095   }
00096 
00099 #endif // __CS_CSTOOL_BITMASKTOSTR_H__

Generated for Crystal Space 1.0.2 by doxygen 1.4.7