PageRenderTime 23ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llmemorystream.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 81 lines | 21 code | 10 blank | 50 comment | 0 complexity | f2491744870a79e735980cb5c5f95bc4 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llmemorystream.h
  3. * @author Phoenix
  4. * @date 2005-06-03
  5. * @brief Implementation of a simple fixed memory stream
  6. *
  7. * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #ifndef LL_LLMEMORYSTREAM_H
  29. #define LL_LLMEMORYSTREAM_H
  30. /**
  31. * This is a simple but effective optimization when you want to treat
  32. * a chunk of memory as an istream. I wrote this to avoid turing a
  33. * buffer into a string, and then throwing the string into an
  34. * iostringstream just to parse it into another datatype, eg, LLSD.
  35. */
  36. #include <iostream>
  37. /**
  38. * @class LLMemoryStreamBuf
  39. * @brief This implements a wrapper around a piece of memory for istreams
  40. *
  41. * The memory passed in is NOT owned by an instance. The caller must
  42. * be careful to always pass in a valid memory location that exists
  43. * for at least as long as this streambuf.
  44. */
  45. class LL_COMMON_API LLMemoryStreamBuf : public std::streambuf
  46. {
  47. public:
  48. LLMemoryStreamBuf(const U8* start, S32 length);
  49. ~LLMemoryStreamBuf();
  50. void reset(const U8* start, S32 length);
  51. protected:
  52. int underflow();
  53. //std::streamsize xsgetn(char* dest, std::streamsize n);
  54. };
  55. /**
  56. * @class LLMemoryStream
  57. * @brief This implements a wrapper around a piece of memory for istreams
  58. *
  59. * The memory passed in is NOT owned by an instance. The caller must
  60. * be careful to always pass in a valid memory location that exists
  61. * for at least as long as this streambuf.
  62. */
  63. class LL_COMMON_API LLMemoryStream : public std::istream
  64. {
  65. public:
  66. LLMemoryStream(const U8* start, S32 length);
  67. ~LLMemoryStream();
  68. protected:
  69. LLMemoryStreamBuf mStreamBuf;
  70. };
  71. #endif // LL_LLMEMORYSTREAM_H