// file : build/config/utility -*- C++ -*- // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file #ifndef BUILD_CONFIG_UTILITY #define BUILD_CONFIG_UTILITY #include #include #include // pair #include #include namespace build { class scope; class list_value; namespace config { // Set, if necessary, a required config.* variable. // // Return the reference to the value as well as the indication of // whether the variable has actually been set. // template std::pair required (scope& root, const char* name, const T& default_value); std::pair required (scope& root, const char* name, const char* default_value); // Set, if necessary, an optional config.* variable. In particular, // an unspecified variable is set to NULL which is used to to // distinguish between the "configured as unspecified" and "not // yet configured" cases. // // Return the pointer to the value, which can be NULL. // template const T* optional (scope& root, const char* name); // Add all the values from a variable to the C-string list. T is // either target or scope. // template void append_options (std::vector& args, T& s, const char* var) { if (auto val = s[var]) { for (const name& n: val.template as ()) { if (n.simple ()) args.push_back (n.value.c_str ()); else if (n.directory ()) args.push_back (n.dir.string ().c_str ()); else fail << "expected option instead of " << n << info << "in variable " << var; } } } } } #include #endif // BUILD_CONFIG_UTILITY