ccFlags.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  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; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #ifndef CC_FLAGS_HEADER
  18. #define CC_FLAGS_HEADER
  19. //System
  20. #include <cstring>
  21. //! Flags
  22. class ccFlags
  23. {
  24. public:
  25. //! Sets all bits to 0
  26. void reset()
  27. {
  28. memset(table,0,sizeof(bool)*8);
  29. }
  30. //! Converts a byte to this structure
  31. void fromByte(unsigned char byte)
  32. {
  33. unsigned char i,mask = 1;
  34. for (i=0;i<8;++i)
  35. {
  36. table[i] = ((byte & mask) == mask);
  37. mask <<= 1;
  38. }
  39. }
  40. //! Converts this structure to a byte
  41. unsigned char toByte() const
  42. {
  43. unsigned char i,byte = 0,mask = 1;
  44. for (i=0;i<8;++i)
  45. {
  46. if (table[i])
  47. byte |= mask;
  48. mask <<= 1;
  49. }
  50. return byte;
  51. }
  52. //! Table of 8 booleans (one per bit)
  53. bool table[8];
  54. };
  55. #endif //CC_FLAGS_HEADER