basis.h
Go to the documentation of this file.
00001 /** 00002 * @file basis.h 00003 * @brief BASIS utilities of BASIS project of BASIS package. 00004 * 00005 * @note The basis.h module was automatically generated by BASIS from the 00006 * template file basis.h.in which is part of the BASIS installation. 00007 * 00008 * This header file includes the header files of the remaining BASIS utilities. 00009 * Hence, it is sufficient to only include this header file. 00010 * 00011 * Copyright (c) 2011, 2012 University of Pennsylvania. All rights reserved.<br /> 00012 * See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file. 00013 * 00014 * Contact: SBIA Group <sbia-software at uphs.upenn.edu> 00015 * 00016 * @ingroup BasisCxxUtilities 00017 */ 00018 00019 #pragma once 00020 #ifndef _BASIS_BASIS_BASIS_H 00021 #define _BASIS_BASIS_BASIS_H 00022 00023 #include <basis/utilities.h> // project-independent utilities 00024 00025 00026 /// @addtogroup BasisCxxUtilities 00027 /// @{ 00028 00029 00030 namespace basis { 00031 00032 00033 // =========================================================================== 00034 // constants 00035 // =========================================================================== 00036 00037 /// @brief The project name. 00038 extern const char* PROJECT; 00039 /// @brief The version string given as "<major>.<minor>.<patch>". 00040 extern const char* VERSION; 00041 /// @brief The major version number. 00042 extern const unsigned int VERSION_MAJOR; 00043 /// @brief The minor version number. 00044 extern const unsigned int VERSION_MINOR; 00045 /// @brief The patch number. 00046 extern const unsigned int VERSION_PATCH; 00047 /// @brief Complete version information as output by --version option. 00048 extern const char* RELEASE; 00049 /// @brief Default copyright of executables. 00050 extern const char* COPYRIGHT; 00051 /// @brief Default license of executables. 00052 extern const char* LICENSE; 00053 /// @brief Default contact to use for help output of executables. 00054 extern const char* CONTACT; 00055 00056 // =========================================================================== 00057 // package directories 00058 // =========================================================================== 00059 00060 /** 00061 * @brief Get absolute path of directory containing runtime executables. 00062 * 00063 * @returns Absolute path of directory containing runtime executables. 00064 */ 00065 std::string bindir(); 00066 00067 /** 00068 * @brief Get absolute path of directory containing auxiliary executables. 00069 * 00070 * @returns Absolute path of directory containing auxiliary executables. 00071 */ 00072 std::string libexecdir(); 00073 00074 /** 00075 * @brief Get absolute path of directory containing libraries. 00076 * 00077 * @returns Absolute path of directory containing libraries. 00078 */ 00079 std::string libdir(); 00080 00081 /** 00082 * @brief Get absolute path of directory containing auxiliary data. 00083 * 00084 * @returns Absolute path of directory containing auxiliary data. 00085 */ 00086 std::string datadir(); 00087 00088 // =========================================================================== 00089 // executable information 00090 // =========================================================================== 00091 00092 /** 00093 * @brief Print contact information. 00094 * 00095 * @param [in] contact Name of contact. If @c NULL, CONTACT is used. 00096 */ 00097 void print_contact(const char* contact = NULL); 00098 00099 /** 00100 * @brief Print version information including copyright and license notices. 00101 * 00102 * @param [in] name Name of executable. Should not be set programmatically 00103 * to the first argument of the @c main() function, but 00104 * a string literal instead. 00105 * @param [in] version Version of executable, e.g., release of project 00106 * this executable belongs to. Defaults to RELEASE. 00107 * @param [in] project Name of project this executable belongs to. 00108 * If @c NULL, defaults to PROJECT. If an empty string, 00109 * no project information is printed. 00110 * @param [in] copyright The copyright notice, excluding the common prefix 00111 * "Copyright (c) " and suffix ". All rights reserved.". 00112 * If @c NULL, COPYRIGHT is used. If an empty string, 00113 * no copyright notice is printed. 00114 * @param [in] license Information regarding licensing. If @c NULL, LICENSE 00115 * is used. If an empty string, no license information 00116 * is printed. 00117 */ 00118 void print_version(const char* name, 00119 const char* version = NULL, 00120 const char* project = NULL, 00121 const char* copyright = NULL, 00122 const char* license = NULL); 00123 00124 /** 00125 * @brief Get UID of build target. 00126 * 00127 * The UID of a build target is its name prepended by a namespace identifier 00128 * which should be unique for each project. 00129 * 00130 * @param [in] name Name of build target. 00131 * 00132 * @returns UID of named build target. 00133 */ 00134 std::string targetuid(const std::string& name); 00135 00136 /** 00137 * @brief Determine whether a given build target is known. 00138 * 00139 * @param [in] name Name of build target. 00140 * 00141 * @returns Whether the named target is a known executable target. 00142 */ 00143 bool istarget(const std::string& name); 00144 00145 /** 00146 * @brief Get absolute path of executable file. 00147 * 00148 * This function determines the absolute file path of an executable. If no 00149 * arguments are given, the absolute path of this executable is returned. 00150 * If the command names a known executable build target, the absolute path to 00151 * the corresonding built (and installed) executable file is returned. 00152 * Otherwise, the named command is searched in the system @c PATH and its 00153 * absolute path returned if found. If the executable is not found, an 00154 * empty string is returned. 00155 * 00156 * @todo This function currently makes use of the which command implemented 00157 * in Python and called as subprocess in order to search a command 00158 * in the system @c PATH. This which command is part of BASIS and 00159 * can also be used on Windows. However, a native C++ implementation 00160 * would be desireable. 00161 * 00162 * @param [in] name Name of command or @c NULL. 00163 * 00164 * @returns Absolute path of executable or an empty string if not found. 00165 * If @p name is @c NULL, the path of this executable is returned. 00166 * 00167 * @sa exename() 00168 * @sa exedir() 00169 */ 00170 std::string exepath(const std::string& name = std::string()); 00171 00172 /** 00173 * @brief Get name of executable file. 00174 * 00175 * @note The name of the executable may or may not include the file name 00176 * extension depending on the executable type and operating system. 00177 * Hence, this function is neither an equivalent to 00178 * os::path::basename(exepath()) nor os::path::filename(exepath()). 00179 * In particular, on Windows, the .exe and .com extension is not 00180 * included in the returned executable name. 00181 * 00182 * @param [in] name Name of command or @c NULL. 00183 * 00184 * @returns Name of executable file or an empty string if not found. 00185 * If @p name is @c NULL, the name of this executable is returned. 00186 * 00187 * @sa exepath() 00188 */ 00189 std::string exename(const std::string& name = std::string()); 00190 00191 /** 00192 * @brief Get directory of executable file. 00193 * 00194 * @param [in] name Name of command or @c NULL. 00195 * 00196 * @returns Absolute path of directory containing executable or an empty string if not found. 00197 * If @p name is @c NULL, the directory of this executable is returned. 00198 * 00199 * @sa exepath() 00200 */ 00201 std::string exedir(const std::string& name = std::string()); 00202 00203 // =========================================================================== 00204 // command execution 00205 // =========================================================================== 00206 00207 /** 00208 * @brief Execute command as subprocess. 00209 * 00210 * This function is a replacement for system() on Unix and is furthermore 00211 * less platform dependent. The first argument of the given command-line string 00212 * is mapped to an absolute executable file using exepath() if the given first 00213 * argument is a know build target name. Otherwise, the command-line is used 00214 * unmodified. 00215 * 00216 * @param [in] cmd Command-line given as double quoted string. Arguments 00217 * containing whitespaces have to be quoted using double 00218 * quotes. Use a backslash (\\) to escape double quotes 00219 * inside an argument as well as to escape a backslash 00220 * itself (required if backslash at end of double quoted 00221 * argument, e.g., "this argument \\"). 00222 * @param [in] quiet Turns off output of stdout of child process to stdout 00223 * of parent process. 00224 * @param [out] out Output stream where command output is written to. 00225 * @param [in] allow_fail If true, no exception is thrown if the exit code 00226 * of the child process is non-zero. Otherwise, 00227 * a SubprocessException object is thrown in that case. 00228 * @param [in] verbose Verbosity of output messages. Does not affect 00229 * verbosity of executed command. 00230 * @param [in] simulate Whether to simulate command execution only. 00231 * 00232 * @returns Exit code of command or -1 if subprocess creation failed. 00233 * 00234 * @throws SubprocessError If subprocess creation failed or command returned 00235 * a non-zero exit code while @p allow_fail is false. 00236 */ 00237 int execute(const std::string& cmd, 00238 bool quiet = false, 00239 // attention: stdout is a macro defined by windows.h 00240 std::ostream* out = NULL, 00241 bool allow_fail = false, 00242 int verbose = 0, 00243 bool simulate = false); 00244 00245 /** 00246 * @brief Execute command as subprocess. 00247 * 00248 * This function is a replacement for system() on Unix and is furthermore 00249 * less platform dependent. The first argument of the given command-line string 00250 * is mapped to an absolute executable file using exepath() if the given first 00251 * argument is a know build target name. Otherwise, the command-line is used 00252 * unmodified. 00253 * 00254 * @param [in,out] args Command-line given as argument vector. The first 00255 * argument has to be either a build target name or the 00256 * name/path of the command to execute. 00257 * @param [in] quiet Turns off output of stdout of child process to 00258 * stdout of parent process. 00259 * @param [out] out Output stream where command output is written to. 00260 * @param [in] allow_fail If true, no exception is thrown if the exit code 00261 * of the child process is non-zero. Otherwise, 00262 * a SubprocessException object is thrown in that case. 00263 * @param [in] verbose Verbosity of output messages. Does not affect 00264 * verbosity of executed command. 00265 * @param [in] simulate Whether to simulate command execution only. 00266 * 00267 * @returns Exit code of command or -1 if subprocess creation failed. 00268 * 00269 * @throws SubprocessError If subprocess creation failed or command returned 00270 * a non-zero exit code while @p allow_fail is false. 00271 */ 00272 int execute(std::vector<std::string> args, 00273 bool quiet = false, 00274 // attention: stdout is a macro defined by windows.h 00275 std::ostream* out = NULL, 00276 bool allow_fail = false, 00277 int verbose = 0, 00278 bool simulate = false); 00279 00280 00281 } // end of namespaces 00282 00283 00284 /// @} 00285 // end of Doxygen group 00286 00287 00288 #endif // _BASIS_BASIS_BASIS_H