⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 straccum.hh

📁 Click is a modular router toolkit. To use it you ll need to know how to compile and install the sof
💻 HH
📖 第 1 页 / 共 2 页
字号:
    /** @brief Append the data from @a begin to @a end to the end of this     * StringAccum.     *     * Does nothing if @a begin >= @a end. */    inline void append(const char *begin, const char *end) {	if (begin < end)	    append_data(begin, end - begin);	else if (begin == String::out_of_memory_data())	    assign_out_of_memory();    }    /** @brief Append string representation of @a x to this StringAccum.     * @param x number to append     * @param base numeric base: must be 8, 10, or 16     * @param uppercase true means use uppercase letters in base 16 */    void append_numeric(String::int_large_t x, int base = 10, bool uppercase = true);    /** @overload */    void append_numeric(String::uint_large_t x, int base = 10, bool uppercase = true);    /** @brief Append result of snprintf() to this StringAccum.     * @param n maximum number of characters to print     * @param format format argument to snprintf()     *     * The terminating null character is not appended to the string.     *     * @note The safe vsnprintf() variant is called if it exists.  It does in     * the Linux kernel, and on modern Unix variants.  However, if it does not     * exist on your machine, then this function is actually unsafe, and you     * should make sure that the printf() invocation represented by your     * arguments will never write more than @a n characters, not including the     * terminating null. */    StringAccum &snprintf(int n, const char *format, ...) CLICK_SNPRINTF_ATTR;    /** @brief Return a String object with this StringAccum's contents.     *     * This operation donates the StringAccum's memory to the returned String.     * After a call to take_string(), the StringAccum object becomes empty,     * and any future append() operations may cause memory allocations.  If     * the StringAccum is out-of-memory, the returned String is also     * out-of-memory, but the StringAccum's out-of-memory state is reset. */    String take_string();    /** @brief Assign this StringAccum to @a x. */    StringAccum &operator=(const StringAccum &x) {	if (&x != this) {	    if (out_of_memory())		_s = 0, _cap = 0;	    _len = 0;	    append(x.data(), x.length());	}	return *this;    }    /** @brief Swap this StringAccum's contents with @a x. */    void swap(StringAccum &x);    // see also operator<< declarations below    /** @cond never */    /** @brief Adjust the StringAccum's length (deprecated).     * @param delta length adjustment     * @deprecated Use adjust_length() instead. */    inline void forward(int delta) CLICK_DEPRECATED;    /** @endcond never */  private:    unsigned char *_s;    int _len;    int _cap;    bool grow(int);    void assign_out_of_memory();    inline void append_safe_data(const char *s, int len) {	if (char *x = extend(len))	    memcpy(x, s, len);    }    void append_unsafe_data(const char *s, int len);    inline void append_data(const char *s, int len) {	const char *my_s = reinterpret_cast<char *>(_s);	if (likely(!(s >= my_s && s + len <= my_s + _len)		   || len == 0 || _len + len <= _cap))	    append_safe_data(s, len);	else	    append_unsafe_data(s, len);    }    friend StringAccum &operator<<(StringAccum &sa, const char *s);#if HAVE_PERMSTRING    friend StringAccum &operator<<(StringAccum &sa, PermString s);#endif};inline StringAccum &operator<<(StringAccum &, char);inline StringAccum &operator<<(StringAccum &, unsigned char);inline StringAccum &operator<<(StringAccum &, const char *);inline StringAccum &operator<<(StringAccum &, const String &);inline StringAccum &operator<<(StringAccum &, const StringAccum &);#ifdef HAVE_PERMSTRINGinline StringAccum &operator<<(StringAccum &, PermString);#endifinline StringAccum &operator<<(StringAccum &, bool);inline StringAccum &operator<<(StringAccum &, short);inline StringAccum &operator<<(StringAccum &, unsigned short);inline StringAccum &operator<<(StringAccum &, int);inline StringAccum &operator<<(StringAccum &, unsigned);StringAccum &operator<<(StringAccum &, long);StringAccum &operator<<(StringAccum &, unsigned long);#if HAVE_LONG_LONGinline StringAccum &operator<<(StringAccum &, long long);inline StringAccum &operator<<(StringAccum &, unsigned long long);#endif#if HAVE_INT64_TYPES && !HAVE_INT64_IS_LONG && !HAVE_INT64_IS_LONG_LONGinline StringAccum &operator<<(StringAccum &, int64_t);inline StringAccum &operator<<(StringAccum &, uint64_t);#endif#if defined(CLICK_USERLEVEL) || defined(CLICK_TOOL)StringAccum &operator<<(StringAccum &, double);#endifStringAccum &operator<<(StringAccum &, void *);inlineStringAccum::StringAccum(int capacity)    : _len(0){    assert(capacity >= 0);    if (capacity) {	_s = (unsigned char *) CLICK_LALLOC(capacity);	_cap = (_s ? capacity : -1);    } else {	_s = 0;	_cap = 0;    }}/** @cond never */inline void StringAccum::forward(int delta) {    adjust_length(delta);}/** @endcond never *//** @relates StringAccum    @brief Append character @a c to StringAccum @a sa.    @return @a sa    @note Same as @a sa.append(@a c). */inline StringAccum &operator<<(StringAccum &sa, char c){    sa.append(c);    return sa;}/** @relates StringAccum    @brief Append character @a c to StringAccum @a sa.    @return @a sa    @note Same as @a sa.append(@a c). */inline StringAccum &operator<<(StringAccum &sa, unsigned char c){    sa.append(c);    return sa;}/** @relates StringAccum    @brief Append null-terminated C string @a cstr to StringAccum @a sa.    @return @a sa    @note Same as @a sa.append(@a cstr, -1). */inline StringAccum &operator<<(StringAccum &sa, const char *cstr){    sa.append(cstr, -1);    return sa;}/** @relates StringAccum    @brief Append "true" or "false" to @a sa, depending on @a b.    @return @a sa */inline StringAccum &operator<<(StringAccum &sa, bool b){    return sa << (b ? "true" : "false");}/** @relates StringAccum    @brief Append decimal representation of @a i to @a sa.    @return @a sa */inline StringAccum &operator<<(StringAccum &sa, short i){    return sa << static_cast<long>(i);}/** @relates StringAccum    @brief Append decimal representation of @a u to @a sa.    @return @a sa */inline StringAccum &operator<<(StringAccum &sa, unsigned short u){    return sa << static_cast<unsigned long>(u);}/** @relates StringAccum    @brief Append decimal representation of @a i to @a sa.    @return @a sa */inline StringAccum &operator<<(StringAccum &sa, int i){    return sa << static_cast<long>(i);}/** @relates StringAccum    @brief Append decimal representation of @a u to @a sa.    @return @a sa */inline StringAccum &operator<<(StringAccum &sa, unsigned u){    return sa << static_cast<unsigned long>(u);}#if HAVE_LONG_LONG/** @relates StringAccum    @brief Append decimal representation of @a q to @a sa.    @return @a sa */inline StringAccum &operator<<(StringAccum &sa, long long q){    sa.append_numeric(static_cast<String::int_large_t>(q));    return sa;}/** @relates StringAccum    @brief Append decimal representation of @a q to @a sa.    @return @a sa */inline StringAccum &operator<<(StringAccum &sa, unsigned long long q){    sa.append_numeric(static_cast<String::uint_large_t>(q));    return sa;}#endif#if HAVE_INT64_TYPES && !HAVE_INT64_IS_LONG && !HAVE_INT64_IS_LONG_LONG/** @relates StringAccum    @brief Append decimal representation of @a q to @a sa.    @return @a sa */inline StringAccum &operator<<(StringAccum &sa, int64_t q){    sa.append_numeric(static_cast<String::int_large_t>(q));    return sa;}/** @relates StringAccum    @brief Append decimal representation of @a q to @a sa.    @return @a sa */inline StringAccum &operator<<(StringAccum &sa, uint64_t q){    sa.append_numeric(static_cast<String::uint_large_t>(q));    return sa;}#endif/** @relates StringAccum    @brief Append the contents of @a str to @a sa.    @return @a sa */StringAccum &operator<<(StringAccum &sa, const String &str){    sa.append(str.begin(), str.end());    return sa;}#if HAVE_PERMSTRINGinline StringAccum &operator<<(StringAccum &sa, PermString s){    sa.append_safe_data(s.c_str(), s.length());    return sa;}#endif/** @relates StringAccum    @brief Append the contents of @a sb to @a sa.    @return @a sa */inline StringAccum &operator<<(StringAccum &sa, const StringAccum &sb){    sa.append(sb.begin(), sb.end());    return sa;}#undef CLICK_SNPRINTF_ATTRCLICK_ENDDECLS#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -