boost :: mpl:如何为具有超过50个条目的列表生成预生成的头文件? [英] boost::mpl: How to generate pre-generated header files for lists with more than 50 entries?

查看:452
本文介绍了boost :: mpl:如何为具有超过50个条目的列表生成预生成的头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我发现这里一些python脚本为具有超过50个条目的列表生成头文件。



但我不能管理生成一个单一的头文件。有人可以向我解释如何使用这些脚本?我也没有在提升文档中找到任何帮助。



任何帮助将不胜感激。

解决方案

重要更新:



一个更好的脚本,只需要一个有效的 python 环境在此答案中对此问题进行了说明。



原始答案



查看我的 answer 到您的问题



以下bash代码将为51到100个条目生成MPL容器。如果你不关心其他MPL容器类型,只是想生成MPL列表,相应地调整 CONTAINERS 的值。

 #! / bin / bash 

#此脚本的名称。
SCRIPT_NAME = $(基本名称$ 0)
#此脚本的使用消息。
USAGE =用法:$ {SCRIPT_NAME}< path-to-boost-source> [< new-value-for BOOST_MPL_LIMIT_VECTOR_SIZE>]

#脚本参数:
#包含Boost源的目录的(绝对)路径。
SOURCE = $(readlink -e$ 1)
#Boost.MPL的向量的新限制。
NEW_BOOST_MPL_LIMIT_VECTOR_SIZE = $ 2

#检查参数的有效性。
if [[-z$ {SOURCE}]] || ! [[-d$ {SOURCE}]];然后
echo缺少Boost目录的路径。
echo $ {USAGE}
exit
fi
REGEX_INTEGER ='^ [0-9] + $'
如果[[-n$ {NEW_BOOST_MPL_LIMIT_VECTOR_SIZE} ]]&& ! [[$ {NEW_BOOST_MPL_LIMIT_VECTOR_SIZE} =〜$ {REGEX_INTEGER}]];然后
echoBOOST_MPL_LIMIT_VECTOR_SIZE的新大小必须是无符号整数!
echo $ {USAGE}
exit
fi


#Boost.MPL容器,对其进行了更多的预处理
#header-files应生成。
CONTAINERS =vector list set map
#没有Boost.MPL-map的相同容器。
CONTAINERS_WITHOUT_MAP = $(echo $ {CONTAINERS} | sed's / map // g')

#切换到Boost.MPL的include目录。
pushd $ {SOURCE} / boost / mpl> / dev / null 2>& 1

#可能改变Boost.MPL向量的限制。
if [[-n$ {NEW_BOOST_MPL_LIMIT_VECTOR_SIZE}]];
sed -i / s / \(define \s\ + BOOST_MPL_LIMIT_VECTOR_SIZE \s\ + \)[0-9] \ + / \1 $ {NEW_BOOST_MPL_LIMIT_VECTOR_SIZE} /。 /limits/vector.hpp
fi

#为每个具有60到100个元素
#的MPL容器创建hpp文件,这将在生成期间使用。
用于$ {CONTAINERS}中的容器; do
for i in {6..10}; do
sed -es / 50 / $ {i} 0 / g\
-es / 41 / $((i-1))1 / g\
-es / 40 / $((i-1))0 / g\
./${container}/${container}50.hpp \
> ./${container}/${container}${i}0.hpp;
done
done
for container in $ {CONTAINERS_WITHOUT_MAP}; do
for i in {6..10}; do
sed -es / 50 / $ {i} 0 / g\
-es / 41 / $((i-1))1 / g\
-es / 40 / $((i-1))0 / g\
./${container}/${container}50_c.hpp \
> ./${container}/${container}${i}0_c.hpp;
done
done

#保留Boost.MPL的include目录。
popd> / dev / null 2>& 1
#更改为Boost.MPL的源目录。
pushd $ {SOURCE} / libs / mpl / preprocessed> / dev / null 2>& 1

#使用60到100个元素为每个MPL容器创建cpp文件
#将在生成期间使用。
用于$ {CONTAINERS}中的容器; do
for i in {6..10}; do
sed -es / 50 / $ {i} 0 / g\
-es / 41 / $((i-1))1 / g\
-es / 40 / $((i-1))0 / g\
./${container}/${container}50.cpp \
> ./${container}/${container}${i}0.cpp;
done
done
for container in $ {CONTAINERS_WITHOUT_MAP}; do
for i in {6..10}; do
sed -es / 50 / $ {i} 0 / g\
-es / 41 / $((i-1))1 / g\
-es / 40 / $((i-1))0 / g\
./${container}/${container}50_c.cpp \
> ./${container}/${container}${i}0_c.cpp;
done
done

