Panda3D
Loading...
Searching...
No Matches
stringStream.I
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file stringStream.I
10 * @author drose
11 * @date 2007-07-03
12 */
13
14/**
15 *
16 */
17INLINE StringStream::
18StringStream() : std::iostream(&_buf) {
19}
20
21/**
22 * This version of the constructor preloads the buffer with the indicated
23 * data.
24 */
25INLINE StringStream::
26StringStream(const std::string &source) : std::iostream(&_buf) {
27 set_data(source);
28}
29
30/**
31 * Empties the buffer.
32 */
33INLINE void StringStream::
34clear_data() {
35 _buf.clear();
36}
37
38/**
39 * Returns the number of characters available to be read from the data stream.
40 */
41INLINE size_t StringStream::
43 flush();
44 return _buf.get_data().size();
45}
46
47/**
48 * Returns the contents of the data stream as a string.
49 */
50INLINE std::string StringStream::
51get_data() {
52 flush();
53 const vector_uchar &data = _buf.get_data();
54 if (!data.empty()) {
55 return std::string((char *)&data[0], data.size());
56 }
57 return std::string();
58}
59
60/**
61 * Replaces the contents of the data stream. This implicitly reseeks to 0.
62 */
63INLINE void StringStream::
64set_data(const std::string &data) {
65 _buf.clear();
66 if (!data.empty()) {
67 set_data((const unsigned char *)data.data(), data.size());
68 }
69}
70
71/**
72 * Swaps the indicated buffer for the contents of the internal buffer.
73 */
74INLINE void StringStream::
75swap_data(vector_uchar &data) {
76 flush();
77 _buf.swap_data(data);
78}
const vector_uchar & get_data() const
Returns a reference to the contents of the internal buffer, without any of the iostream buffer.
void clear()
Empties the buffer.
void swap_data(vector_uchar &data)
Swaps the indicated buffer for the contents of the internal buffer.
size_t get_data_size()
Returns the number of characters available to be read from the data stream.
get_data
Returns the contents of the data stream as a string.
void clear_data()
Empties the buffer.
set_data
Replaces the contents of the data stream.
void swap_data(vector_uchar &data)
Swaps the indicated buffer for the contents of the internal buffer.
STL namespace.