gpt4 book ai didi

c++ - 具有虚拟文件系统的 c 预处理器

转载 作者:太空宇宙 更新时间:2023-11-04 02:05:36 24 4
gpt4 key购买 nike

我想找一个预处理c文件的库,具有以下特点:

  1. 过程定义
  2. 过程包括

我想要的小例子:

输入

some_file.h

some_code

主程序

#if SOME_DEFINE == TRUE
#inlcude "some_file.h"
#else
#endif
...

输出(SOME_DEFINE = TRUE)主程序

some_code
...

似乎 boost::wave 非常适合它。但是我想要更多:包含文件的虚拟文件系统。所以预处理器将从内存中的虚拟文件系统中获取包含文件,而不是从硬盘中获取。当我必须用很多不同的定义预处理同一个文件时,我需要它进行更快的预处理。

所以问题是:是否存在像 boost::wave 这样的库,但支持虚拟文件系统?或者 boost::wave 以某种方式支持它?

最佳答案

从文档到 Boost Wave:

The Input Policy

The input policy type may be specified as a template parameter to the wave::context object and is used for customizing the way, how an included file is to be represented by a pair of iterators pointing to the beginning and the end of the resulting input sequence. If this template parameter is not given while instantiating the context object, it defaults to the iteration_context_policies::load_file_to_string type.

因此 input_policy 看起来是您的扩展点。您可以通过将迭代器返回到用于演示目的的硬编码文本来测试它:

namespace boost { namespace wave { namespace iteration_context_policies {

struct hardcoded_header_policy {

template <typename IterContext>
class inner {

public:
// expose the begin and end iterators for the included file
template <typename Position>
static void init_iterators(IterContext &iter_ctx, Position const &act_pos)
{
typedef typename IterContext::iterator_type iterator_type;

iter_ctx.hard_coded_contents = "// header file '" << iter_ctx.filename << "' intentionally left blank\n";

iter_ctx.first = iterator_type(iter_ctx.hard_coded_contents.begin(), iter_ctx.hard_coded_contents.end(), PositionT(iter_ctx.filename));
iter_ctx.last = iterator_type();
}

private:
std::string hard_coded_contents;
};
};

} } }

关于c++ - 具有虚拟文件系统的 c 预处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20947464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com