各种小功能集二

2023-05-16

各种小功能集一

十一、C/C++路径解析

头文件

std::string UtilsGetPath(const char *pszFilename);
std::string UtilsGetDirname(const char *pszFilename);
std::string UtilsGetFilename(const char *pszFullFilename);
std::string UtilsGetBasename(const char *pszFullFilename);
std::string UtilsGetExtension(const char *pszFullFilename);

源文件:使用案例如注释

/************************************************************************/
/*                        UtilsFindFilenameStart()                        */
/************************************************************************/

static int UtilsFindFilenameStart(const char * pszFilename)

{
	size_t iFileStart = strlen(pszFilename);

	for (;
		iFileStart > 0
		&& pszFilename[iFileStart - 1] != '/'
		&& pszFilename[iFileStart - 1] != '\\';
		iFileStart--) {
	}

	return static_cast<int>(iFileStart);
}


/************************************************************************/
/*                             UtilsGetPath()                             */
/************************************************************************/

/**
 * Extract directory path portion of filename.
 *
 * Returns a string containing the directory path portion of the passed
 * filename.  If there is no path in the passed filename an empty string
 * will be returned (not NULL).
 *
 * <pre>
 * UtilsGetPath( "abc/def.xyz" ) == "abc"
 * UtilsGetPath( "/abc/def/" ) == "/abc/def"
 * UtilsGetPath( "/" ) == "/"
 * UtilsGetPath( "/abc/def" ) == "/abc"
 * UtilsGetPath( "abc" ) == ""
 * </pre>
 *
 * @param pszFilename the filename potentially including a path.
 *
 *  @return Path in an internal string which must not be freed.  The string
 * may be destroyed by the next CPL filename handling call.  The returned
 * will generally not contain a trailing path separator.
 */
std::string UtilsGetPath(const char *pszFilename)
{
	const int iFileStart = UtilsFindFilenameStart(pszFilename);
	if (iFileStart == 0) return "";
	return std::string(pszFilename, pszFilename + iFileStart - 1);
}


/************************************************************************/
/*                             UtilsGetDirname()                          */
/************************************************************************/

/**
 * Extract directory path portion of filename.
 *
 * Returns a string containing the directory path portion of the passed
 * filename.  If there is no path in the passed filename the dot will be
 * returned.  It is the only difference from UtilsGetPath().
 *
 * <pre>
 * UtilsGetDirname( "abc/def.xyz" ) == "abc"
 * UtilsGetDirname( "/abc/def/" ) == "/abc/def"
 * UtilsGetDirname( "/" ) == "/"
 * UtilsGetDirname( "/abc/def" ) == "/abc"
 * UtilsGetDirname( "abc" ) == "."
 * </pre>
 *
 * @param pszFilename the filename potentially including a path.
 *
 * @return Path in an internal string which must not be freed.  The string
 * may be destroyed by the next CPL filename handling call.  The returned
 * will generally not contain a trailing path separator.
 */
std::string UtilsGetDirname(const char *pszFilename)
{
	const int iFileStart = UtilsFindFilenameStart(pszFilename);
	if (iFileStart == 0) return ".";
	return std::string(pszFilename, pszFilename + iFileStart - 1);
}


/************************************************************************/
/*                           UtilsGetFilename()                           */
/************************************************************************/

/**
 * Extract non-directory portion of filename.
 *
 * Returns a string containing the bare filename portion of the passed
 * filename.  If there is no filename (passed value ends in trailing directory
 * separator) an empty string is returned.
 *
 * <pre>
 * UtilsGetFilename( "abc/def.xyz" ) == "def.xyz"
 * UtilsGetFilename( "/abc/def/" ) == ""
 * UtilsGetFilename( "abc/def" ) == "def"
 * </pre>
 *
 * @param pszFullFilename the full filename potentially including a path.
 *
 * @return just the non-directory portion of the path (points back into
 * original string).
 */