#现在使用python脚本生成MPL预处理的文件。
python preprocess_vector.py all $ {SOURCE}
python preprocess_list.py all $ {SOURCE}
python preprocess_set.py all $ {SOURCE}
python preprocess_map.py all $ { SOURCE}
python preprocess.py all $ {SOURCE}

#离开Boost.MPL的源目录。
popd> / dev / null 2>& 1

超过100个条目,请调整for-loops中的范围。



我希望能帮助您。

Deniz



更新:



我意识到我的原始版本的脚本只生成编号版本的MPL-容器头。



我通过添加 python preprocess.py all $ {SOURCE} 接近脚本的结尾。
然而,这只会在生成相应的宏设置(例如 BOOST_MPL_LIMIT_VECTOR_SIZE )时生成未编号的MPL-容器头的修改版本



这些修改可以在 user.hpp 文件中的每个子目录中进行, code> $ {SOURCE} / libs / mpl / preprocessed / include



b
$ b

  #define BOOST_MPL_LIMIT_VECTOR_SIZE 30 

$ {SOURCE} /libs/mpl/preprocessed/include/gcc/user.hpp boost :: mpl :: vector (包含 boost / mpl / vector.hpp )现在可以保存30个元素,而不是默认的20。



注意:



但是,可能不会调整 BOOST_MPL_LIMIT_VECTOR_SIZE 仅用于生成,并保留其在 $ {SOURCE} /boost/mpl/limits/vector.hpp 中定义的值。 />
可能,这甚至不编译,因为底层的 boost :: mpl :: vector21 boost :: mpl :: vectorN 无法找到(因为不会自动包含)。
最佳解决方案可能是调整 $ {SOURCE} /boost/mpl/limits/vector.hpp 中的值。如果给出第二个(可选)参数,上述bash脚本可以自动执行。


I want to code a state machine which has a reaction list with more than 50 entries.

I found here some python scripts to generate header files for lists with more than 50 entries.

But I cannot manage to generate a single header file. Can someone please explain to me how to use theses scripts? I also didn't find any help in boost documention.

Any help would be appreciated.

解决方案

Important Update:

A more improved script, which only requires a working python environment is described in this answer to this question.

Original Answer

See my answer to your question on the Boost mailing-list.

The following bash-code will generate the MPL-containers for 51 to 100 entries. If you do not care about the other MPL-container types and just want to generate MPL-lists, adjust the value of CONTAINERS accordingly.

#! /bin/bash

# The name of this script.
SCRIPT_NAME=$(basename $0)
# The usage message for this script.
USAGE="Usage:  ${SCRIPT_NAME} <path-to-boost-source> [<new-value-for BOOST_MPL_LIMIT_VECTOR_SIZE>]"

# Script-arguments:
# The (absolute) path to the directory containing the Boost-source.
SOURCE=$(readlink -e "$1")
# The new limit for Boost.MPL's vector.
NEW_BOOST_MPL_LIMIT_VECTOR_SIZE=$2

# Check validity of arguments.
if [[ -z "${SOURCE}" ]] || ! [[ -d "${SOURCE}" ]]; then
  echo "Missing path to Boost directory."
  echo ${USAGE}
  exit
fi
REGEX_INTEGER='^[0-9]+$'
if [[ -n "${NEW_BOOST_MPL_LIMIT_VECTOR_SIZE}" ]] && ! [[ ${NEW_BOOST_MPL_LIMIT_VECTOR_SIZE} =~ ${REGEX_INTEGER} ]]; then
  echo "New size for BOOST_MPL_LIMIT_VECTOR_SIZE must be an unsigned integer!"
  echo ${USAGE}
  exit
fi


# The Boost.MPL-containers for which more preprocessed
# header-files shall be generated.
CONTAINERS="vector list set map"
# The same containers without Boost.MPL-map.
CONTAINERS_WITHOUT_MAP=$(echo ${CONTAINERS} | sed 's/map//g')

