/*
- * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#define SQUID_SBUF_H
#include "base/InstanceId.h"
+#include "base/TextException.h"
#include "Debug.h"
#include "globals.h"
-#include "sbuf/Exceptions.h"
#include "sbuf/forward.h"
#include "sbuf/MemBlob.h"
#include "sbuf/Stats.h"
#include <climits>
-#include <cstdarg>
#include <iosfwd>
#include <iterator>
#if HAVE_UNISTD_H
/** print SBuf contents and debug information about the SBuf to an ostream
*
- * Debug function, dumps to a stream informations on the current SBuf,
+ * Debug function, dumps to a stream information on the current SBuf,
* including low-level details and statistics.
*/
std::ostream& dump(std::ostream &os) const;
/** random-access read to any char within the SBuf.
*
- * \throw OutOfBoundsException when access is out of bounds
+ * \throw std::exception when access is out of bounds
* \note bounds is 0 <= pos < length(); caller must pay attention to signedness
*/
char at(size_type pos) const {checkAccessBounds(pos); return operator[](pos);}
*
* \param pos the position to be overwritten
* \param toset the value to be written
- * \throw OutOfBoundsException when pos is of bounds
+ * \throw std::exception when pos is of bounds
* \note bounds is 0 <= pos < length(); caller must pay attention to signedness
* \note performs a copy-on-write if needed.
*/
*/
SBuf consume(size_type n = npos);
- /// gets global statistic informations
+ /// gets global statistic information
static const SBufStats& GetStats();
/** Copy SBuf contents into user-supplied C buffer.
/** Get the length of the SBuf, as a signed integer
*
* Compatibility function for printf(3) which requires a signed int
- * \throw SBufTooBigException if the SBuf is too big for a signed integer
+ * \throw std::exception if buffer length does not fit a signed integer
*/
int plength() const {
- if (length()>INT_MAX)
- throw SBufTooBigException(__FILE__, __LINE__);
+ Must(length() <= INT_MAX);
return static_cast<int>(length());
}
* After the reserveSpace request, the SBuf is guaranteed to have at
* least minSpace bytes of unused backing store following the currently
* used portion and single ownership of the backing store.
- * \throw SBufTooBigException if the user tries to allocate too big a SBuf
+ * \throw std::exception if the user tries to allocate a too big SBuf
*/
void reserveSpace(size_type minSpace) {
Must(minSpace <= maxSize);
* minCapacity bytes of total buffer size, including the currently-used
* portion; it is also guaranteed that after this call this SBuf
* has unique ownership of the underlying memory store.
- * \throw SBufTooBigException if the user tries to allocate too big a SBuf
+ * \throw std::exception if the user tries to allocate a too big SBuf
*/
void reserveCapacity(size_type minCapacity);
/**
* Try to guesstimate how big a MemBlob to allocate.
- * The result is guarranteed to be to be at least the desired size.
+ * The result is guaranteed to be to be at least the desired size.
*/
size_type estimateCapacity(size_type desired) const {return (2*desired);}
void cow(size_type minsize = npos);
- void checkAccessBounds(size_type pos) const;
+ void checkAccessBounds(const size_type pos) const { Must(pos < length()); }
/** Exports a writable pointer to the SBuf internal storage.
* \warning Use with EXTREME caution, this is a dangerous operation.
* buffer ownership. It is instead optimized for a one writer
* (appender), many readers scenario by avoiding unnecessary
* copying and allocations.
- * \throw SBufTooBigException if the user tries to allocate too big a SBuf
+ * \throw std::exception if the user tries to allocate a too big SBuf
*/
char *rawSpace(size_type minSize);