当前位置: 首页 > 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, …...

vue3 字体颜色设置的多种方式

在Vue 3中设置字体颜色可以通过多种方式实现&#xff0c;这取决于你是想在组件内部直接设置&#xff0c;还是在CSS/SCSS/LESS等样式文件中定义。以下是几种常见的方法&#xff1a; 1. 内联样式 你可以直接在模板中使用style绑定来设置字体颜色。 <template><div :s…...

JUC笔记(上)-复习 涉及死锁 volatile synchronized CAS 原子操作

一、上下文切换 即使单核CPU也可以进行多线程执行代码&#xff0c;CPU会给每个线程分配CPU时间片来实现这个机制。时间片非常短&#xff0c;所以CPU会不断地切换线程执行&#xff0c;从而让我们感觉多个线程是同时执行的。时间片一般是十几毫秒(ms)。通过时间片分配算法执行。…...

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

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

Android Bitmap治理全解析:从加载优化到泄漏防控的全生命周期管理

引言 Bitmap&#xff08;位图&#xff09;是Android应用内存占用的“头号杀手”。一张1080P&#xff08;1920x1080&#xff09;的图片以ARGB_8888格式加载时&#xff0c;内存占用高达8MB&#xff08;192010804字节&#xff09;。据统计&#xff0c;超过60%的应用OOM崩溃与Bitm…...

GC1808高性能24位立体声音频ADC芯片解析

1. 芯片概述 GC1808是一款24位立体声音频模数转换器&#xff08;ADC&#xff09;&#xff0c;支持8kHz~96kHz采样率&#xff0c;集成Δ-Σ调制器、数字抗混叠滤波器和高通滤波器&#xff0c;适用于高保真音频采集场景。 2. 核心特性 高精度&#xff1a;24位分辨率&#xff0c…...

Web 架构之 CDN 加速原理与落地实践

文章目录 一、思维导图二、正文内容&#xff08;一&#xff09;CDN 基础概念1. 定义2. 组成部分 &#xff08;二&#xff09;CDN 加速原理1. 请求路由2. 内容缓存3. 内容更新 &#xff08;三&#xff09;CDN 落地实践1. 选择 CDN 服务商2. 配置 CDN3. 集成到 Web 架构 &#xf…...

LeetCode - 199. 二叉树的右视图

题目 199. 二叉树的右视图 - 力扣&#xff08;LeetCode&#xff09; 思路 右视图是指从树的右侧看&#xff0c;对于每一层&#xff0c;只能看到该层最右边的节点。实现思路是&#xff1a; 使用深度优先搜索(DFS)按照"根-右-左"的顺序遍历树记录每个节点的深度对于…...

基于TurtleBot3在Gazebo地图实现机器人远程控制

1. TurtleBot3环境配置 # 下载TurtleBot3核心包 mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src git clone -b noetic-devel https://github.com/ROBOTIS-GIT/turtlebot3.git git clone -b noetic https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git git clone -b noetic-dev…...

GruntJS-前端自动化任务运行器从入门到实战

Grunt 完全指南&#xff1a;从入门到实战 一、Grunt 是什么&#xff1f; Grunt是一个基于 Node.js 的前端自动化任务运行器&#xff0c;主要用于自动化执行项目开发中重复性高的任务&#xff0c;例如文件压缩、代码编译、语法检查、单元测试、文件合并等。通过配置简洁的任务…...

掌握 HTTP 请求:理解 cURL GET 语法

cURL 是一个强大的命令行工具&#xff0c;用于发送 HTTP 请求和与 Web 服务器交互。在 Web 开发和测试中&#xff0c;cURL 经常用于发送 GET 请求来获取服务器资源。本文将详细介绍 cURL GET 请求的语法和使用方法。 一、cURL 基本概念 cURL 是 "Client URL" 的缩写…...