# Change into include-directory of Boost.MPL.
pushd ${SOURCE}/boost/mpl  >/dev/null 2>&1

# Possibly change the limit for Boost.MPL's vector.
if [[ -n "${NEW_BOOST_MPL_LIMIT_VECTOR_SIZE}" ]]; then
  sed -i "s/\(define\s\+BOOST_MPL_LIMIT_VECTOR_SIZE\s\+\)[0-9]\+/\1${NEW_BOOST_MPL_LIMIT_VECTOR_SIZE}/" ./limits/vector.hpp
fi

# Create hpp-files for each MPL-container with 60 to 100 elements
# which will be used during generation.
for container in ${CONTAINERS}; do
  for i in {6..10}; do
    sed -e "s/50/${i}0/g" \
        -e "s/41/$((i-1))1/g" \
        -e "s/40/$((i-1))0/g" \
        ./${container}/${container}50.hpp \
      > ./${container}/${container}${i}0.hpp;
  done
done
for container in ${CONTAINERS_WITHOUT_MAP}; do
  for i in {6..10}; do
    sed -e "s/50/${i}0/g" \
        -e "s/41/$((i-1))1/g" \
        -e "s/40/$((i-1))0/g" \
        ./${container}/${container}50_c.hpp \
      > ./${container}/${container}${i}0_c.hpp;
  done
done

# Leave include-directory of Boost.MPL.
popd  >/dev/null 2>&1
# Change into source-directory of Boost.MPL.
pushd ${SOURCE}/libs/mpl/preprocessed  >/dev/null 2>&1

# Create cpp-files for each MPL-container with 60 to 100 elements
# which will be used during generation.
for container in ${CONTAINERS}; do
  for i in {6..10}; do
    sed -e "s/50/${i}0/g" \
        -e "s/41/$((i-1))1/g" \
        -e "s/40/$((i-1))0/g" \
        ./${container}/${container}50.cpp \
      > ./${container}/${container}${i}0.cpp;
  done
done
for container in ${CONTAINERS_WITHOUT_MAP}; do
  for i in {6..10}; do
    sed -e "s/50/${i}0/g" \
        -e "s/41/$((i-1))1/g" \
        -e "s/40/$((i-1))0/g" \
        ./${container}/${container}50_c.cpp \
      > ./${container}/${container}${i}0_c.cpp;
  done
done

# Now generate MPL-preprocessed files using the python-scripts.
python preprocess_vector.py all ${SOURCE}
python preprocess_list.py   all ${SOURCE}
python preprocess_set.py    all ${SOURCE}
python preprocess_map.py    all ${SOURCE}
python preprocess.py        all ${SOURCE}

# Leave source-directory of Boost.MPL.
popd  >/dev/null 2>&1

For even bigger containers with more than 100 entries, adjust the range in the for-loops.

I hope that helps.
Deniz

Update:

I realized that my original version of the script did only generate the numbered versions of the MPL-container headers. However, it did not update the non-numbered versions.

I fixed it by adding python preprocess.py all ${SOURCE} near the end of the script. However, this does only generate modified versions of the non-numbered MPL-container headers if during generation the corresponding macro settings (e.g. a higher value for BOOST_MPL_LIMIT_VECTOR_SIZE) are different than the original values.

These modifications can be made in the file user.hpp within each subdirectory of ${SOURCE}/libs/mpl/preprocessed/include.

For example, by adding

#define BOOST_MPL_LIMIT_VECTOR_SIZE 30

to ${SOURCE}/libs/mpl/preprocessed/include/gcc/user.hpp the boost::mpl::vector (included from boost/mpl/vector.hpp) is able to hold 30 elements, now, instead of the default 20.

Note:

However, it might not be a good idea to adjust values like BOOST_MPL_LIMIT_VECTOR_SIZE only for generation and leave its value defined in ${SOURCE}/boost/mpl/limits/vector.hpp untouched.
Possibly, this does not even compile because the underlying boost::mpl::vector21 to boost::mpl::vectorN cannot be found (because not being included automatically). Best solution is probably to adjust the value in ${SOURCE}/boost/mpl/limits/vector.hpp. The above bash-script can automatically do so, if the second (optional) argument is given.

这篇关于boost :: mpl:如何为具有超过50个条目的列表生成预生成的头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