//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: Sanjay Ghemawat
//
// A string like object that points into another piece of memory.
// Useful for providing an interface that allows clients to easily
// pass in either a "const char*" or a "string".
//
// Arghh! I wish C++ literals were automatically of type "string".
#ifndef MUDUO_BASE_STRINGPIECE_H
#define MUDUO_BASE_STRINGPIECE_H
#include <string.h>
#include <iosfwd> // for ostream forward-declaration
#include <muduo/base/Types.h>
#ifndef MUDUO_STD_STRING
#include <string>
#endif
namespace muduo {
class StringPiece {
private:
const char* ptr_;
int length_;
public:
// We provide non-explicit singleton constructors so users can pass
// in a "const char*" or a "string" wherever a "StringPiece" is
// expected.
StringPiece()
: ptr_(NULL), length_(0) { }
StringPiece(const char* str)
: ptr_(str), length_(static_cast<int>(strlen(ptr_))) { }
StringPiece(const unsigned char* str)
: ptr_(reinterpret_cast<const char*>(str)),
length_(static_cast<int>(strlen(ptr_))) { }
StringPiece(const string& str)
: ptr_(str.data()), length_(static_cast<int>(str.size())) { }
#ifndef MUDUO_STD_STRING
StringPiece(const std::string& str)
: ptr_(str.data()), length_(static_cast<int>(str.size())) { }
#endif
StringPiece(const char* offset, int len)
: ptr_(offset), length_(len) { }
// data() may return a pointer to a buffer with embedded NULs, and the
// returned buffer may or may not be null terminated. Therefore it is
// typically a mistake to pass data() to a routine that expects a NUL
// terminated string. Use "as_string().c_str()" if you really need to do
// this. Or better yet, change your routine so it does not rely on NUL
// termination.
const char* data() const { return ptr_; }
int size() const { return length_; }
bool empty() const { return length_ == 0; }
void clear() { ptr_ = NULL; length_ = 0; }
void set(const char* buffer, int len) { ptr_ = buffer; length_ = len; }
void set(const char* str) {
ptr_ = str;
length_ = static_cast<int>(strlen(str));
}
void set(const void* buffer, int len) {
ptr_ = reinterpret_cast<const char*>(buffer);
length_ = len;
}
char operator[](int i) const { return ptr_[i]; }
void remove_prefix(int n) {
ptr_ += n;
length_ -= n;
}
void remove_suffix(int n) {
length_ -= n;
}
bool operator==(const StringPiece& x) const {
return ((length_ == x.length_) &&
(memcmp(ptr_, x.ptr_, length_) == 0));
}
bool operator!=(const StringPiece& x) const {
return !(*this == x);
}
#define STRINGPIECE_BINARY_PREDICATE(cmp,auxcmp) \
bool operator cmp (const StringPiece& x) const { \
int r = memcmp(ptr_, x.ptr_, length_ < x.length_ ? length_ : x.length_); \
return ((r auxcmp 0) || ((r == 0) && (length_ cmp x.length_))); \
}
STRINGPIECE_BINARY_PREDICATE(<, <);
STRINGPIECE_BINARY_PREDICATE(<=, <);
STRINGPIECE_BINARY_PREDICATE(>=, >);
STRINGPIECE_BINARY_PREDICATE(>, >);
#undef STRINGPIECE_BINARY_PREDICATE
int compare(const StringPiece& x) const {
int r = memcmp(ptr_, x.ptr_, length_ < x.length_ ? length_ : x.length_);
if (r == 0) {
if (length_ < x.length_) r = -1;
else if (length_ > x.length_) r = +1;
}
return r;
}
string as_string() const {
return string(data(), size());
}
void CopyToString(string* target) const {
target->assign(ptr_, length_);
}
#ifndef MUDUO_STD_STRING
void CopyToStdString(std::string* target) const {
target->assign(ptr_, length_);
}
#endif
// Does "this" start with "x"
bool starts_with(const StringPiece& x) const {
return ((length_ >= x.length_) && (memcmp(ptr_, x.ptr_, x.length_) == 0));
}
};
} // namespace muduo
// ------------------------------------------------------------------
// Functions used to create STL containers that use StringPiece
// Remember that a StringPiece's lifetime had better be less than
// that of the underlying string or char*. If it is not, then you
// cannot safely store a StringPiece into an STL container
// ------------------------------------------------------------------
#ifdef HAVE_TYPE_TRAITS
// This makes vector<StringPiece> really fast for some STL implementations
template<> struct __type_traits<muduo::StringPiece> {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
typedef __true_type has_trivial_destructor;
typedef __true_type is_POD_type;
};
#endif
// allow StringPiece to be logged
std::ostream& operator<<(std::ostream& o, const muduo::StringPiece& piece);
#endif // MUDUO_BASE_STRINGPIECE_H
相关推荐
用Verilog搭出RISC-V架构单周期CPU
这是笔者学校暑期学期的必修课,难度并不高(仅追求及格的话),但相当耗时,对于在硬件设计方面完全不感冒的同学更是一场避不开的折磨,所以笔者想通过自己的成果和被折磨经验来帮助有此方面需求的同学,或是对于CPU设计有浓厚兴趣的人。
漫话Redis源码之五十一
/* * Copyright (c) 2018, Salvatore Sanfilippo <antirez at gmail dot com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are ...
TCP协议中ARQ自动重传的三种实现方式对比(含SACK详解)
本文深入解析TCP协议中ARQ自动重传的三种实现方式,包括停止-等待、回退N步和选择重传协议,特别详细介绍了SACK机制的工作原理和优势。通过对比分析各协议的效率、复杂度和适用场景,为网络通信中的可靠性传输提供了实用的选型指南。
yara 源码学习(二) 规则编译部分
yara源码分析
9 HAL库驱动框架简述(STM32HAL库)
HAL库外设的使用步骤总结如下:1、定义并填充xxx外设句柄结构体。2、如果遵循HAL库规范,通过HAL_xxx_MspInit()函数,实现外设底层资源的初始化,包括但不限于GPIO、时钟、DMA、中断等资源的初始化。3、调用HAL库的对应外设初始化函数,形如:HAL_xxx_Init()。4、初始化完成,开始使用外设。5、使用方法具体查看对应外设的HAL库驱动包中的说明:补充:HAL库使用主线外设初始化外设使用。
基于verilog的16QAM调制
思路1:正交调幅法——实现16QAM调制,可以理解为时相位相差90度的两个正弦波的4PAM叠加。 4比特输入经过2->4进制转化得到两路2比特输入,然后分别经过4PAM后叠加所得输出即为16QAM调制结果。 具体程序稍后编写。 思路2:复合相移法——可以借助前面编写的QPSK,相当于两路幅度不同的QPSK的叠加,比如幅度分别取1和3 。 思路1正交调幅法的设计方案: 两正弦波相位差...
漫话Redis源码之四十八
/* * Copyright (c) 2000-2010 Marc Alexander Lehmann <schmorp@schmorp.de> * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: * * 1. Redis...
为什么你的SiC MOSFET仿真不准?可能是离子注入的‘沟道效应’在捣鬼(Silvaco BCA模块详解)
本文深入分析了SiC MOSFET仿真中离子注入沟道效应的关键影响,揭示了Silvaco BCA模块在模拟SiC晶向和角度参数时的核心设置要点。通过详细解析晶圆偏切与注入角度的等效关系,提供优化MOSFET沟道区注入仿真的五步实战方法,帮助工程师将阈值电压仿真误差从26%降低到5%以内。
漫话Redis源码之五十
/* * Copyright (c) 2018, Salvatore Sanfilippo <antirez at gmail dot com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are ...
Isaac Sim仿真平台学习(2)系统架构
isaac sim系统架构
DeepSeek如何构建可扩展的 AI 驱动交易系统,基于 MetaTrader 5 与 Python 利用先进的数据处理、机器学习和容器化部署来优化算法交易。
MT5 Python API 架构设计分为三层:通信层:利用异步消息传递(例如 ZeroMQ 或标准套接字编程)支持每秒数万个数据请求。转换层: C++ 动态库有效地将 MT5 命令转换为 Python 对象(反之亦然),从而优化速度和内存使用率。接口层:提供Pythonic API,封装了所有终端功能,包括:1)实时价格订阅(滴答或秒级更新)2)历史数据检索(从M1到更高的时间范围)3)订单流监控(交易详情和市场深度)4)策略执行引擎(用于算法交易)
BSD许可证的条款
<!--google_ad_client = "pub-3254020074528490";/* 728x90, 创建于 08-7-28 */google_ad_slot = "4707384325";google_ad_width = 728;google_ad_height = 90;//-->英文:* Copyright (c) 1982, 1
30天入门 SAP BTP 开发系列之十四: 将 SAP Business Application Studio 里开发好的 Node.js 应用部署到 Cloud Foundry 环境中
本教程详细介绍了如何将SAP Business Application Studio中的Node.js应用部署到Cloud Foundry环境。在完成本地开发和测试后,通过cf login命令连接Cloud Foundry环境,配置manifest.yml文件指定应用参数和路由信息。使用cf push命令完成应用的上传和部署,最终使应用运行在SAP BTP的云端环境中。教程包含从路由创建到部署验证的完整流程,确保开发者能够成功将Node.js应用发布到生产环境。
traits
2014-08-24 星期日 20:47:29 traits简而言之就是型别+偏特化 先给出只有型别的 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
IEM模型,地表粗糙度模拟
利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟
jre9下载 jdk9
(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】
有关C++ Traits编程技法
真是不得不佩服C++知识内容的庞大,最近在啃侯捷的《STL源码剖析》这本书,看到第三章迭代器知识有关 traits 的部分一脸蒙蔽,无奈只能向度娘寻求帮助。C++ STL 泛化,全特化,偏特化。模板的特化和偏特化以及相关理解。关于模板的泛化、全特化和偏特化。C++模板之特化与偏特化详解。C++模板的全特化和偏特化。C++模板全特化、偏特化。C++模板的特化详解。模板的全特化和偏特化。
IDEA的使用指南
IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.
细说 C++ Traits Classes
本文转载自 leehao.me https://blog.youkuaiyun.com/lihao21/article/details/55043881,感谢原作者的讲解。 最近在看侯捷的《STL源码剖析》,看到第三章有关 traits 的介绍,被搞得一头雾水,看了半天不知所云。为了彻底了解这个技法的原理,硬着头皮上网查了资料,并结合 Scott Meyers 的 《Effective C++》,总算是把 ...
android 蓝牙通讯demo
android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。
详解PHP中的Traits
PHP是单继承的语言,在PHP 5.4 Traits出现之前,PHP的类无法同时从两个基类继承属性或方法。php的Traits和Go语言的组合功能类似,通过在类中使用use关键字声明要组合的Trait名称,而具体某个Trait的声明使用trait关键词,Trait不能直接实例化。具体用法请看下面的代码: ? 1 2 3 4 5 6 7 8 9 10
python安装VTK、traits、mayavi
1.下载安装包 下载和自己平台匹配的安装包,比如笔者的python是3.8,于是从官网下载了 VTK-8.2.0-cp38-cp38-win_amd64.whl traits-6.3.2-cp38-cp38-win_amd64.whl mayavi-4.7.1+vtk82-cp38-cp38-win_amd64.whl 注释:cp38指的是python3.8,安装mayavi前需要安装vtk,要注意版本的对应关系 下载时,有个小技巧。在网页上ctrl+F,然后输入vtk等,查找定位到安装包的下载链接。
SIMD Traits.h
对于相等比较等按位操作,符号不影响正确性。3. unsigned_simd_friendly_equivalent_scalar_t 把整数、枚举和指针统一成等宽无符号整数。后面的类型别名会先使用 std::remove_const_t<T>,因此普通的顶层 const 会被移除后再传入。simd_friendly_equivalent_scalar_t<MyStruct> // 替换失败。simd_friendly_equivalent_scalar_t<int> // 有效。
stl 中的type traits
原文地址:中的type traits">stl 中的type traits作者:fengshao5411 【转】《STL源码剖析》学习笔记2——神奇的__type_traits 已有 82 次阅读 2009-12-21 11:10 http://blog.youkuaiyun.com/lonelywinter340/archive/2008/11/15/3297892.aspx 在STL中为了提供通用的操作
Day23-Type Traits 深度:从原理到手写实战
C++进阶计划 · Day 23 | 预计学习时长:2小时。
C++ traits技法的一点理解
为了更好的理解traits技法。我们一步一步的深入。先从实际写代码的过程中我们遇到诸如下面伪码说起。 1 template< typename T,typename B> 2 void (T a,B c){ 3 if(变量a 属于类型b){ 4 //执行相应的代码 5 a+=c; 6 } else if(变量a 属于类型c){ ...
【Rust日报】2023-12-21 宣布在 traits 中支持 async fn 和返回位置上的 impl Trait
Rust 官方博客 - 宣布在 traits 中支持async fn和返回位置上的impl TraitRust 官方博客在最新的文章中宣布了一项重要进展:支持在 traits 中使用async fn和返回位置上的impl Trait。这一功能将在 Rust 1.75 版本中正式发布,该 stable 版本将于下周发布。下面是一个混合async fn和-> impl Trai...
STL Traits编程技法
traits编程技法大量运用于STL实现中。通过它在一定程度上弥补了C++不是强型别语言的遗憾,增强了C++关于型别认证方面的能力。 traits编程技法是利用“内嵌型别”的编程技法和编译器的template参数推导功能实现的。 iterator_traits 1.对于class type要求其“内嵌型别” 要求与STL兼容的容器,其迭代器必须定义一下五种型别: it...
1万+



被折叠的 条评论
为什么被折叠?