std::string UtilsGetFilename(const char *pszFullFilename)
{
	const int iLen = static_cast<int>(strlen(pszFullFilename));
	const int iFileStart = UtilsFindFilenameStart(pszFullFilename);
	return std::string(pszFullFilename + iFileStart, pszFullFilename + iLen);
}

/************************************************************************/
/*                           UtilsGetBasename()                           */
/************************************************************************/

/**
 * Extract basename (non-directory, non-extension) portion of filename.
 *
 * Returns a string containing the file basename portion of the passed
 * name.  If there is no basename (passed value ends in trailing directory
 * separator, or filename starts with a dot) an empty string is returned.
 *
 * <pre>
 * UtilsGetBasename( "abc/def.xyz" ) == "def"
 * UtilsGetBasename( "abc/def" ) == "def"
 * UtilsGetBasename( "abc/def/" ) == ""
 * </pre>
 *
 * @param pszFullFilename the full filename potentially including a path.
 *
 * @return just the non-directory, non-extension portion of the path in
 * an internal string which must not be freed.  The string
 * may be destroyed by the next CPL filename handling call.
 */

std::string UtilsGetBasename(const char *pszFullFilename)
{
	const size_t iFileStart = static_cast<size_t>(UtilsFindFilenameStart(pszFullFilename));
	size_t iExtStart = strlen(pszFullFilename);
	for (;
		iExtStart > iFileStart && pszFullFilename[iExtStart] != '.';
		iExtStart--) {
	}
	if (iExtStart == iFileStart) iExtStart = strlen(pszFullFilename);
	return std::string(pszFullFilename + static_cast<int>(iFileStart),
		pszFullFilename + static_cast<int>(iExtStart));
}


/************************************************************************/
/*                           UtilsGetExtension()                          */
/************************************************************************/

/**
 * Extract filename extension from full filename.
 *
 * Returns a string containing the extension portion of the passed
 * name.  If there is no extension (the filename has no dot) an empty string
 * is returned.  The returned extension will not include the period.
 *
 * <pre>
 * UtilsGetExtension( "abc/def.xyz" ) == "xyz"
 * UtilsGetExtension( "abc/def" ) == ""
 * </pre>
 *
 * @param pszFullFilename the full filename potentially including a path.
 *
 * @return just the extension portion of the path in
 * an internal string which must not be freed.  The string
 * may be destroyed by the next CPL filename handling call.
 */
std::string UtilsGetExtension(const char *pszFullFilename)
{
	if (pszFullFilename[0] == '\0') return "";
	size_t iFileStart = static_cast<size_t>(UtilsFindFilenameStart(pszFullFilename));
	size_t sLen = strlen(pszFullFilename);
	size_t iExtStart = strlen(pszFullFilename);
	for (;
		iExtStart > iFileStart && pszFullFilename[iExtStart] != '.';
		iExtStart--) {
	}
	if (iExtStart == iFileStart)
		return "";
	// If the extension is too long, it is very much likely not an extension,
	// but another component of the path
	const size_t knMaxExtensionSize = 10;
	if (sLen - iExtStart > knMaxExtensionSize) {
		return "";
	}
	return std::string(iExtStart + 1 + pszFullFilename, pszFullFilename + sLen);
}

十二、c++开发时总结

        1.单参数的构造函数(除去有默认参数,还有不带默认参数1的也是)要加上 explicit 关键字。

表明该构造函数是显示的, 而非隐式的。

        2.如果定义的类申请了堆内存,那么建议添加深拷贝构造函数。(默认拷贝构造函数是浅拷贝,在隐藏的拷贝中容易造成内存泄漏)

        3.一个人有做基类的情况时,同时该类申请了堆内存,那么该类的析构函数应该加上virtual关键字。(基类指针指向派生类delete时,派生类部分部分清除造成内存泄漏)

        4.基类中即将被重写的函数添加virtual,是一条应该遵守的编码习惯。(虚基类可以解决二义性的问题 )

