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