Guest User

Bit_Flags0.1

a guest
Apr 8th, 2012
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     SA-MP Bit_Flags 0.1
  3.     Copyright © 2012 Jonny5
  4.  
  5.     This program is free software: you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation, either version 3 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     To view a copy of the GNU General Public License see http://www.gnu.org/licenses/
  16. */
  17. #if defined _BIT_FLAGS_included
  18.   #endinput
  19. #endif
  20. #define _BIT_FLAGS_included
  21.  
  22. #define BitFlag: enum (<<= 1)
  23.  
  24. forward Check_All_Bit_Flags(flags,{Float,_}:...);
  25. forward Check_Any_Bit_Flags(flags,{Float,_}:...);
  26. forward Check_Bit_Flag(flags,flag);
  27. forward Add_Bit_Flag(&flags,flag);
  28. forward Add_Bit_Flags(&flags,{Float,_}:...);
  29. forward Remove_Bit_Flag(&flags,flag);
  30. forward Remove_Bit_Flags(&flags,{Float,_}:...);
  31. forward Remove_All_Bit_Flags(&flags);
  32.  
  33. public Check_All_Bit_Flags(flags,{Float,_}:...) {for (new i = 1; i < numargs(); ++i)if(!(Check_Bit_Flag(flags,getarg(i)))) return 0;return 1;}
  34. public Check_Any_Bit_Flags(flags,{Float,_}:...) {for (new i = 1; i < numargs(); ++i)if(Check_Bit_Flag(flags,getarg(i))) return 1;return 0;}
  35. public Check_Bit_Flag(flags,flag)               {if((flags &  flag)) return 1;return 0;}
  36. public Add_Bit_Flag(&flags,flag)                {if(!(Check_Bit_Flag(flags,flag))) flags = flags | flag ;return 1;}
  37. public Add_Bit_Flags(&flags,{Float,_}:...)      {for (new i = 1; i < numargs(); ++i)Add_Bit_Flag(flags,getarg(i));return 1;}
  38. public Remove_Bit_Flag(&flags,flag)             {if(Check_Bit_Flag(flags,flag)) flags = flags & ~flag ;return 1;}
  39. public Remove_Bit_Flags(&flags,{Float,_}:...)   {for (new i = 1; i < numargs(); ++i)Remove_Bit_Flag(flags,getarg(i));return 1;}
  40. public Remove_All_Bit_Flags(&flags)             {flags=0;return 1;}
  41.  
  42. //for pawno ref
  43. /*
  44. native Check_All_Bit_Flags(flags,{Float,_}:...); //checks for all flags
  45. native Check_Any_Bit_Flags(flags,{Float,_}:...); //checks for any flags
  46. native Check_Bit_Flag(flags,flag); //check for a single flag
  47. native
  48. native Add_Bit_Flag(&flags,flag); //Add a flag
  49. native Add_Bit_Flags(&flags,{Float,_}:...); //add a list of flags
  50. native
  51. native Remove_Bit_Flag(&flags,flag); //remove one flag
  52. native Remove_Bit_Flags(&flags,{Float,_}:...); //remove a list of flags
  53. Remove_All_Bit_Flags(&flags); //removes all flags
  54. */
RAW Paste Data