aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llmemorystream.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcommon/llmemorystream.h')
-rw-r--r--linden/indra/llcommon/llmemorystream.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llmemorystream.h b/linden/indra/llcommon/llmemorystream.h
new file mode 100644
index 0000000..4210eb9
--- /dev/null
+++ b/linden/indra/llcommon/llmemorystream.h
@@ -0,0 +1,82 @@
1/**
2 * @file llmemorystream.h
3 * @author Phoenix
4 * @date 2005-06-03
5 * @brief Implementation of a simple fixed memory stream
6 *
7 * Copyright (c) 2005-2007, Linden Research, Inc.
8 *
9 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement
12 * ("Other License"), formally executed by you and Linden Lab. Terms of
13 * the GPL can be found in doc/GPL-license.txt in this distribution, or
14 * online at http://secondlife.com/developers/opensource/gplv2
15 *
16 * There are special exceptions to the terms and conditions of the GPL as
17 * it is applied to this Source Code. View the full text of the exception
18 * in the file doc/FLOSS-exception.txt in this software distribution, or
19 * online at http://secondlife.com/developers/opensource/flossexception
20 *
21 * By copying, modifying or distributing this software, you acknowledge
22 * that you have read and understood your obligations described above,
23 * and agree to abide by those obligations.
24 *
25 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
26 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
27 * COMPLETENESS OR PERFORMANCE.
28 */
29
30#ifndef LL_LLMEMORYSTREAM_H
31#define LL_LLMEMORYSTREAM_H
32
33/**
34 * This is a simple but effective optimization when you want to treat
35 * a chunk of memory as an istream. I wrote this to avoid turing a
36 * buffer into a string, and then throwing the string into an
37 * iostringstream just to parse it into another datatype, eg, LLSD.
38 */
39
40#include <iostream>
41
42/**
43 * @class LLMemoryStreamBuf
44 * @brief This implements a wrapper around a piece of memory for istreams
45 *
46 * The memory passed in is NOT owned by an instance. The caller must
47 * be careful to always pass in a valid memory location that exists
48 * for at least as long as this streambuf.
49 */
50class LLMemoryStreamBuf : public std::streambuf
51{
52public:
53 LLMemoryStreamBuf(const U8* start, S32 length);
54 ~LLMemoryStreamBuf();
55
56 void reset(const U8* start, S32 length);
57
58protected:
59 int underflow();
60 //std::streamsize xsgetn(char* dest, std::streamsize n);
61};
62
63
64/**
65 * @class LLMemoryStream
66 * @brief This implements a wrapper around a piece of memory for istreams
67 *
68 * The memory passed in is NOT owned by an instance. The caller must
69 * be careful to always pass in a valid memory location that exists
70 * for at least as long as this streambuf.
71 */
72class LLMemoryStream : public std::istream
73{
74public:
75 LLMemoryStream(const U8* start, S32 length);
76 ~LLMemoryStream();
77
78protected:
79 LLMemoryStreamBuf mStreamBuf;
80};
81
82#endif // LL_LLMEMORYSTREAM_H