PageRenderTime 38ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llcrc.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 68 lines | 17 code | 8 blank | 43 comment | 0 complexity | f4834a8ee4c33378372dee67f3476655 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llcrc.h
  3. * @brief LLCRC class header file.
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLCRC_H
  27. #define LL_LLCRC_H
  28. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. // Class llcrc
  30. //
  31. // Simple 32 bit crc. To use, instantiate an LLCRC instance and feed
  32. // it the bytes you want to check. It will update the internal crc as
  33. // you go, and you can qery it at the end. As a horribly inefficient
  34. // example (don't try this at work kids):
  35. //
  36. // LLCRC crc;
  37. // FILE* fp = LLFile::fopen(filename,"rb");
  38. // while(!feof(fp)) {
  39. // crc.update(fgetc(fp));
  40. // }
  41. // fclose(fp);
  42. // llinfos << "File crc: " << crc.getCRC() << llendl;
  43. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. class LL_COMMON_API LLCRC
  45. {
  46. protected:
  47. U32 mCurrent;
  48. public:
  49. LLCRC();
  50. U32 getCRC() const;
  51. void update(U8 next_byte);
  52. void update(const U8* buffer, size_t buffer_size);
  53. void update(const std::string& filename);
  54. #ifdef _DEBUG
  55. // This function runs tests to make sure the crc is
  56. // working. Returns TRUE if it is.
  57. static BOOL testHarness();
  58. #endif
  59. };
  60. #endif // LL_LLCRC_H