PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/llbufferstream.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 152 lines | 46 code | 17 blank | 89 comment | 2 complexity | 66e7621d9295506d8df0d1ea69f3550a MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llbufferstream.h
  3. * @author Phoenix
  4. * @date 2005-10-10
  5. * @brief Classes to treat an LLBufferArray as a c++ iostream.
  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_LLBUFFERSTREAM_H
  29. #define LL_LLBUFFERSTREAM_H
  30. #include <iosfwd>
  31. #include <iostream>
  32. #include "llbuffer.h"
  33. /**
  34. * @class LLBufferStreamBuf
  35. * @brief This implements the buffer wrapper for an istream
  36. *
  37. * The buffer array passed in is not owned by the stream buf object.
  38. */
  39. class LLBufferStreamBuf : public std::streambuf
  40. {
  41. public:
  42. LLBufferStreamBuf(
  43. const LLChannelDescriptors& channels,
  44. LLBufferArray* buffer);
  45. virtual ~LLBufferStreamBuf();
  46. protected:
  47. #if( LL_WINDOWS || __GNUC__ > 2 )
  48. typedef std::streambuf::pos_type pos_type;
  49. typedef std::streambuf::off_type off_type;
  50. #endif
  51. /* @name streambuf vrtual implementations
  52. */
  53. //@{
  54. /*
  55. * @brief called when we hit the end of input
  56. *
  57. * @return Returns the character at the current position or EOF.
  58. */
  59. virtual int underflow();
  60. /*
  61. * @brief called when we hit the end of output
  62. *
  63. * @param c The character to store at the current put position
  64. * @return Returns EOF if the function failed. Any other value on success.
  65. */
  66. virtual int overflow(int c);
  67. /*
  68. * @brief synchronize the buffer
  69. *
  70. * @return Returns 0 on success or -1 on failure.
  71. */
  72. virtual int sync();
  73. /*
  74. * @brief Seek to an offset position in a stream.
  75. *
  76. * @param off Offset value relative to way paramter
  77. * @param way The seek direction. One of ios::beg, ios::cur, and ios::end.
  78. * @param which Which pointer to modify. One of ios::in, ios::out,
  79. * or both masked together.
  80. * @return Returns the new position or an invalid position on failure.
  81. */
  82. #if( LL_WINDOWS || __GNUC__ > 2)
  83. virtual pos_type seekoff(
  84. off_type off,
  85. std::ios::seekdir way,
  86. std::ios::openmode which);
  87. #else
  88. virtual streampos seekoff(
  89. streamoff off,
  90. std::ios::seekdir way,
  91. std::ios::openmode which);
  92. #endif
  93. /*
  94. * @brief Get s sequence of characters from the input
  95. *
  96. * @param dst Pointer to a block of memory to accept the characters
  97. * @param length Number of characters to be read
  98. * @return Returns the number of characters read
  99. */
  100. //virtual streamsize xsgetn(char* dst, streamsize length);
  101. /*
  102. * @brief Write some characters to output
  103. *
  104. * @param src Pointer to a sequence of characters to be output
  105. * @param length Number of characters to be put
  106. * @return Returns the number of characters written
  107. */
  108. //virtual streamsize xsputn(char* src, streamsize length);
  109. //@}
  110. protected:
  111. // This channels we are working on.
  112. LLChannelDescriptors mChannels;
  113. // The buffer we work on
  114. LLBufferArray* mBuffer;
  115. };
  116. /**
  117. * @class LLBufferStream
  118. * @brief This implements an istream based wrapper around an LLBufferArray.
  119. *
  120. * This class does not own the buffer array, and does not hold a
  121. * shared pointer to it. Since the class itself is fairly ligthweight,
  122. * just make one on the stack when needed and let it fall out of
  123. * scope.
  124. */
  125. class LLBufferStream : public std::iostream
  126. {
  127. public:
  128. LLBufferStream(
  129. const LLChannelDescriptors& channels,
  130. LLBufferArray* buffer);
  131. ~LLBufferStream();
  132. protected:
  133. LLBufferStreamBuf mStreamBuf;
  134. };
  135. #endif // LL_LLBUFFERSTREAM_H