当前位置: 首页 > news >正文

介绍几种使用工具

FileWatch,观测文件变化,源码地址:https://github.com/ThomasMonkman/filewatch
nlohmann::json,json封装解析,源码地址:https://github.com/nlohmann/json
optionparser,解析选项,源码地址:https://optionparser.sourceforge.net/

以上介绍的这三个工具都是我在学习FastDDS过程中看到的。他们的使用非常简单,都只有一个头文件。下面简单介绍一下如何使用:
FileWatch

#include <functional>
#include "FileWatch.hpp"using FileWatchHandle = std::unique_ptr<filewatch::FileWatch<std::string>>;void watch()
{std::cout << "watch" << std::endl;
}int main()
{std::function<void()> callback = watch;(new filewatch::FileWatch<std::string>("d:\\test.txt",[callback](const std::string& /*path*/, const filewatch::Event change_type){switch (change_type){case filewatch::Event::modified:callback();break;default:// No-opbreak;}}));getchar();return 0;
}

只需要设置一个文件路径和一个回调函数,当这个文件改动时,就会触发回调函数。这个可以做一些热更新配置的功能,当配置文件变动时,无需重启软件,就能读取新的配置。
nlohmann::json

#include "json.hpp"
#include <iostream>using Info = nlohmann::json;int main()
{Info info;std::cout << info.size() << std::endl;info["a"] = "b";std::cout << info["a"] << std::endl;auto iter = info.find("a");if (iter == info.end()) {std::cout << "not found" << std::endl;}else {std::cout << *iter << std::endl;}std::string s = R"({"name" : "nick","credits" : "123","ranking" : 1})";auto j = nlohmann::json::parse(s);std::cout << j["name"] << std::endl;std::string ss = j.dump();std::cout << "ss : " << ss << std::endl;Info j1;Info j2 = nlohmann::json::object();Info j3 = nlohmann::json::array();std::cout << j1.is_object() << std::endl;std::cout << j1.type_name() << std::endl;std::cout << j2.is_object() << std::endl;std::cout << j2.is_array() << std::endl;Info infoo{{"name", "darren"},{"credits", 123},{"ranking", 1}};std::cout << infoo["name"] << std::endl;std::cout << infoo.type_name() << std::endl;//遍历for (auto iter = infoo.begin(); iter != infoo.end(); iter++) {std::cout << iter.key() << " : " << iter.value() << std::endl;//std::cout << iter.value() << std::endl;//std::cout << *iter << std::endl;}system("pause");return 0;
}

在这里插入图片描述

更多内容可以参考csdn:https://blog.csdn.net/gaoyuelon/article/details/131482372?fromshare=blogdetail
optionparser

#include "optionparser.h"struct Arg : public option::Arg
{static void print_error(const char* msg1,const option::Option& opt,const char* msg2){fprintf(stderr, "%s", msg1);fwrite(opt.name, opt.namelen, 1, stderr);fprintf(stderr, "%s", msg2);}static option::ArgStatus Unknown(const option::Option& option,bool msg){if (msg){print_error("Unknown option '", option, "'\n");}return option::ARG_ILLEGAL;}static option::ArgStatus Required(const option::Option& option,bool msg){if (option.arg != 0 && option.arg[0] != 0){return option::ARG_OK;}if (msg){print_error("Option '", option, "' requires an argument\n");}return option::ARG_ILLEGAL;}static option::ArgStatus Numeric(const option::Option& option,bool msg){char* endptr = 0;if (option.arg != nullptr){strtol(option.arg, &endptr, 10);if (endptr != option.arg && *endptr == 0){return option::ARG_OK;}}if (msg){print_error("Option '", option, "' requires a numeric argument\n");}return option::ARG_ILLEGAL;}template<long min = 0, long max = std::numeric_limits<long>::max()>static option::ArgStatus NumericRange(const option::Option& option,bool msg){static_assert(min <= max, "NumericRange: invalid range provided.");char* endptr = 0;if (option.arg != nullptr){long value = strtol(option.arg, &endptr, 10);if (endptr != option.arg && *endptr == 0 &&value >= min && value <= max){return option::ARG_OK;}}if (msg){std::ostringstream os;os << "' requires a numeric argument in range ["<< min << ", " << max << "]" << std::endl;print_error("Option '", option, os.str().c_str());}return option::ARG_ILLEGAL;}static option::ArgStatus String(const option::Option& option,bool msg){if (option.arg != 0){return option::ARG_OK;}if (msg){print_error("Option '", option, "' requires an argument\n");}return option::ARG_ILLEGAL;}};enum  optionIndex
{UNKNOWN_OPT,HELP,SAMPLES,INTERVAL,ENVIRONMENT
};const option::Descriptor usage[] = {{ UNKNOWN_OPT, 0, "", "",                Arg::None,"Usage: HelloWorldExample <publisher|subscriber>\n\nGeneral options:" },{ HELP,    0, "h", "help",               Arg::None,      "  -h \t--help  \tProduce help message." },{ UNKNOWN_OPT, 0, "", "",                Arg::None,      "\nPublisher options:"},{ SAMPLES, 0, "s", "samples",            Arg::NumericRange<>,"  -s <num>, \t--samples=<num>  \tNumber of samples (0, default, infinite)." },{ INTERVAL, 0, "i", "interval",          Arg::NumericRange<>,"  -i <num>, \t--interval=<num>  \tTime between samples in milliseconds (Default: 100)." },{ ENVIRONMENT, 0, "e", "env",            Arg::None,       "  -e \t--env   \tLoad QoS from environment." },{ 0, 0, 0, 0, 0, 0 }
};int main(int argc, char **argv)
{argc -= (argc > 0);argv += (argc > 0); // skip program name argv[0] if presentoption::Stats stats(true, usage, argc, argv);std::vector<option::Option> options(stats.options_max);std::vector<option::Option> buffer(stats.buffer_max);option::Parser parse(true, usage, argc, argv, &options[0], &buffer[0]);try{if (parse.error()){throw 1;}if (options[HELP] || options[UNKNOWN_OPT]){throw 1;}// For backward compatibility count and sleep may be given positionallyif (parse.nonOptionsCount() > 3 || parse.nonOptionsCount() == 0){throw 2;}// Decide between publisher or subscriberconst char* type_name = parse.nonOption(0);// make sure is the first option.// type_name and buffer[0].name reference the original command line char array// type_name must precede any other arguments in the array.// Note buffer[0].arg may be null for non-valued options and is not reliable for// testing purposes.if (parse.optionsCount() && type_name >= buffer[0].name){throw 2;}if (strcmp(type_name, "publisher") == 0){std::cout << "publisher" << std::endl;}else if (strcmp(type_name, "subscriber") == 0){std::cout << "subscriber" << std::endl;}else{throw 2;}}catch (int error){if (error == 2){std::cerr << "ERROR: first argument must be <publisher|subscriber> followed by - or -- options"<< std::endl;}option::printUsage(fwrite, stdout, usage);return error;}getchar();return 0;
}

在这里插入图片描述
简单好用的工具能给我们工作带来很多便利,希望这些工具对你有用~

相关文章:

介绍几种使用工具

FileWatch&#xff0c;观测文件变化&#xff0c;源码地址&#xff1a;https://github.com/ThomasMonkman/filewatch nlohmann::json&#xff0c;json封装解析&#xff0c;源码地址&#xff1a;https://github.com/nlohmann/json optionparser&#xff0c;解析选项&#xff0c;源…...

Vue:关于声明式导航中的 跳转、高亮、以及两个类名的定制

声明式导航-导航链接 文章目录 声明式导航-导航链接router-link的两大特点&#xff08;能跳转、能高亮&#xff09;声明式导航-两个类名定制两个高亮类名 实现导航高亮&#xff0c;实现方式其实&#xff0c;css&#xff0c;JavaScript , Vue ,都可以实现。其实关于路由导航&…...

Sharding-JDBC分库分表-自动配置与分片规则加载原理-3

Sharding JDBC自动配置的原理 与所有starter一样&#xff0c;shardingsphere-jdbc-core-spring-boot-starter也是通过SPI自动配置的原理实现分库分表配置加载&#xff0c;spring.factories文件中的自动配置类shardingsphere-jdbc-core-spring-boot-starter功不可没&#xff0c…...

E8267D 是德科技矢量信号发生器

描述 最先进的微波信号发生器 安捷伦E8267D PSG矢量信号发生器是业界首款集成式微波矢量信号发生器&#xff0c;I/Q调制最高可达44 GHz&#xff0c;典型输出功率为23 dBm&#xff0c;最高可达20 GHz&#xff0c;对于10 GHz信号&#xff0c;10 kHz偏移时的相位噪声为-120 dBc/…...

Git git fetch 和 git pull 区别

git pull和git fetch的作用都是用于从远程仓库获取最新代码&#xff0c;但它们之间有一些区别。 git pull会自动执行两个操作&#xff1a;git fetch和git merge。它从远程仓库获取最新代码&#xff0c;并将其合并到当前分支中。 示例&#xff1a;运行git pull origin master会从…...

软件UI工程师工作的岗位职责(合集)

软件UI工程师工作的岗位职责1 职责&#xff1a; 1.负责产品的UI视觉设计(手机软件界面 网站界面 图标设计产品广告及 企业文化的创意设计等); 2.负责公司各种客户端软件客户端的UE/UI界面及相关图标制作; 3.设定产品界面的整体视觉风格; 4.参与产品规划构思和创意过程&…...

Mac系统Anaconda环境配置Python的json库

本文介绍在Mac电脑的Anaconda环境中&#xff0c;配置Python语言中&#xff0c;用以编码、解码、处理JSON数据的json库的方法&#xff1b;在Windows电脑中配置json库的方法也是类似的&#xff0c;大家可以一并参考。 JSON&#xff08;JavaScript Object Notation&#xff09;是一…...

Python数据分析与数据挖掘:解析数据的力量

引言&#xff1a; 随着大数据时代的到来&#xff0c;数据分析和数据挖掘已经成为许多行业中不可或缺的一部分。在这个信息爆炸的时代&#xff0c;如何从大量的数据中提取有价值的信息&#xff0c;成为了企业和个人追求的目标。而Python作为一种强大的编程语言&#xff0c;提供…...

我的私人笔记(安装hive)

1.hive下载&#xff1a;Index of /dist/hive/hive-1.2.1 或者上传安装包至/opt/software&#xff1a;rz或winscp上传 2.解压 cd /opt/software tar -xzvf apache-hive-1.2.1-bin.tar.gz -C /opt/servers/ 3.重命名 mv apache-hive-1.2.1-bin hive 4.配置环境变量 vi /etc/…...

【kubernetes】k8s部署APISIX及在KubeSphere使用APISIX

Apache APISIX https://apisix.apache.org/ 功能比nginx-ingress更强 本文采用2.5.0版本 https://apisix.apache.org/zh/docs/apisix/2.15/getting-started/ 概述内容来源于官方&#xff0c;学习于马士兵云原生课程 概述 Apache APISIX 是什么&#xff1f; Apache APISIX 是 …...

串口接收数据-控制LED灯

目标 通过串口接收数据&#xff0c;对数据分析&#xff0c;控制8个LED灯按照设定时间闪烁。 8个LED灯可以任意设计&#xff0c;是否闪烁。闪烁时间按ms计算&#xff0c;通过串口发送&#xff0c;可设置1~4,294,967,296ms&#xff0c;也就是4字节数据协议自拟&#xff0c;有数…...

python面试题合集(一)

python技术面试题 1、Python中的幂运算 在python中幂运算是由两个 **星号运算的&#xff0c;实例如下&#xff1a; >>> a 2 ** 2 >>> a 4我们可以看到2的平方输出结果为4。 那么 ^指的是什么呢&#xff1f;我们用代码进行演示&#xff1a; >>>…...

论文浅尝 | 利用对抗攻击策略缓解预训练语言模型中的命名实体情感偏差问题...

笔记整理&#xff1a;田家琛&#xff0c;天津大学博士&#xff0c;研究方向为文本分类 链接&#xff1a;https://ojs.aaai.org/index.php/AAAI/article/view/26599 动机 近年来&#xff0c;随着预训练语言模型&#xff08;PLMs&#xff09;在情感分类领域的广泛应用&#xff0c…...

springboot web开发springmvc自动配置原理

前言 我们也知道springboot启用springmvc基本不用做什么配置可以很方便就使用了但是不了解原理,开发过程中遇到点问题估计就比较头疼,不管了解的深不深入,先巴拉一番再说… 下面我们先看看官网…我的版本是2.3.2版本,发现官网改动也比较大…不同版本自己巴拉下吧,结构虽然变化…...

发表于《自然》杂志:语音转文本BCI的新突破实现62字/分钟的速度

语音脑机接口&#xff08;BCI&#xff09;是一项创新技术&#xff0c;通过用户的大脑信号在用户和某些设备之间建立通信通道&#xff0c;它们在恢复残疾患者的言语和通信能力方面具有巨大潜力。 早期的研究虽然很有希望&#xff0c;但尚未达到足够高的精度来解码大脑活动&…...

微软 Turing Bletchley v3视觉语言模型更新:必应搜索图片更精准

据微软新闻稿透露&#xff0c;在推出第三代Turing Bletchley视觉语言模型后&#xff0c;微软计划逐步将其整合到Bing等相关产品中&#xff0c;以提供更出色的图像搜索体验。这款模型最初于2021年11月面世&#xff0c;并在2022年秋季开始邀请用户测试。 凭借用户的反馈和建议&am…...

Ubuntu 22.04 x86_64 源码编译 pytorch-v2.0.1 笔记【2】编译成功

20230831继续&#xff1a; 当前状态 (pytorch-build) yeqiangyeqiang-MS-7B23:~/Downloads/src/pytorch$ pwd /home/yeqiang/Downloads/src/pytorch (pytorch-build) yeqiangyeqiang-MS-7B23:~/Downloads/src/pytorch$ python3 -V Python 3.10.6 (pytorch-build) yeqiangyeqi…...

IIR滤波器

IIR滤波器原理 IIR的特点是&#xff1a;非线性相位、消耗资源少。 IIR滤波器的系统函数与差分方程如下所示&#xff1a; 由差分方程可知IIR滤波器存在反馈&#xff0c;因此在FPGA设计时要考虑到有限字长效应带来的影响。差分方程中包括两个部分&#xff1a;输入信号x(n)的M节…...

【QT】使用qml的QtWebEngine遇到的一些问题总结

在使用qt官方的一些QML的QtWebEngine相关的例程的时候&#xff0c;有时在运行会报如下错误&#xff1a; WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed 这个问题在main函数里面最前面加上&#xff1a; QCoreApplication::setAttr…...

230902-部署Gradio到已有FastAPI及服务器中

1. 官方例子 run.py from fastapi import FastAPI import gradio as grCUSTOM_PATH "/gradio"app FastAPI()app.get("/") def read_main():return {"message": "This is your main app"}io gr.Interface(lambda x: "Hello, …...

OpenLayers 可视化之热力图

注&#xff1a;当前使用的是 ol 5.3.0 版本&#xff0c;天地图使用的key请到天地图官网申请&#xff0c;并替换为自己的key 热力图&#xff08;Heatmap&#xff09;又叫热点图&#xff0c;是一种通过特殊高亮显示事物密度分布、变化趋势的数据可视化技术。采用颜色的深浅来显示…...

TDengine 快速体验(Docker 镜像方式)

简介 TDengine 可以通过安装包、Docker 镜像 及云服务快速体验 TDengine 的功能&#xff0c;本节首先介绍如何通过 Docker 快速体验 TDengine&#xff0c;然后介绍如何在 Docker 环境下体验 TDengine 的写入和查询功能。如果你不熟悉 Docker&#xff0c;请使用 安装包的方式快…...

Leetcode 3577. Count the Number of Computer Unlocking Permutations

Leetcode 3577. Count the Number of Computer Unlocking Permutations 1. 解题思路2. 代码实现 题目链接&#xff1a;3577. Count the Number of Computer Unlocking Permutations 1. 解题思路 这一题其实就是一个脑筋急转弯&#xff0c;要想要能够将所有的电脑解锁&#x…...

vue3 定时器-定义全局方法 vue+ts

1.创建ts文件 路径&#xff1a;src/utils/timer.ts 完整代码&#xff1a; import { onUnmounted } from vuetype TimerCallback (...args: any[]) > voidexport function useGlobalTimer() {const timers: Map<number, NodeJS.Timeout> new Map()// 创建定时器con…...

uniapp微信小程序视频实时流+pc端预览方案

方案类型技术实现是否免费优点缺点适用场景延迟范围开发复杂度​WebSocket图片帧​定时拍照Base64传输✅ 完全免费无需服务器 纯前端实现高延迟高流量 帧率极低个人demo测试 超低频监控500ms-2s⭐⭐​RTMP推流​TRTC/即构SDK推流❌ 付费方案 &#xff08;部分有免费额度&#x…...

C# SqlSugar:依赖注入与仓储模式实践

C# SqlSugar&#xff1a;依赖注入与仓储模式实践 在 C# 的应用开发中&#xff0c;数据库操作是必不可少的环节。为了让数据访问层更加简洁、高效且易于维护&#xff0c;许多开发者会选择成熟的 ORM&#xff08;对象关系映射&#xff09;框架&#xff0c;SqlSugar 就是其中备受…...

【论文阅读28】-CNN-BiLSTM-Attention-(2024)

本文把滑坡位移序列拆开、筛优质因子&#xff0c;再用 CNN-BiLSTM-Attention 来动态预测每个子序列&#xff0c;最后重构出总位移&#xff0c;预测效果超越传统模型。 文章目录 1 引言2 方法2.1 位移时间序列加性模型2.2 变分模态分解 (VMD) 具体步骤2.3.1 样本熵&#xff08;S…...

Linux --进程控制

本文从以下五个方面来初步认识进程控制&#xff1a; 目录 进程创建 进程终止 进程等待 进程替换 模拟实现一个微型shell 进程创建 在Linux系统中我们可以在一个进程使用系统调用fork()来创建子进程&#xff0c;创建出来的进程就是子进程&#xff0c;原来的进程为父进程。…...

视觉slam十四讲实践部分记录——ch2、ch3

ch2 一、使用g++编译.cpp为可执行文件并运行(P30) g++ helloSLAM.cpp ./a.out运行 二、使用cmake编译 mkdir build cd build cmake .. makeCMakeCache.txt 文件仍然指向旧的目录。这表明在源代码目录中可能还存在旧的 CMakeCache.txt 文件,或者在构建过程中仍然引用了旧的路…...

LINUX 69 FTP 客服管理系统 man 5 /etc/vsftpd/vsftpd.conf

FTP 客服管理系统 实现kefu123登录&#xff0c;不允许匿名访问&#xff0c;kefu只能访问/data/kefu目录&#xff0c;不能查看其他目录 创建账号密码 useradd kefu echo 123|passwd -stdin kefu [rootcode caozx26420]# echo 123|passwd --stdin kefu 更改用户 kefu 的密码…...