PageRenderTime 28ms CodeModel.GetById 22ms app.highlight 3ms 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
 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
29#ifndef LL_LLMEMORYSTREAM_H
30#define LL_LLMEMORYSTREAM_H
31
32/** 
33 * This is a simple but effective optimization when you want to treat
34 * a chunk of memory as an istream. I wrote this to avoid turing a
35 * buffer into a string, and then throwing the string into an
36 * iostringstream just to parse it into another datatype, eg, LLSD.
37 */
38
39#include <iostream>
40
41/** 
42 * @class LLMemoryStreamBuf
43 * @brief This implements a wrapper around a piece of memory for istreams
44 *
45 * The memory passed in is NOT owned by an instance. The caller must
46 * be careful to always pass in a valid memory location that exists
47 * for at least as long as this streambuf.
48 */
49class LL_COMMON_API LLMemoryStreamBuf : public std::streambuf
50{
51public:
52	LLMemoryStreamBuf(const U8* start, S32 length);
53	~LLMemoryStreamBuf();
54
55	void reset(const U8* start, S32 length);
56
57protected:
58	int underflow();
59	//std::streamsize xsgetn(char* dest, std::streamsize n);
60};
61
62
63/** 
64 * @class LLMemoryStream
65 * @brief This implements a wrapper around a piece of memory for istreams
66 *
67 * The memory passed in is NOT owned by an instance. The caller must
68 * be careful to always pass in a valid memory location that exists
69 * for at least as long as this streambuf.
70 */
71class LL_COMMON_API LLMemoryStream : public std::istream
72{
73public:
74	LLMemoryStream(const U8* start, S32 length);
75	~LLMemoryStream();
76
77protected:
78	LLMemoryStreamBuf mStreamBuf;
79};
80
81#endif // LL_LLMEMORYSTREAM_H