Quick Start 快速入門

Preprocessing with Wave is highly configurable. You must define a few options to control it. Here are a few of the options you can define:
Wave進行預處理是高度可配置的。你必須定義一些選項來控制它。以下是一些你可以定義的選項:

 include search paths defining where to search for files to be included with #include <...> and #include "..." directives
    包含查找路徑定義,用於查找 #include <...>#include "..." 指令中所包含的文件
 which macros to predefine and which of the predefined macros to undefine
    哪些宏是預定義的以及哪些預定義宏被去定義
 whether to enable any of several extensions to the C++ Standard (such as for variadics and placemarkers)
    是否允許C++標準的幾個擴展(如variadics 和 placemarkers)

You can access all these processing parameters through the boost::wave::context object. So you must instantiate one object instance of this type to use the Wave library. (For more information about the context template class, please refer to the class reference here.) To instantiate the boost::wave::context object you have to supply at least two template parameters: the iterator type of the underlying input stream to use and the type of the lexer iterator to be used as the token source for the preprocessing engine.
你可以通過boost::wave::context對像訪問所有這些處理參數。因此你必須實例化該類型的一個對像實例來使用Wave庫。(有關context模板類的更多信息,請參考這裡的類參考)。要實例化boost::wave::context對象,你必須至少提供兩個模板參數:所用的底層輸入流的迭代器類型,以及用作處理器引擎單詞源的lexer迭代器類型。

Do not instantiate the main preprocessing iterators yourself. Get them from the boost::wave::context object instead. The following code snippet is taken from the quick_start sample, which shows a minimal usage scenario for Wave.
你不要自己來實例化主預處理迭代器。而應從boost::wave::context對像獲取它們。以下代碼片斷取自於quick_start示例,示範了Wave的一個最小的用例。

 // The following preprocesses a given input file.
// Open the file and read it into a string variable
// 以下對給定的輸入文件進行預處理。打開該文件並將它讀入到一個字符串變量
std::ifstream instream("input.cpp");
std::string input(
std::istreambuf_iterator<char>
(instream.rdbuf()),
std::istreambuf_iterator<char>());

// The template boost::wave::cpplexer::lex_token<> is the
// token type to be used by the Wave library.
// This token type is one of the central types throughout
// the library, because it is a template parameter to some
// of the public classes and templates and it is returned
// from the iterators.
// The template boost::wave::cpplexer::lex_iterator<> is
// the lexer iterator to use as the token source for the
// preprocessing engine. In this case this is parametrized
// with the token type.
// 模板 boost::wave::cpplexer::lex_token<> 是Wave庫所使用的單
//
詞類型。該單詞類型是本庫的核心類型之一,因為它是某些公用類和模板的
//
模板參數,並且是從迭代器返回的。
// 模板 boost::wave::cpplexer::lex_iterator<> 是用作預處理器
// 引擎單詞源的lexer迭代器。在本例中它是以單詞類型進行參數化的。
typedef boost::wave::cpplexer::lex_iterator<
boost::wave::cpplexer::lex_token<> >
lex_iterator_type;
typedef boost::wave::context<
std::string::iterator, lex_iterator_type>
context_type;
context_type ctx(input.begin(), input.end(), "input.cpp");

// At this point you may want to set the parameters of the
// preprocessing as include paths and/or predefined macros.
// 在此處你可能想設置預處理的參數,如包含路徑和/或預定義宏。
ctx.add_include_path("...");
ctx.add_macro_definition(...);

// Get the preprocessor iterators and use them to generate
// the token sequence.
// 獲取預處理迭代器,並用它們來生成單詞序列。
context_type::iterator_type first = ctx.begin();
context_type::iterator_type last = ctx.end();

// The input stream is preprocessed for you during iteration
// over [first, last)
// 當對 [first, last) 進行迭代時,即為你對輸入流進行預處理
while (first != last) {
std::cout << (*first).get_value();
++first;
}

The constructor of the boost::wave::context object can take a pair of arbitrary iterator types (at least input_iterator type iterators) to the input stream, which must supply the data to be processed. The third parameter supplies a filename, which is reported in the preprocessor output to indicate the current context. Note though, that this filename is used only as long as no #include or #line directives are encountered, which in turn will alter the current reported filename.
boost::wave::context 對象的構造函數接受一對指向輸入流的任意迭代器類型(至少是 input_iterator 類型的迭代器),它們必須提供要進行處理的數據。第三個參數提供一個文件名,用於在預處理器輸出的報告中表示當前的上下文。不過請注意,這個文件名僅用於沒有 #include#line 指令的情況,否則將改變當前報告的文件名。

The iteration over the preprocessed tokens is relatively straightforward. Just get the starting and the ending iterators from the context object (maybe after initializing some include search paths) and you are done! Dereferencing the iterator will return the preprocessed tokens generated on the fly from the input stream. (To get further information about the token type, you may want to look here.)
對預處理單詞的迭代是比較簡單的。只需要從上下文對像(可能是在初始化一些包含查找路徑之後)獲得開始和結束迭代器就可以了!對迭代器的提領將返回從輸入流就地生成的預處理單詞。(有關單詞類型的更多信息,你可在這裡找到)。