1 | /* |
---|
2 | * ====================================================================== |
---|
3 | * Rappture::SimpleBuffer |
---|
4 | * |
---|
5 | * AUTHOR: Derrick Kearney, Purdue University |
---|
6 | * |
---|
7 | * Copyright (c) 2004-2008 Purdue Research Foundation |
---|
8 | * ---------------------------------------------------------------------- |
---|
9 | * See the file "license.terms" for information on usage and |
---|
10 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
11 | * ====================================================================== |
---|
12 | * |
---|
13 | * This code is based on the Tcl_DString facility included in the |
---|
14 | * Tcl source release, which includes the following copyright: |
---|
15 | * |
---|
16 | * Copyright (c) 1987-1993 The Regents of the University of California. |
---|
17 | * Copyright (c) 1994-1998 Sun Microsystems, Inc. |
---|
18 | * Copyright (c) 2001 by Kevin B. Kenny. All rights reserved. |
---|
19 | * |
---|
20 | * This software is copyrighted by the Regents of the University of |
---|
21 | * California, Sun Microsystems, Inc., Scriptics Corporation, |
---|
22 | * and other parties. The following terms apply to all files associated |
---|
23 | * with the software unless explicitly disclaimed in individual files. |
---|
24 | * |
---|
25 | * The authors hereby grant permission to use, copy, modify, distribute, |
---|
26 | * and license this software and its documentation for any purpose, provided |
---|
27 | * that existing copyright notices are retained in all copies and that this |
---|
28 | * notice is included verbatim in any distributions. No written agreement, |
---|
29 | * license, or royalty fee is required for any of the authorized uses. |
---|
30 | * Modifications to this software may be copyrighted by their authors |
---|
31 | * and need not follow the licensing terms described here, provided that |
---|
32 | * the new terms are clearly indicated on the first page of each file where |
---|
33 | * they apply. |
---|
34 | * |
---|
35 | * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY |
---|
36 | * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
---|
37 | * ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY |
---|
38 | * DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE |
---|
39 | * POSSIBILITY OF SUCH DAMAGE. |
---|
40 | * |
---|
41 | * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, |
---|
42 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, |
---|
43 | * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE |
---|
44 | * IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE |
---|
45 | * NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR |
---|
46 | * MODIFICATIONS. |
---|
47 | * |
---|
48 | * GOVERNMENT USE: If you are acquiring this software on behalf of the |
---|
49 | * U.S. government, the Government shall have only "Restricted Rights" |
---|
50 | * in the software and related documentation as defined in the Federal· |
---|
51 | * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you |
---|
52 | * are acquiring the software on behalf of the Department of Defense, the |
---|
53 | * software shall be classified as "Commercial Computer Software" and the |
---|
54 | * Government shall have only "Restricted Rights" as defined in Clause |
---|
55 | * 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the |
---|
56 | * authors grant the U.S. Government and others acting in its behalf |
---|
57 | * permission to use and distribute the software in accordance with the |
---|
58 | * terms specified in this license.· |
---|
59 | * |
---|
60 | * ====================================================================== |
---|
61 | */ |
---|
62 | |
---|
63 | #ifndef RAPPTURE_SIMPLEBUFFER_H |
---|
64 | #define RAPPTURE_SIMPLEBUFFER_H |
---|
65 | |
---|
66 | #include <fstream> |
---|
67 | |
---|
68 | #define RP_SIMPLEBUFFER_MIN_SIZE 256 |
---|
69 | |
---|
70 | #ifdef __cplusplus |
---|
71 | extern "C" { |
---|
72 | #endif // ifdef __cplusplus |
---|
73 | |
---|
74 | |
---|
75 | namespace Rappture { |
---|
76 | |
---|
77 | class SimpleBuffer { |
---|
78 | public: |
---|
79 | SimpleBuffer(); |
---|
80 | SimpleBuffer(int nbytes); |
---|
81 | SimpleBuffer(const char* bytes, int nbytes=-1); |
---|
82 | SimpleBuffer(const SimpleBuffer& b); |
---|
83 | SimpleBuffer& operator=(const SimpleBuffer& b); |
---|
84 | SimpleBuffer operator+(const SimpleBuffer& b) const; |
---|
85 | SimpleBuffer& operator+=(const SimpleBuffer& b); |
---|
86 | virtual ~SimpleBuffer(); |
---|
87 | |
---|
88 | const char* bytes() const; |
---|
89 | unsigned int size() const; |
---|
90 | |
---|
91 | SimpleBuffer& clear(); |
---|
92 | int append(const char* bytes, int nbytes=-1); |
---|
93 | int read(const char* bytes, int nbytes); |
---|
94 | int seek(int offset, int whence); |
---|
95 | int tell() const; |
---|
96 | SimpleBuffer& rewind(); |
---|
97 | |
---|
98 | bool good() const; |
---|
99 | bool bad() const; |
---|
100 | bool eof() const; |
---|
101 | |
---|
102 | SimpleBuffer& move(SimpleBuffer& b); |
---|
103 | |
---|
104 | protected: |
---|
105 | |
---|
106 | void bufferInit(); |
---|
107 | void bufferFree(); |
---|
108 | |
---|
109 | private: |
---|
110 | |
---|
111 | /// Pointer to the memory that holds our buffer's data |
---|
112 | char* _buf; |
---|
113 | |
---|
114 | /// Position offset within the buffer's memory |
---|
115 | unsigned int _pos; |
---|
116 | |
---|
117 | /// Size of the used memory in the buffer |
---|
118 | unsigned int _size; |
---|
119 | |
---|
120 | /// Total space available in the buffer |
---|
121 | unsigned int _spaceAvl; |
---|
122 | |
---|
123 | /// State of the last file like operation. |
---|
124 | bool _fileState; |
---|
125 | }; |
---|
126 | |
---|
127 | } // namespace Rappture |
---|
128 | |
---|
129 | #ifdef __cplusplus |
---|
130 | } |
---|
131 | #endif // ifdef __cplusplus |
---|
132 | |
---|
133 | #endif // RAPPTURE_SIMPLEBUFFER_H |
---|