多继承和多重继承二义性的解决方法(第5、第6、第7点):

        5.在有可能出现多层继承时,应该使用虚继承基类(保证基类只会调用一次);

        6.子类访问父类成员数据可以指定父类名;

        7.子类访问父类方法可以指定父类名或者重写方法再调用父类方法;

        8.虚函数和虚基类在调用的时候是没有问题的,但是在delete的时候会发生堆报错。(delete的内存地址与new的内存地址不同,所以会造成问题,详情)

        9.如果存在继承,调用基类方法或成员变量时建议用类名注明作用域。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

各种小功能集二 的相关文章

  • pytorch 半精度训练

    必坑记录 这种训练直接变成nan了结果 实验结果 前者采用正常训练 后者改进为 from torch cuda amp import autocast as autocast 实验发现从一epoch44秒 xff0c 减少为35秒 但是训练
  • earth mover‘s distances学习记录

    https zhuanlan zhihu com p 145739750 后面的感觉没讲清楚 一开始我没想清楚 xff0c 为什么可以把问题转换成线性规划问题 问题转换一下 xff0c 一个工厂有A xff0c B xff0c C三个仓库
  • A Tutorial on Energy-Based Learning(机器学习能量模型)学习记录

    1 Introduction 其中Y是标签 X是输入 基于能量的机器学习模型即是寻找这样一个函数 和输入数据越接近 能量越小 给定一个输入 最好的模型即是对应的Y的值是真实值 这个真实值的能量是最小的 此模型可以做的工作有 预测 Ranki
  • dncnn(残差网络图像去燥记录)

    一 xff0c 生成训练数据 1 xff0c 原文相关知识 we use the noisy images from a wide range of noise levels e g 0 55 to train a single DnCNN
  • win10 10016自动重启错误解决记录

    1 xff0c 没解决 1352127440 xff0c 找到 组件服务 xff0c 然后依次展开组件服务 计算机 我的电脑 DCOM配置 xff0c 找到 9CA88EE3 ACB7 47C8 AFC4 AB702511C276 xff0
  • 无偏估计、有效性、相合性

    定义 xff1a 在已知概率分布函数构造的情况下 xff0c 概率分布的一些参数未知 xff0c 如高斯分布的namda 方差 xff0c 而利用采集到的参数来对未知参数进行估计就是参数估计 比较基础的有矩估计 最大似然估计 而不同的方法对
  • Windows10下安装point-cloud-annotation-tool点云标注工具——吐血之路总结

    零 为了标注点云数据 xff0c 经过多方查找免费开源的标注软件 xff0c 根据使用要求和方便程度最终选择了这款可以在Windows下编译安装的point cloud annotation tool xff0c 基于QT和vtk和PCL进
  • ROS 中CompressedImage消息的发布与订阅

    背景 xff1a 某些情况下需要录图像数据的包 xff0c 非常占空间和带宽 xff0c 尤其对于一些工业相机图像一张好几兆 xff0c 每秒30帧的话一份钟好几个G xff0c 这时候可以选择的订阅压缩图像 xff0c 下面直接来个dem
  • 【C#】简单的串口发送

    一 核心代码 xff1a SerialPort serialPort span class token operator 61 span span class token keyword new span span class token
  • 原生OKHttp以及OKHttpUtil的使用

    Android系统提供了两种HTTP通信类 xff0c HttpURLConnection和HttpClient 尽管Google在大部分安卓版本中推荐使用HttpURLConnection xff0c 但是这个类相比HttpClient实
  • c++编译器配置错误问题clang: error: linker command failed with exit code 1 (use -v to see invocation)

    背景 xff1a ubuntu18 04系统 之前装其他程序的时候安装了一些软件 xff0c 不知道什么时候g 43 43 编译器从 usr bin c 43 43 组里面给删掉了 xff0c 默认的编译器成了clang 43 43 xff
  • apollo7.0------浅谈激光雷达运动补偿(二)--计算解析

    背景介绍 运动补偿相关介绍参考第一篇博客 xff1a apollo7 0 浅谈激光雷达运动补偿 龙性的腾飞的博客 CSDN博客 lidar运动补偿 本篇博客主要解释一下上篇博客中运动补偿的计算部分 xff0c 简单来说就是一个利用四元数球面
  • Matlab激光雷达相机联合标定经验分享

    一 背景介绍 联合标定是做多传感器融合的基础工作 xff0c 也是一个没有最好只有更好的研究方向 xff0c 相关论文也是层出不穷 xff0c 网上也有许多开源的工作 xff0c 包括Autoware的工具箱我也试过 xff0c 感觉标定效
  • 如何更改Ubuntu系统的输出为HDMI(耳机,扬声器)?

    由于需要用HDMI外接音频设备 xff0c 故想要改变电脑输出 xff0c 本人用的为Ubuntu14 04 开始在网上搜寻怎么更改 xff0c 查到需在声音设置里面更改音频输出为HDMI xff0c 可当我打开声音设置 xff0c 嗯 x
  • PPT中插入图片背景透明化小技巧

    新版的编辑器真不适应 xff0c 费劲 xff01 xff01 xff01 最近两天做开题答辩ppt xff0c 发现了ppt中处理图片背景的一个小技巧 xff0c 在此分享给大家 PPT一般会带有背景图片 xff0c 那种带浅色调logo
  • ROS发布Float32MultiArray消息C++/Python

    在ros下发布一个字符串消息或整数消息 xff0c 网上例程不少 xff0c ROSwiki上也有教程 xff0c 有时就需要一次发送不止一个数据 xff0c 这时候就得用到数组了 xff0c C 43 43 的也好找 xff0c 不过py
  • c++中string、char *、char[]相互转换

    一 string转char 主要有三种方法可以将str转换为char 类型 xff0c 分别是 xff1a data c str copy 其中 xff0c copy 可能会报安全性错误 xff0c 自行解决即可 3 1 data 方法 s
  • char数组与char指针

    转载来源 xff1a https www cnblogs com nzbbody p 3553222 html https blog csdn net jack 20 article details 78913202 一 0 的添加 存在的
  • linux下tcpdump的使用

    简介 用简单的话来定义tcpdump xff0c 就是 xff1a dump the traffic on a network xff0c 根据使用者的定义对网络上的数据包进行截获的包分析工具 tcpdump可以将网络中传送的数据包的 头
  • khadas vim3安装ros1

    khadas vim3 按照网上的方法可以正常安装ros2 xff0c 但是按照ros1则可能会有一些奇奇怪怪的问题导致按照失败 xff0c 不过在一位群友的帮助下 xff0c 找到了解决的方法 khadas vim3 将源换为下面 xff

