]> git.ipfire.org Git - thirdparty/squid.git/blame - src/SBuf.h
Typo in rev.13366
[thirdparty/squid.git] / src / SBuf.h
CommitLineData
412da427 1/*
412da427
FC
2 * SQUID Web Proxy Cache http://www.squid-cache.org/
3 * ----------------------------------------------------------
4 *
5 * Squid is the result of efforts by numerous individuals from
6 * the Internet community; see the CONTRIBUTORS file for full
7 * details. Many organizations have provided support for Squid's
8 * development; see the SPONSORS file for full details. Squid is
9 * Copyrighted (C) 2001 by the Regents of the University of
10 * California; see the COPYRIGHT file for full details. Squid
11 * incorporates software developed and/or copyrighted by other
12 * sources; see the CREDITS file for full details.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 */
28
29#ifndef SQUID_SBUF_H
30#define SQUID_SBUF_H
31
32#include "base/InstanceId.h"
412da427 33#include "MemBlob.h"
62842d40 34#include "SBufExceptions.h"
412da427
FC
35#include "SquidString.h"
36
62842d40 37#include <climits>
074d6a40
AJ
38#include <cstdarg>
39#include <iosfwd>
412da427
FC
40#if HAVE_UNISTD_H
41#include <unistd.h>
42#endif
412da427 43
496a9e97 44/* SBuf placeholder for printf */
412da427
FC
45#ifndef SQUIDSBUFPH
46#define SQUIDSBUFPH "%.*s"
47#define SQUIDSBUFPRINT(s) (s).plength(),(s).rawContent()
48#endif /* SQUIDSBUFPH */
49
6a17a36d 50// TODO: move within SBuf and rename
412da427
FC
51typedef enum {
52 caseSensitive,
53 caseInsensitive
54} SBufCaseSensitive;
55
56/**
57 * Container for various SBuf class-wide statistics.
58 *
59 * The stats are not completely accurate; they're mostly meant to
60 * understand whether Squid is leaking resources
61 * and whether SBuf is paying off the expected gains.
62 */
63class SBufStats
64{
65public:
7cbd3256
FC
66 uint64_t alloc; ///<number of calls to SBuf constructors
67 uint64_t allocCopy; ///<number of calls to SBuf copy-constructor
68 uint64_t allocFromString; ///<number of copy-allocations from Strings
69 uint64_t allocFromCString; ///<number of copy-allocations from c-strings
70 uint64_t assignFast; ///<number of no-copy assignment operations
71 uint64_t clear; ///<number of clear operations
72 uint64_t append; ///<number of append operations
73 uint64_t toStream; ///<number of write operations to ostreams
74 uint64_t setChar; ///<number of calls to setAt
75 uint64_t getChar; ///<number of calls to at() and operator[]
76 uint64_t compareSlow; ///<number of comparison operations requiring data scan
77 uint64_t compareFast; ///<number of comparison operations not requiring data scan
78 uint64_t copyOut; ///<number of data-copies to other forms of buffers
79 uint64_t rawAccess; ///<number of accesses to raw contents
7f175a76 80 uint64_t nulTerminate; ///<number of c_str() terminations
7cbd3256
FC
81 uint64_t chop; ///<number of chop operations
82 uint64_t trim; ///<number of trim operations
83 uint64_t find; ///<number of find operations
84 uint64_t scanf; ///<number of scanf operations
85 uint64_t caseChange; ///<number of toUpper and toLower operations
86 uint64_t cowFast; ///<number of cow operations not actually requiring a copy
87 uint64_t cowSlow; ///<number of cow operations requiring a copy
88 uint64_t live; ///<number of currently-allocated SBuf
412da427 89
496a9e97 90 ///Dump statistics to an ostream.
412da427
FC
91 std::ostream& dump(std::ostream &os) const;
92 SBufStats();
93
94 SBufStats& operator +=(const SBufStats&);
95};
96
4685b0c4
FC
97class CharacterSet;
98
412da427
FC
99/**
100 * A String or Buffer.
101 * Features: refcounted backing store, cheap copy and sub-stringing
102 * operations, copy-on-write to isolate change operations to each instance.
103 * Where possible, we're trying to mimic std::string's interface.
104 */
105class SBuf
106{
107public:
7cbd3256 108 typedef MemBlob::size_type size_type;
50827187 109 static const size_type npos = 0xffffffff; // max(uint32_t)
412da427
FC
110
111 /// Maximum size of a SBuf. By design it MUST be < MAX(size_type)/2. Currently 256Mb.
112 static const size_type maxSize = 0xfffffff;
113
114 /// create an empty (zero-size) SBuf
115 SBuf();
116 SBuf(const SBuf &S);
117
118 /** Constructor: import c-style string
119 *
120 * Create a new SBuf containing a COPY of the contents of the
121 * c-string
122 * \param S the c string to be copied
7cbd3256 123 * \param n how many bytes to import into the SBuf. If it is npos
412da427
FC
124 * or unspecified, imports to end-of-cstring
125 * \note it is the caller's responsibility not to go out of bounds
50827187 126 * \note bounds is 0 <= pos < length(); caller must pay attention to signedness
412da427 127 */
7cbd3256 128 explicit SBuf(const char *S, size_type n = npos);
412da427
FC
129
130 /** Constructor: import SquidString, copying contents.
131 *
132 * This method will be removed once SquidString has gone.
133 */
496a9e97
FC
134 explicit SBuf(const String &S);
135
136 /// Constructor: import std::string. Contents are copied.
137 explicit SBuf(const std::string &s);
412da427
FC
138
139 ~SBuf();
62842d40 140
412da427
FC
141 /** Explicit assignment.
142 *
143 * Current SBuf will share backing store with the assigned one.
144 */
145 SBuf& assign(const SBuf &S);
62842d40 146
412da427
FC
147 /** Assignment operator.
148 *
149 * Current SBuf will share backing store with the assigned one.
150 */
62842d40 151 SBuf& operator =(const SBuf & S) {return assign(S);}
412da427
FC
152
153 /** Import a c-string into a SBuf, copying the data.
154 *
155 * It is the caller's duty to free the imported string, if needed.
156 * \param S the c string to be copied
7cbd3256 157 * \param n how many bytes to import into the SBuf. If it is npos
412da427
FC
158 * or unspecified, imports to end-of-cstring
159 * \note it is the caller's responsibility not to go out of bounds
7cbd3256
FC
160 * \note to assign a std::string use the pattern:
161 * assign(stdstr.data(), stdstd.length())
412da427 162 */
7cbd3256 163 SBuf& assign(const char *S, size_type n = npos);
412da427
FC
164
165 /** Assignment operator. Copy a NULL-terminated c-style string into a SBuf.
166 *
167 * Copy a c-style string into a SBuf. Shortcut for SBuf.assign(S)
168 * It is the caller's duty to free the imported string, if needed.
7cbd3256 169 * \note not \0-clean
412da427 170 */
62842d40 171 SBuf& operator =(const char *S) {return assign(S);}
412da427 172
412da427
FC
173 /** reset the SBuf as if it was just created.
174 *
175 * Resets the SBuf to empty, memory is freed lazily.
176 */
177 void clear();
178
179 /** Append operation
180 *
181 * Append the supplied SBuf to the current one; extend storage as needed.
182 */
183 SBuf& append(const SBuf & S);
184
185 /** Append operation for C-style strings.
186 *
187 * Append the supplied c-string to the SBuf; extend storage
188 * as needed.
189 *
190 * \param S the c string to be copied. Can be NULL.
a452bc8b
FC
191 * \param Ssize how many bytes to import into the SBuf. If it is npos
192 * or unspecified, imports to end-of-cstring. If S is NULL,
193 * Ssize is ignored.
7cbd3256
FC
194 * \note to append a std::string use the pattern
195 * cstr_append(stdstr.data(), stdstd.length())
412da427 196 */
7cbd3256 197 SBuf& append(const char * S, size_type Ssize = npos);
412da427
FC
198
199 /** Assignment operation with printf(3)-style definition
200 * \note arguments may be evaluated more than once, be careful
201 * of side-effects
202 */
203 SBuf& Printf(const char *fmt, ...);
204
205 /** Append operation with printf-style arguments
206 * \note arguments may be evaluated more than once, be careful
207 * of side-effects
208 */
209 SBuf& appendf(const char *fmt, ...);
496a9e97 210
412da427
FC
211 /** Append operation, with vsprintf(3)-style arguments.
212 * \note arguments may be evaluated more than once, be careful
213 * of side-effects
214 */
215 SBuf& vappendf(const char *fmt, va_list vargs);
216
496a9e97 217 /// print the SBuf contents to the supplied ostream
412da427
FC
218 std::ostream& print(std::ostream &os) const;
219
496a9e97 220 /** print SBuf contents and debug information about the SBuf to an ostream
412da427
FC
221 *
222 * Debug function, dumps to a stream informations on the current SBuf,
223 * including low-level details and statistics.
224 */
225 std::ostream& dump(std::ostream &os) const;
226
227 /** random-access read to any char within the SBuf
228 *
229 * does not check access bounds. If you need that, use at()
230 */
fdd1982c 231 char operator [](size_type pos) const {++stats.getChar; return store_->mem[off_+pos];}
412da427
FC
232
233 /** random-access read to any char within the SBuf.
234 *
235 * \throw OutOfBoundsException when access is out of bounds
50827187 236 * \note bounds is 0 <= pos < length(); caller must pay attention to signedness
412da427 237 */
fdd1982c 238 char at(size_type pos) const {checkAccessBounds(pos); return operator[](pos);}
412da427
FC
239
240 /** direct-access set a byte at a specified operation.
241 *
242 * \param pos the position to be overwritten
243 * \param toset the value to be written
244 * \throw OutOfBoundsException when pos is of bounds
50827187 245 * \note bounds is 0 <= pos < length(); caller must pay attention to signedness
412da427
FC
246 * \note performs a copy-on-write if needed.
247 */
248 void setAt(size_type pos, char toset);
249
250 /** compare to other SBuf, str(case)cmp-style
251 *
252 * \param isCaseSensitive one of caseSensitive or caseInsensitive
7cbd3256 253 * \param n compare up to this many bytes. if npos (default), compare whole SBufs
412da427
FC
254 * \retval >0 argument of the call is greater than called SBuf
255 * \retval <0 argument of the call is smaller than called SBuf
256 * \retval 0 argument of the call has the same contents of called SBuf
257 */
7cbd3256
FC
258 int compare(const SBuf &S, SBufCaseSensitive isCaseSensitive, size_type n = npos) const;
259
260 /// shorthand version for compare
261 inline int cmp(const SBuf &S, size_type n = npos) const {
262 return compare(S,caseSensitive,n);
263 }
264
265 /// shorthand version for case-insensitive comparison
266 inline int caseCmp(const SBuf &S, size_type n = npos) const {
267 return compare(S,caseInsensitive,n);
268 }
412da427
FC
269
270 /** check whether the entire supplied argument is a prefix of the SBuf.
271 * \param S the prefix to match against
272 * \param isCaseSensitive one of caseSensitive or caseInsensitive
273 * \retval true argument is a prefix of the SBuf
274 */
275 bool startsWith(const SBuf &S, SBufCaseSensitive isCaseSensitive = caseSensitive) const;
276
412da427
FC
277 bool operator ==(const SBuf & S) const;
278 bool operator !=(const SBuf & S) const;
7cbd3256
FC
279 bool operator <(const SBuf &S) const {return (cmp(S) < 0);}
280 bool operator >(const SBuf &S) const {return (cmp(S) > 0);}
281 bool operator <=(const SBuf &S) const {return (cmp(S) <= 0);}
282 bool operator >=(const SBuf &S) const {return (cmp(S) >= 0);}
412da427
FC
283
284 /** Consume bytes at the head of the SBuf
285 *
286 * Consume N chars at SBuf head, or to SBuf's end,
287 * whichever is shorter. If more bytes are consumed than available,
288 * the SBuf is emptied
289 * \param n how many bytes to remove; could be zero.
7cbd3256 290 * npos (or no argument) means 'to the end of SBuf'
412da427
FC
291 * \return a new SBuf containing the consumed bytes.
292 */
293 SBuf consume(size_type n = npos);
294
496a9e97 295 /// gets global statistic informations
412da427
FC
296 static const SBufStats& GetStats();
297
298 /** Copy SBuf contents into user-supplied C buffer.
299 *
300 * Export a copy of the SBuf's contents into the user-supplied
301 * buffer, up to the user-supplied-length. No zero-termination is performed
302 * \return num the number of actually-copied chars.
303 */
304 size_type copy(char *dest, size_type n) const;
305
306 /** exports a pointer to the SBuf internal storage.
307 * \warning ACCESSING RAW STORAGE IS DANGEROUS!
308 *
496a9e97
FC
309 * Returns a ead-only pointer to SBuf's content. No terminating null
310 * character is appended (use c_str() for that).
412da427
FC
311 * The returned value points to an internal location whose contents
312 * are guaranteed to remain unchanged only until the next call
313 * to a non-constant member function of the SBuf object. Such a
314 * call may be implicit (e.g., when SBuf is destroyed
315 * upon leaving the current context).
316 * This is a very UNSAFE way of accessing the data.
317 * This call never returns NULL.
318 * \see c_str
319 * \note the memory management system guarantees that the exported region
320 * of memory will remain valid if the caller keeps holding
321 * a valid reference to the SBuf object and does not write or append to
322 * it. For example:
323 * \code
324 * SBuf foo("some string");
325 * const char *bar = foo.rawContent();
326 * doSomething(bar); //safe
327 * foo.append(" other string");
328 * doSomething(bar); //unsafe
329 * \endcode
330 */
331 const char* rawContent() const;
332
333 /** Exports a writable pointer to the SBuf internal storage.
334 * \warning Use with EXTREME caution, this is a dangerous operation.
335 *
336 * Returns a pointer to the first unused byte in the SBuf's storage,
ac7947fd
FC
337 * which can be be used for appending. At least minSize bytes will
338 * be available for writing.
339 * The returned pointer must not be stored by the caller, as it will
496a9e97 340 * be invalidated by the first call to a non-const method call
412da427 341 * on the SBuf.
ac7947fd 342 * This call guarantees to never return NULL.
8aa34dad
FC
343 * \see reserveSpace
344 * \note Unlike reserveSpace(), this method does not guarantee exclusive
345 * buffer ownership. It is instead optimized for a one writer
346 * (appender), many readers scenario by avoiding unnecessary
347 * copying and allocations.
412da427
FC
348 * \throw SBufTooBigException if the user tries to allocate too big a SBuf
349 */
ac7947fd 350 char *rawSpace(size_type minSize);
412da427 351
50827187 352 /** Obtain how much free space is available in the backing store.
8aa34dad 353 *
50827187
FC
354 * \note: unless the client just cow()ed, it is not guaranteed that
355 * the free space can be used.
8aa34dad
FC
356 */
357 size_type spaceSize() const { return store_->spaceSize(); }
358
412da427
FC
359 /** Force a SBuf's size
360 * \warning use with EXTREME caution, this is a dangerous operation
361 *
362 * Adapt the SBuf internal state after external interference
363 * such as writing into it via rawSpace.
7cbd3256
FC
364 * \throw TextException if SBuf doesn't have exclusive ownership of store
365 * \throw SBufTooBigException if new size is bigger than available store space
412da427
FC
366 */
367 void forceSize(size_type newSize);
368
369 /** exports a null-terminated reference to the SBuf internal storage.
370 * \warning ACCESSING RAW STORAGE IS DANGEROUS! DO NOT EVER USE
371 * THE RETURNED POINTER FOR WRITING
372 *
373 * The returned value points to an internal location whose contents
374 * are guaranteed to remain unchanged only until the next call
375 * to a non-constant member function of the SBuf object. Such a
376 * call may be implicit (e.g., when SBuf is destroyed
377 * upon leaving the current context).
378 * This is a very UNSAFE way of accessing the data.
379 * This call never returns NULL.
380 * \see rawContent
381 * \note the memory management system guarantees that the exported region
496a9e97
FC
382 * of memory will remain valid will remain valid only if the
383 * caller keeps holding a valid reference to the SBuf object and
384 * does not write or append to it
412da427
FC
385 */
386 const char* c_str();
387
496a9e97 388 /// Returns the number of bytes stored in SBuf.
62842d40 389 size_type length() const {return len_;}
412da427
FC
390
391 /** Get the length of the SBuf, as a signed integer
392 *
393 * Compatibility function for printf(3) which requires a signed int
394 * \throw SBufTooBigException if the SBuf is too big for a signed integer
395 */
62842d40
FC
396 int plength() const {
397 if (length()>INT_MAX)
398 throw SBufTooBigException(__FILE__, __LINE__);
399 return static_cast<int>(length());
400 }
412da427
FC
401
402 /** Check whether the SBuf is empty
403 *
404 * \return true if length() == 0
405 */
62842d40 406 bool isEmpty() const {return (len_==0);}
412da427 407
8aa34dad 408 /** Request to guarantee the SBuf's free store space.
412da427
FC
409 *
410 * After the reserveSpace request, the SBuf is guaranteed to have at
7cbd3256 411 * least minSpace bytes of unused backing store following the currently
ac7947fd 412 * used portion and single ownership of the backing store.
412da427
FC
413 * \throw SBufTooBigException if the user tries to allocate too big a SBuf
414 */
e842ecce 415 void reserveSpace(size_type minSpace) {
6fd0701a 416 Must(minSpace <= maxSize);
a44b8b80 417 Must(length() <= maxSize - minSpace);
e842ecce
FC
418 reserveCapacity(length()+minSpace);
419 }
412da427 420
8aa34dad 421 /** Request to guarantee the SBuf's store capacity
412da427
FC
422 *
423 * After this method is called, the SBuf is guaranteed to have at least
7cbd3256 424 * minCapacity bytes of total buffer size, including the currently-used
577bcebc
FC
425 * portion; it is also guaranteed that after this call this SBuf
426 * has unique ownership of the underlying memory store.
412da427
FC
427 * \throw SBufTooBigException if the user tries to allocate too big a SBuf
428 */
429 void reserveCapacity(size_type minCapacity);
430
431 /** slicing method
432 *
496a9e97
FC
433 * Removes SBuf prefix and suffix, leaving a sequence of 'n'
434 * bytes starting from position 'pos', first byte is at pos 0.
435 * It is an in-place-modifying version of substr.
412da427 436 * \param pos start sub-stringing from this byte. If it is
496a9e97 437 * npos or it is greater than the SBuf length, the SBuf is cleared and
50827187 438 * an empty SBuf is returned.
412da427 439 * \param n maximum number of bytes of the resulting SBuf.
7cbd3256 440 * npos means "to end of SBuf".
496a9e97 441 * if it is 0, the SBuf is cleared and an empty SBuf is returned.
496a9e97
FC
442 * if it overflows the end of the SBuf, it is capped to the end of SBuf
443 * \see substr, trim
412da427
FC
444 */
445 SBuf& chop(size_type pos, size_type n = npos);
446
447 /** Remove characters in the toremove set at the beginning, end or both
448 *
449 * \param toremove characters to be removed. Stops chomping at the first
450 * found char not in the set
451 * \param atBeginning if true (default), strips at the beginning of the SBuf
452 * \param atEnd if true (default), strips at the end of the SBuf
453 */
454 SBuf& trim(const SBuf &toRemove, bool atBeginning = true, bool atEnd = true);
455
456 /** Extract a part of the current SBuf.
457 *
496a9e97
FC
458 * Return a fresh a fresh copy of a portion the current SBuf, which is
459 * left untouched. The same parameter convetions apply as for chop.
460 * \see trim, chop
412da427
FC
461 */
462 SBuf substr(size_type pos, size_type n = npos) const;
463
464 /** Find first occurrence of character in SBuf
465 *
466 * Returns the index in the SBuf of the first occurrence of char c.
7cbd3256 467 * \return npos if the char was not found
412da427 468 * \param startPos if specified, ignore any occurrences before that position
496a9e97 469 * if startPos is npos or greater than length() npos is always returned
7cbd3256 470 * if startPos is less than zero, it is ignored
412da427
FC
471 */
472 size_type find(char c, size_type startPos = 0) const;
473
474 /** Find first occurrence of SBuf in SBuf.
475 *
476 * Returns the index in the SBuf of the first occurrence of the
477 * sequence contained in the str argument.
478 * \param startPos if specified, ignore any occurrences before that position
496a9e97 479 * if startPos is npos or greater than length() npos is always returned
7cbd3256 480 * \return npos if the SBuf was not found
412da427
FC
481 */
482 size_type find(const SBuf & str, size_type startPos = 0) const;
483
484 /** Find last occurrence of character in SBuf
485 *
486 * Returns the index in the SBuf of the last occurrence of char c.
7cbd3256 487 * \return npos if the char was not found
412da427 488 * \param endPos if specified, ignore any occurrences after that position.
496a9e97 489 * if npos or greater than length(), the whole SBuf is considered
412da427
FC
490 */
491 size_type rfind(char c, size_type endPos = npos) const;
492
493 /** Find last occurrence of SBuf in SBuf
494 *
495 * Returns the index in the SBuf of the last occurrence of the
496 * sequence contained in the str argument.
7cbd3256 497 * \return npos if the sequence was not found
412da427 498 * \param endPos if specified, ignore any occurrences after that position
496a9e97 499 * if npos or greater than length(), the whole SBuf is considered
412da427
FC
500 */
501 size_type rfind(const SBuf &str, size_type endPos = npos) const;
502
503 /** Find first occurrence of character of set in SBuf
504 *
505 * Finds the first occurrence of ANY of the characters in the supplied set in
506 * the SBuf.
7cbd3256 507 * \return npos if no character in the set could be found
412da427 508 * \param startPos if specified, ignore any occurrences before that position
7cbd3256 509 * if npos, then npos is always returned
c8046ec7
FC
510 *
511 * TODO: rename to camelCase
412da427 512 */
810a5427 513 size_type findFirstOf(const CharacterSet &set, size_type startPos = 0) const;
3c1106a0
FC
514
515 /** Find first occurrence character NOT in character set
516 *
c8046ec7 517 * \return npos if all characters in the SBuf are from set
3c1106a0
FC
518 * \param startPos if specified, ignore any occurrences before that position
519 * if npos, then npos is always returned
c8046ec7
FC
520 *
521 * TODO: rename to camelCase
3c1106a0 522 */
810a5427 523 size_type findFirstNotOf(const CharacterSet &set, size_type startPos = 0) const;
412da427
FC
524
525 /** sscanf-alike
526 *
527 * sscanf re-implementation. Non-const, and not \0-clean.
528 * \return same as sscanf
529 * \see man sscanf(3)
530 */
531 int scanf(const char *format, ...);
532
533 /** Lower-case SBuf
534 *
535 * Returns a lower-cased COPY of the SBuf
536 * \see man tolower(3)
537 */
538 SBuf toLower() const;
539
540 /** Upper-case SBuf
541 *
542 * Returns an upper-cased COPY of the SBuf
543 * \see man toupper(3)
544 */
545 SBuf toUpper() const;
546
547 /** String export function
496a9e97
FC
548 * converts the SBuf to a legacy String, by copy.
549 * \deprecated
412da427
FC
550 */
551 String toString() const;
552
7cbd3256
FC
553 /// std::string export function
554 std::string toStdString() const { return std::string(buf(),length()); }
555
496a9e97
FC
556 // TODO: possibly implement erase() similar to std::string's erase
557 // TODO: possibly implement a replace() call
412da427
FC
558private:
559
560 MemBlob::Pointer store_; ///< memory block, possibly shared with other SBufs
561 size_type off_; ///< our content start offset from the beginning of shared store_
562 size_type len_; ///< number of our content bytes in shared store_
563 static SBufStats stats; ///< class-wide statistics
564
7cbd3256
FC
565 /// SBuf object identifier; does not change when contents do,
566 /// including during assignment
567 const InstanceId<SBuf> id;
412da427 568
62842d40
FC
569 /** obtain prototype store
570 *
571 * Just-created SBufs all share to the same MemBlob.
572 * This call instantiates and returns it.
573 */
574 static MemBlob::Pointer GetStorePrototype();
575
576 /**
577 * obtains a char* to the beginning of this SBuf in memory.
578 * \note the obtained string is NOT null-terminated.
579 */
580 char * buf() const {return (store_->mem+off_);}
581
582 /** returns the pointer to the first char after this SBuf end
583 *
584 * No checks are made that the space returned is safe, checking that is
585 * up to the caller.
586 */
587 char * bufEnd() const {return (store_->mem+off_+len_);}
588
589 /**
590 * Try to guesstimate how big a MemBlob to allocate.
591 * The result is guarranteed to be to be at least the desired size.
592 */
fdd1982c 593 size_type estimateCapacity(size_type desired) const {return (2*desired);}
412da427 594
412da427
FC
595 void reAlloc(size_type newsize);
596
a452bc8b 597 void cow(size_type minsize = npos);
412da427
FC
598
599 void checkAccessBounds(size_type pos) const;
62842d40 600
7cbd3256
FC
601 /** Low-level append operation
602 *
603 * Takes as input a contiguous area of memory and appends its contents
604 * to the SBuf, taking care of memory management. Does no bounds checking
605 * on the supplied memory buffer, it is the duty of the caller to ensure
606 * that the supplied area is valid.
607 */
608 SBuf& lowAppend(const char * memArea, size_type areaSize);
412da427
FC
609};
610
496a9e97 611/// ostream output operator
62842d40
FC
612inline std::ostream &
613operator <<(std::ostream& os, const SBuf& S)
614{
615 return S.print(os);
616}
412da427
FC
617
618#endif /* SQUID_SBUF_H */