diff --git a/preprocessed/README.txt b/preprocessed/README.txt index caa8691..75ae37f 100644 --- a/preprocessed/README.txt +++ b/preprocessed/README.txt @@ -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 -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 @@ -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" diff --git a/preprocessed/boost_mpl_preprocess.py b/preprocessed/boost_mpl_preprocess.py index 1724c32..72a18ab 100755 --- a/preprocessed/boost_mpl_preprocess.py +++ b/preprocessed/boost_mpl_preprocess.py @@ -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: @@ -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', @@ -117,9 +137,9 @@ def main(): cmdlineParser.add_argument("--num-elements", dest='numElements', metavar="", 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="", + cmdlineParser.add_argument(dest='sourceDir', metavar="", 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. @@ -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" )