随机推荐

  • 【Android】CMake添加多个c文件

    1 准备工作 先下相关的插件 xff0c 进入setting xff0c 勾选这LLDB NDK CMake三个 xff0c 点击OK后即可下载 2 Native C 43 43 工程 简单总结一下CMake使用的操作步骤 1 新建Nati
  • 什么是字节序(端序、低端字节序、高端字节序、网络字节序)

    前言 一个内容为12 xff08 字符串 xff09 的文本文件 xff0c 它的第一个字节是什么 xff08 小端序 xff09 xff1f 如果你的回答是0x32 xff0c 那你真的应该好好理解下字节序了 如下图所示 xff0c 我这
  • APM中电机输出分析

    一 APM类分析 老规矩 xff0c 先上类图 xff08 1 xff09 如图 xff08 1 xff09 所示 xff0c AP Motors是大部分电机类的父类 xff0c 是AC AttitudeControl姿态控制类的保护型成员
  • 解决安装ROS时出现的sudo rosdep init错误问题

    解决安装ROS时出现的sudo rosdep init错误问题 目前安装ROS时输入sudo rosdep init的命令时 xff0c 可能会出现以下的错误 xff1a ERROR cannot download default sour
  • JS实现HTTP请求头-Basic Authorization

    HTTP协议中的 Authorization 请求消息头含有服务器用于验证用户代理身份的凭证 xff0c 通常会在服务器返回401 Unauthorized 状态码以及WWW Authenticate 消息头之后在后续请求中发送此消息头 A
  • C语言Post和Get方法 ,拿过去直接用

    C语言post 和get 方法的实现 我自己实现的post 和get 请求方法 xff0c 可以直接使用在单片机上 xff0c 比如ESP32 上 xff0c OPl1000 上面 xff0c 下面直接上代码 span class toke
  • QT中图表类QChart系列之(1)-基本用法,画折线图、各个类之间的关系

    参考 xff1a https www cnblogs com yunhaisoft p 5180127 html 首先要注意3点 xff1a xff08 1 xff09 在 pro文件中添加 xff1a QT 43 61 charts xf
  • STM32使用FIFO实现USART串口发送中断

    fifo就不要造轮子了 xff0c 用现成的就行了 linux内核中有目前人类写出的基于c语言的最强FIFO xff0c 请自行搜索学习 巧夺天工的kfifo xff0c kfifo精妙无比 xff0c 实在是高 xff0c 其中用到的环回
  • c++的json读取操作

    使用的开源库是nlohmann json 后续操作也都是基于该开源库操作 本地json文件如下 xff1a 34 model config 34 34 model type 34 34 paddlex 34 34 model cfg fil
  • 三维重建了解

    一 三维重建方法 1 1 传统方法 RGBD D来源结构光或者TOF xff1a 缺点 xff0c 重建范围受限 xff0c 一般不能重建大模型 xff1b 比如 xff0c kinectFusion xff0c DynamicFusion
  • docker容器常用命令

    一 常用命令 显示本地镜像 xff1a docker images 显示已经启动的容器 xff1a docker ps a 从docker hub拉取镜像 reed98 airsim v0是镜像名 xff1a docker pull ree
  • ARM学习随笔(12)定时器查询方式和中断方式

    定时器详细讲解 百度文库 点击打开链接 xff08 一 xff09 查询方式和中断方式的区别在于 xff1a 查询方式不断查询标志位然后进行处理 xff0c 而中断要编写中断服务子程序来处理中断事件 xff08 二 xff09 内部中断是指
  • vgg16网络裁剪并加载模型参数

    主要是测试下模型裁剪后转onnx的问题 删除vgg16网络全连接层 xff0c 加载预训练模型并重新保存模型参数 xff0c 将该参数用于转onnx模型格式 usr bin env python coding utf 8 64 Time 2
  • pth转onnx的三种情况

    usr bin env python coding utf 8 64 Time 2022 8 3 16 19 64 Author weiz 64 ProjectName cbir 64 File pth2onnx py 64 Descrip
  • 以vgg为backbone的简易图像检索系统

    图像检索 xff08 Content based Image Retrieval xff0c 简称CBIR xff09 即以图搜图 xff0c 基于图片语义信息 xff0c 诸如颜色 纹理 布局 CNN based高层语义等特征检索技术 该
  • img2pose: Face Alignment and Detection via 6DoF, Face Pose Estimation代码理解

    import argparse import os import sys import time import numpy as np from PIL import Image ImageOps from torchvision impo
  • 解决普通用户使用sudo找不到命令

    sudo bazel build c opt define MEDIAPIPE DISABLE GPU 61 1 mediapipe examples desktop face mesh face mesh cpu 出现 xff1a sud
  • sfm算法之三角化(三角测量)

    sfm算法流程一般是特征点提取 特征点匹配 计算本质矩阵 基础矩阵 xff0c 最后三角化 但是利用机械臂去观察周围 xff0c 前后帧姿态变化参数是具有的 xff0c 所以不需要通过基础矩阵获取 即利用机械臂的信息直接进行深度估计 已知
  • bazel构建项目案例(第三方库,编译成库,运行案例)

    使用bazel构建项目 xff0c 包含如何引入外部库 xff08 项目中引入了opencv和编译的tensorflow lite库 xff09 xff0c 如何编译成动态库和静态库 xff0c 以及如何调用编译好的库 项目根目录的所有文件
  • 各种小功能集二

    各种小功能集一 十一 C C 43 43 路径解析 头文件 std string UtilsGetPath const char pszFilename std string UtilsGetDirname const char pszFi