ACE_Get_Opt函数笔记
#include "ace/OS_NS_string.h"
#include "ace/Configuration.h"
#include "ace/Configuration_Import_Export.h"
#include "ace/Get_Opt.h"
#include "ace/Log_Msg.h"
#include "ace/INET_Addr.h"
#include "ace/Service_Object.h" class HA_Status: public ACE_Service_Object
{
public:
virtual int init(int argc, ACE_TCHAR *argv[]); private:
ACE_INET_Addr listen_addr_;
}; int HA_Status::init(int argc, ACE_TCHAR *argv[])
{
// Listing 1 code/ch04 // define the valid options, A colon following an option letter means
// the options requires an arguemnt. Use a double colon if the argument
// is optional. examp: "a:b:cd::e" has "-a ,-b , -c ,-d, -e".
static const ACE_TCHAR options[] = ACE_TEXT(":f:");
ACE_Get_Opt cmd_opts(argc, argv, options); // use the long_option()method to equate a long option string
// with one of the short options;
if (cmd_opts.long_option(ACE_TEXT("config"),'f', ACE_Get_Opt::ARG_REQUIRED) == -1)
return -1; int option;
ACE_TCHAR config_file[MAXPATHLEN];
ACE_OS::strcpy(config_file, ACE_TEXT("HAStatus.conf")); // Use operator() (or the get_opt() method) to iterate through the
// command line options.It returns the short option character when
// located, and the short option equivalent when a long option is processed.
// operator() returns EOF when all the options have been processed.
while((option = cmd_opts()) != EOF)
switch (option) {
case 'f':
// The option's argument is accessed via the opt_arg() method.
ACE_OS::strncpy(config_file,
cmd_opts.opt_arg(),
MAXPATHLEN);
break;
case ':':
//If it is a ':',get_opt() return a ':' when a required argument is missing.
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("-%c requires an argument\n"),
cmd_opts.opt_opt()), -1);
default:
ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("Parse error.\n")), -1); }
// Listint 1 // Listint 2 code/ch04
ACE_Configuration_Heap config;
if (config.open() == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("config")), -1); ACE_Registry_ImpExp config_importer(config);
if (config_importer.import_config(config_file) == -1)
ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%p\n"), config_file), -1); ACE_Configuration_Section_Key status_section;
if (config.open_section(config.root_section(),
ACE_TEXT("HAStatus"),
0,
status_section) == -1)
ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%p\n"),
ACE_TEXT("Can't open HAStatus sections")),
-1); u_int status_port;
if (config.get_integer_value(status_section,
ACE_TEXT("ListenPort"),
status_port) == -1)
ACE_ERROR_RETURN((LM_ERROR, "HAStatus ListenPort does not exist\n"), -1); this->listen_addr_.set(static_cast<u_short> (status_port)); return 0; } int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
HA_Status status;
status.init(argc, argv);
return 0;
} /* ACE_Get_Opt (int argc,
ACE_TCHAR **argv,
const ACE_TCHAR *optstring,
int skip_args = 1,
int report_error = 0,
int ordering = PERMUTE_ARGS,
int long_only = 0); # 1.start parsing at an arbitrary index
ACE_Get_Opt can be directed to start processing the argument vector at an
arbi- trary point specified by the skip_args parameter.
The default value is 1, which causes ACE_Get_Opt to skip argv[0]
(traditionally, the program name) when parsing a command line passed to
main(). When using ACE_Get_Opt to parse options received when initializing
a dynamic service skip_args is often specified as 0, because arguments
passed to services initialized via the ACE Service Configurator framework
start in argv[0]. # 2.Report errors while parsing
By default, ACE_Get_Opt is silent about parsing errors; it simply returns
the appropriate value from operator() (or the get_opt() method), allowing
your application to handle and report errors in the most sensible way. If,
however, you’d rather have ACE_Get_Opt display an error message when it
detects an error in the specified argument vector, the constructor’s
report_errors argu- ment should be non-zero. In this case, ACE_Get_Opt will
use ACE_ERROR with the LM_ERROR severity to report the error. # 3.Alternate long option specification
If "W" is included in the options definitions string, ACE_Get_Opt treats -W
similarly to --. For example, -W foo will be parsed the same as --foo. This
can be useful when manipulating argument vectors to change parameters into
long options by inserting an element with -W instead of inserting -- on an
existing element. # 4.About argument ordering
Some applications require you to specify all options at the beginning of
the command line, while others allow you to mix options and other non-option
tokens (such as file names). ACE_Get_Opt supports selection of use cases
defined by enumerators defined in ACE_Get_Opt. ## 1.ACE_Get_Opt::PERMUTE_ARGS: As the argument vector is parsed, the elements
are dynamically rearranged so that those with valid options(and their arguments)
appear at the front of the argument vector, in their original relative ordering.
Non-option elements are placed after the option elements. They can be processed
by some other part of your system, or processed as known non-options. When
operator() returns EOF to indicate the end of options, opt_ind() returns the
index to the first non-option element in the argumet vector. ## 2.ACE_Get_Opt::REQUIRED_ORDER: The argument vector is not reordered and all
options and their their arguments must be at the front of the argument vector.
If a non-option element is encountered, operator() returns EOF; opt_ind()
returns the index of the non-option element. (What is the non-option element?) ## 3.ACE_Get_Opt::RETURN_IN_ORDER: The argument vector is not reordered. Any
non-option element causes operator() to return 1 and the actual element is accessible
via the opt_arg() method. This mode is useful for situations in which options
and other arguments can be specified in any order and in which the relative
ordering makes a difference. This is a situation where it may be useful to parse
options, examine non-options, and and continue parsing after the non-options using
the skip_args argument to specify the new starting point. ## The other two method to change the argument order
1. If the POSIXLY_CORRECT environment variable is set, the ordering mode is set
to REQUIRE_ORDER
2. A + or - character at the beginning of the options string. + changes the
ordering mode to REQUIRE_ORDER; - changes it to RETURN_IN_ORDER. If both are at
the start of the options string, the last ont is used. # 5.Long optins only
If the long_only parameter to the ACE_Get_Opt constructor is non-zero, command
line tokens that begin with a single - are checked as long options. For example,
if the long_only argument were set to 1, the user could type either --config
or -config. */ /*
# ACE_Configuration is a class that defines the configuration interface for the
following two classes available for accessing and manipulating configuration
information:
## 1. ACE_Configuration_Heap is available on all platforms. It keeps all information
in memory. The memory allocation can be customized to use a persistent backing
store, but the most common use is with dynamically-allocated heap memory. ## 2. ACE_Configuration_Win32Registry is available only on Windows. It implements
the ACE_Configuration interface to access and manipulate information in the
Windows registry. # Configuration data is organized hierarchically in sections, analogous to a
filesystem directory tree. Each configuration object contains a root section
that has no name, similar to the filesystem root in UNIX.All other sections
are created hierar- chically beneath the root section and are named by the
application. Sections can be nested to an arbitrary depth. # Configuration Backing Stores
## 1. ACE_Registry_ImpExp uses a text format that includes type information with
each value. This allows type information to be preserved across export/import,
even on machines with different byte orders. ## 2. ACE_Ini_ImpExp uses the older Windows "INI" file format which does not
have type information associated with the values. Therefore, configuration data
exported using ACE_Ini_ImpExp is always imported as string data, regardless of
the original type. */
ACE_Get_Opt函数笔记的更多相关文章
- MySQL函数笔记
MySQL函数笔记 日期函数 SELECT t1.xcjyrq, t1.* FROM view_sbxx t1 WHERE t1.syzt ; SELECT t1.xcjyrq, t1.* FROM ...
- JavaScript基础——JavaScript函数(笔记)
avaScript 函数(笔记) JavaScript 是函数式编程语言,在JavaScript脚本中可以随处看到函数,函数构成了JavaScript源代码的主体. 一.定义函数 定义函数的方法有两种 ...
- STL之vector常用函数笔记
STL之vector常用函数笔记 学会一些常用的vector就足够去刷acm的题了 ps:for(auto x:b) cout<<x<<" ";是基于范围的 ...
- numpy函数笔记(持续更新)
numpy函数笔记 np.isin用法 np.isin(a,b) 用于判定a中的元素在b中是否出现过,如果出现过返回True,否则返回False,最终结果为一个形状和a一模一样的数组.(注意:这里的a ...
- Javascript进阶篇——(函数)笔记整理
这节是根据慕课网和JavaScript DOM编程艺术一书加起来做的笔记 什么是函数如果需要多次使用同一段代码,可以把它们封装成一个函数.函数(function)就是一组允许在你的代码里随时调用的语句 ...
- 学习Python函数笔记之二
---恢复内容开始--- 1.内置函数:取绝对值函数abs() 2.内置函数:取最大值max(),取最小值min() 3.内置函数:len()是获取序列的长度 4.内置函数:divmod(x,y),返 ...
- 学习python函数笔记之一
1.函数文档字符串,用于存放函数的说明,一般写在第一行 2.函数调用:函数名+参数列表(函数的参数分实际参数和形式参数,str就是形式参数,则'welcome 头 python'就是实际参数) 参数需 ...
- Oracle常用函数笔记
一.字符函数 1.dual 临时表 oracle中的临时变量表,此表只返回第一行第一列 例如:select sysdate from dual 输出:2014-6-9 11:20:39 2.Initc ...
- C++ 内联函数笔记
要使用内联函数,必须采取下述措施之一: +在函数声明前加上关键字inline: +在函数定义前加上关键字inline. 通常的做法是省略原型,将整个定义(即函数头和所有函数代码)放在本应提供原型的地方 ...
随机推荐
- 一道题目学ES6 API,合并对象id相同的两个数组对象
var arr2=[{id:1,name:'23'}] var arr1=[{id:1,car:'car2'}] const combined = arr2.reduce((acc, cur) =&g ...
- Oracle中如何自定义类型
一:Oracle中的类型有很多种,主要可以分为以下几类:1.字符串类型.如:char.nchar.varchar2.nvarchar2.2.数值类型.如:int.number(p,s).integer ...
- mysql_取分组后的前几行值
--方法一: select a.id,a.SName,a.ClsNo,a.Score from Table1 a left join Table1 b on a.ClsNo=b.ClsNo and a ...
- redis入门到精通系列(六):redis的事务详解
(一)事务的概念 谈到数据库的高级应用,不可避免会谈到事务.熟悉mysql的朋友们对事务肯定不陌生,简单来讲事务就是控制一个数据库操作序列要么全部执行要么全部不执行.今天我们就来了解redis中的事务 ...
- 移动端(App)项目进行满屏高度的设置
做移动端App的时候 高度一般会根据页面的元素进行自动设置,不会铺满整个屏幕.通过以下代码实现满屏高度. #app{ width: 100%; height: 100%; position: abso ...
- String类型和包装类型作为参数传递时,是属于值传递还是引用传递呢?
原理知识: 如果参数类型是原始类型,那么传过来的就是这个参数的一个副本,也就是这个原始参数的值,这个跟之前所谈的传值是一样的.如果在函数中改变了副本的 值不会改变原始的值. 如果参数类型是引用类型,那 ...
- 【阿菜做实践】利用ganache-cli本地fork以太坊主链分叉
前言 Fork主网意思是模拟具有与主网相同的状态的网络,但它将作为本地开发网络工作. 这样你就可以与部署的协议进行交互,并在本地测试复杂的交互.不用担心分叉主网作为测试链会占很多内存.这些方法都不会将 ...
- Tableau如何绘制瀑布图
一.将子类别拖至列,利润拖拽至行,类型改为甘特条形图 二 右键利润-快速表计算-汇总(数据会从左向右显示累计汇总) 三.创建计算字段-[利润] 四.将负利润拖拽到大小,利润拖拽到颜色 分析-合计-显示 ...
- Oracle 函数高级查询
目录 oracle高级查询 Oracle SQL获取每个分组中日期最新的一条数据 求平均值(为0的参数不均摊) 字符串清除前面的0 判断字符串串是否包含某个字符串 switch 判断 oracle不足 ...
- 升级过log4j,却还没搞懂log4j漏洞的本质?
摘要:log4j远程代码漏洞问题被大范围曝光后已经有一段时间了,今天完整讲清JNDI和RMI以及该漏洞的深层原因. 本文分享自华为云社区<升级过log4j,却还没搞懂log4j漏洞的本质?为你完 ...