Skip to content

Commit

Permalink
Merge pull request #21 from Bagira80/additions_to_fix_for_issue11224
Browse files Browse the repository at this point in the history
Addition to fix / workaround for issue #11224.
  • Loading branch information
eldiener committed May 20, 2015
2 parents dd5f2d9 + 7c9701e commit b4fe64a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
17 changes: 11 additions & 6 deletions preprocessed/README.txt
Expand Up @@ -2,14 +2,19 @@ Pre-processing of MPL-containers
--------------------------------

Pre-processing of MPL-containers can be accomplished using the script
"boost_mpl_preprocess.py". In the simplest case call it with a single
"boost_mpl_preprocess.py". In the simple case call it with a single
argument which is the path to the source-directory of Boost.

python boost_mpl_preprocess.py <path-to-boost-sourcedir>

This will pre-process all four MPL-container types (vector, list, set,
map) and makes them able to hold up to 100 elements. They can be used
either in their 'numbered' or their 'variadic' form.
If the Boost source-directory is the one this script resides in, you
can just call it without any arguments.

python boost_mpl_preprocess.py

Either way, this will pre-process all four MPL-container types (vector,
list, set, map) and makes them able to hold up to 100 elements. They can
be used either in their 'numbered' or their 'variadic' form.

Additionally, the script also allows more fine-grained pre-processing.
The maximal number of elements an MPL-container type is able to hold can
Expand All @@ -31,8 +36,8 @@ input source-files prior to pre-processing (by implicitly calling script
"fix_boost_mpl_preprocess.py" with the chosen settings). It only patches
the source-files needed for pre-processing the selected MPL-container
types and their selected form ('numbered' or 'variadic').
If calling it with a single argument (as in the former section) all input
source-files will be patched automatically.
If calling it with a single (or no) argument (as in the former section)
all input source-files will be patched automatically.

Instead of fixing the input-files implicitly during pre-processing one
can also fix them explicitly by calling "fix_boost_mpl_preprocess.py"
Expand Down
33 changes: 29 additions & 4 deletions preprocessed/boost_mpl_preprocess.py
Expand Up @@ -72,6 +72,21 @@ def adjust_container_limits_for_variadic_sequences(headerDir, containers, maxEle
print(line)


def current_boost_dir():
"""Returns the (relative) path to the Boost source-directory this file is located in (if any)."""
# Path to directory containing this script.
path = os.path.dirname( os.path.realpath(__file__) )
# Making sure it is located in "${boost-dir}/libs/mpl/preprocessed".
for directory in reversed( ["libs", "mpl", "preprocessed"] ):
(head, tail) = os.path.split(path)
if tail == directory:
path = head
else:
return None
return os.path.relpath( path )



def to_positive_multiple_of_10(string):
"""Converts a string into its encoded positive integer (greater zero) or throws an exception."""
try:
Expand All @@ -96,7 +111,12 @@ def to_existing_absolute_path(string):

def main():
"""The main function."""


# Find the current Boost source-directory in which this script is located.
sourceDir = current_boost_dir()
if sourceDir == None:
sourceDir = ""

# Prepare and run cmdline-parser.
cmdlineParser = argparse.ArgumentParser(description="A generator-script for pre-processed Boost.MPL headers.")
cmdlineParser.add_argument("-v", "--verbose", dest='verbose', action='store_true',
Expand All @@ -117,9 +137,9 @@ def main():
cmdlineParser.add_argument("--num-elements", dest='numElements', metavar="<num-elements>",
type=to_positive_multiple_of_10, default=100,
help="The maximal number of elements per container sequence. (Default=100)")
cmdlineParser.add_argument(dest='sourceDir', metavar="<source-dir>",
cmdlineParser.add_argument(dest='sourceDir', metavar="<source-dir>", default=current_boost_dir(), nargs='?',
type=to_existing_absolute_path,
help="The source-directory of Boost.")
help="The source-directory of Boost. (Default=\"" + sourceDir + "\")")
args = cmdlineParser.parse_args()

# Some verbose debug output.
Expand All @@ -134,7 +154,12 @@ def main():
print " want: set = ", args.want_set
print " want: map = ", args.want_map

# The directories for header- and source files of Boost.MPL.
# Verify that we received any source-directory.
if args.sourceDir == None:
print "You should specify a valid path to the Boost source-directory."
sys.exit(0)

# The directories for header- and source files of Boost.MPL.
# NOTE: Assuming 'args.sourceDir' is the source-directory of the entire boost project.
headerDir = os.path.join( args.sourceDir, "boost", "mpl" )
sourceDir = os.path.join( args.sourceDir, "libs", "mpl", "preprocessed" )
Expand Down

0 comments on commit b4fe64a

Please sign in to comment.