提升程序选项多个模块示例?

时间:2015-09-02 23:01:40

标签: boost options modular

我能够为boost :: program_options找到older dox files,它引用的示例演示了在具有多个模块的项目中使用boost :: program_options,其中每个模块独立地注册其可用选项。有人知道这个例子是否存在以及在哪里找到它?或者,是否有人知道另一个以这种模块化方式使用boost :: program_options的开源项目?

来自dox:

@page multiple_modules Multiple modules

Large programs are likely to have several modules which want to use
some options. One possible approach is show here.
@sa @ref recipe_multiple_modules

@include multiple_modules.cpp 

1 个答案:

答案 0 :(得分:0)

我想要相同的功能。不幸的是我没有在文档中找到它。因此,我黑客攻击解决方案。基本上,我检查第一个参数,验证它并将剩余的参数传递给模块。每个模块都定义了自己的选项。

def functionToCreateContext(): StreamingContext = {
    val ssc = new StreamingContext(...)   // new context
    val lines = ssc.socketTextStream(...) // create DStreams
    ...
    ssc.checkpoint(checkpointDirectory)   // set checkpoint directory
    ssc
}

// Get StreamingContext from checkpoint data or create a new one
val context = StreamingContext.getOrCreate(checkpointDirectory, functionToCreateContext _)

// Do additional setup on context that needs to be done,
// irrespective of whether it is being started or restarted
context. ...

// Start the context
context.start()
context.awaitTermination()

另请参阅我的blog post