目录
4.1 time时间打印
4.2 print
4.3 parse
◆ find_switch()
◆ find_argument()
◆ parse()
◆ parse_2x_arguments()
◆ parse_3x_arguments()
◆ parse_x_arguments()
◆ parse_multiple_arguments()
◆ parse_multiple_2x_arguments()
◆ parse_multiple_3x_arguments()
◆ parse_file_extension_argument()
4.4 程序示例
console模块官方文档:Point Cloud Library (PCL): pcl::console Namespace Reference
4.1 time时间打印
头文件 | #include <pcl/console/time.h> |
pcl::console::TicToc time; | 定义类 |
void tic() | 获取单前时间 |
double toc() const | 获取时间差 |
void toc_print() const | 打印时间 |
4.2 print
#define PCL_ALWAYS(...) pcl::console::print (pcl::console::L_ALWAYS, __VA_ARGS__) |
#define PCL_ERROR(...) pcl::console::print (pcl::console::L_ERROR, __VA_ARGS__) |
#define PCL_WARN(...) pcl::console::print (pcl::console::L_WARN, __VA_ARGS__) |
#define PCL_INFO(...) pcl::console::print (pcl::console::L_INFO, __VA_ARGS__) |
#define PCL_DEBUG(...) pcl::console::print (pcl::console::L_DEBUG, __VA_ARGS__) |
#define PCL_VERBOSE(...) pcl::console::print (pcl::console::L_VERBOSE, __VA_ARGS__) |
4.3 parse
◆ find_switch()
功能 | 判断argv命令行中是否有argument_name |
函数原型 |
|
◆ find_argument()
功能 | 查找名称为"argument_name"的参数在参数列表"argv"中的位置。 |
函数原型 | int pcl::console::find_argument ( int argc, const char *const *argv, |
◆ parse()
功能 | 判断argv命令行中是否有argument_name |
函数原型 | int pcl::console::parse (int argc, // 参数列表的数量 const char *const *argv, // 参数列表const char *argument_name, //搜索的值 Type & value //输出:返回的值 ) |
◆ parse_2x_arguments()
功能 | 输出argv参数列表中2个str数据 |
函数原型 | PCL_EXPORTS int pcl::console::parse_2x_arguments(int argc, // 参数列表的数量 const char *const *argv, // 参数列表const char *str, //搜索的值 double &f, //第一个输出值 double &s, //第二个输出值 bool debug = true //是否打印调试信息 ) |
◆ parse_3x_arguments()
功能 | 输出argv参数列表中3个str数据 |
函数原型 | PCL_EXPORTS int pcl::console::parse_3x_arguments(int argc, double &t, //第3个输出值 |
◆ parse_x_arguments()
功能 | 输出argv参数列表中符合条件的str数据 |
函数原型 | PCL_EXPORTS int pcl::console::parse_x_arguments(int argc, |
◆ parse_multiple_arguments()
功能 | 输出argv参数列表中含有多个str的解析 |
函数原型 | bool pcl::console::parse_multiple_arguments( int argc, const char *const * argv const char * str, std::vector< double > & values,//多次出现相同的命令行参数 ) |
◆ parse_multiple_2x_arguments()
功能 | 输出argv参数列表含有多个str有2个数据的解析 |
函数原型 | bool pcl::console::parse_multiple_arguments( int argc, const char *const * argv const char * str, std::vector< double > & values_f,//输出值的第1个向量 std::vector< double > & values_s,//输出值的第2个向量) |
◆ parse_multiple_3x_arguments()
功能 | 输出argv参数列表含有多个str有3个数据的解析 |
函数原型 | bool pcl::console::parse_multiple_arguments( int argc, const char *const * argv const char * str, std::vector< double > & values_f,//输出值的第1个向量 std::vector< double > & values_s,//输出值的第2个向量) std::vector< double > & values_s,//输出值的第3个向量) |
◆ parse_file_extension_argument()
功能 | 判断argv文件后缀是否有argument_name |
函数原型 |
|
4.4 程序示例
#include <iostream>
#include <pcl/console/parse.h>
#include <pcl/console/print.h>
#include <pcl/console/time.h>
#include <pcl/point_types.h>using namespace std;int main(int argc, char *argv[])
{cout << "--- 01 time ---" << endl;pcl::console::TicToc time; //创建TicToc类time.tic();time.toc_print();cout << "--- 02 print ---" << endl;PCL_ALWAYS(stdout,"%d\n",12);PCL_ERROR(stdout,"%s","Error msg.\n");PCL_INFO(stdout,"%s\n","Info msg.");PCL_DEBUG(stdout,"%s","Pcl info.\n");PCL_VERBOSE(stdout,"%s\n","Pcl verbose.");cout << "--- 03 print ---" << endl;cout << "--- 3.1 find_switch ---" << endl;bool ret = pcl::console::find_switch(argc,argv,"-d");cout << ret << endl;cout << "--- 3.2 find_argument ---" << endl;int idx = pcl::console::find_argument(argc,argv,"-d");cout << idx << endl;cout << "--- 3.3 parse ---" << endl;std::string value;pcl::console::parse(argc,argv,"-d",value);cout << value << endl;cout << "--- 3.4 parse_argument ---" << endl;int ivalue;pcl::console::parse_argument(argc,argv,"-i",ivalue);cout << ivalue << endl;cout << "--- 3.5 parse_2x_arguments ---" << endl;float fv1; float fv2;pcl::console::parse_2x_arguments(argc,argv,"-v",fv1,fv2);cout << fv1 << " " << fv2 << endl;cout << "--- 3.6 parse_3x_arguments ---" << endl;double dv1, dv2,dv3;pcl::console::parse_3x_arguments(argc,argv,"-dbl",dv1,dv2,dv3);cout << dv1 << " " << dv2 << " " << dv3 << endl;cout << "--- 3.7 parse_x_arguments ---" << endl;std::vector<double> vs;pcl::console::parse_x_arguments(argc,argv,"-dbl",vs);for(const auto &iv : vs)cout << iv << " " ;cout << endl;cout << "--- 3.8 parse_multiple_arguments ---" << endl;std::vector<int> mvs;pcl::console::parse_multiple_arguments(argc,argv,"-mv",mvs);for(const auto &iv : mvs)cout << iv << " " ;cout << endl;cout << "--- 3.9 parse_multiple_2x_arguments ---" << endl;std::vector<double> fmvs,smvs;pcl::console::parse_multiple_2x_arguments(argc,argv,"-2mv",fmvs,smvs);for(const auto &iv : fmvs)cout << iv << " " ;cout << endl;for(const auto &iv : smvs)cout << iv << " " ;cout << endl;cout << "--- 3.10 parse_multiple_3x_arguments ---" << endl;std::vector<double> f_mvs,s_mvs,t_mvs;pcl::console::parse_multiple_3x_arguments(argc,argv,"-3mv",f_mvs,s_mvs,t_mvs);for(const auto &iv : f_mvs)cout << iv << " " ;cout << endl;for(const auto &iv : s_mvs)cout << iv << " " ;cout << endl;for(const auto &iv : t_mvs)cout << iv << " " ;cout << endl;cout << "--- 3.11 parse_file_extension_argument ---" << endl;std::vector<int> idxs = pcl::console::parse_file_extension_argument(argc,argv,".pcd");for(const auto &iv : idxs)cout << iv << " ";cout << endl;return 0;
}
打开终端进行验证解析,输入./程序名 待解析字段
***:~/studydata/pcl/18console/build$ ./console -d -i -v 1.1,1.2 -db 1.1,1.2,1.3 -db 1.0,2.0,3.0,4.0 -mv 1 -mv 4 -2mv 8,9 -2mv 10,11 -3mv 12,13,14 -3mv 15,16,17 -3mv 18,19,20
--- 01 time ---
6e-05 ms
--- 02 print ---
12
Error msg.
Info msg.
--- 03 print ---
--- 3.1 find_switch ---
1
--- 3.2 find_argument ---
1
--- 3.3 parse ---
-i
--- 3.4 parse_argument ---
0
--- 3.5 parse_2x_arguments ---
1.1 1.2
--- 3.6 parse_3x_arguments ---
1.1 1.2 1.3
--- 3.7 parse_x_arguments ---
1.1 1.2 1.3
--- 3.8 parse_multiple_arguments ---
1 4
--- 3.9 parse_multiple_2x_arguments ---
8 10
9 11
--- 3.10 parse_multiple_3x_arguments ---
12 15 18
13 16 19
14 17 20
--- 3.11 parse_file_extension_argument ---