BASIS  version 1.2.3 (revision 2104)
Classes | Modules | Files | Defines | Functions | Variables
C++ Utilities
BASIS Utilities

Auxiliary implementations for use in C++ source code. More...

+ Collaboration diagram for C++ Utilities:

Classes

class  sbia::basis::ExecutableTargetInfo
 Provides information about executable build targets. More...

Modules

 Command-line Parsing Library
 

Command-line parsing library for C++.


 Testing Framework
 

Testing framework for C++.


Files

file  basis.h
 

Main include file of BASIS C++ Utilities.


Defines

#define HAVE_LONG_LONG   1
 Whether the long long type is supported by the compiler.
#define HAVE_PTHREAD   1
 Whether the pthread library is available.
#define HAVE_SSTREAM   1
 Whether the ANSI string stream classes are available.
#define HAVE_STRSTREAM   0
 Whether the obsolete string stream classes are available.
#define HAVE_TR1_TUPLE   1
 Whether the tr1/tuple header file is available.
#define LINUX   (defined (linux) || defined (__linux))
 Whether the sources are compiled on a Linux system.
#define MACOS   (defined (__APPLE__) || defined (__OSX__))
 Whether the sources are compiled on a Mac OS system.
#define SBIA_BASIS_NAMESPACE   ::sbia::basis
 Full project own namespace identifier.
#define SBIA_BASIS_NAMESPACE_BEGIN   namespace sbia { namespace basis {
 Macro used to enter project own namespace.
#define SBIA_BASIS_NAMESPACE_END   } }
 Macro used to exit project own namespace.
#define UNIX   (!WINDOWS)
 Whether the sources are compiled on a Unix-based system.
#define WINDOWS   (defined (_WIN32) || defined (WIN32) || defined (_WINDOWS))
 Whether the sources are compiled on a Windows system.

Functions

int sbia::basis::execute_process (const std::string &cmd, bool quiet=false,std::ostream *out=NULL, bool allow_fail=false, int verbose=0, bool simulate=false)
 Execute command as subprocess.
int sbia::basis::execute_process (std::vector< std::string > &args, bool quiet=false,std::ostream *out=NULL, bool allow_fail=false, int verbose=0, bool simulate=false)
 Execute command as subprocess.
bool sbia::basis::executing_in_build_tree ()
 Whether the executable was executed from within the build tree.
string sbia::basis::get_data_directory ()
 Get absolute path of directory containing auxiliary data.
string sbia::basis::get_executable_path (const std::string &target)
 Get canonical path of executable file.
string sbia::basis::get_installation_prefix ()
 Get absolute path of installation directory.
string sbia::basis::get_libexec_directory ()
 Get absolute path of directory containing auxiliary executables.
string sbia::basis::get_library_directory ()
 Get absolute path of directory containing libraries.
string sbia::basis::get_runtime_directory ()
 Get absolute path of directory containing runtime executables.
void sbia::basis::print_contact (const char *contact=NULL)
 Print contact information.
void sbia::basis::print_version (const char *name, const char *copyright=NULL, const char *license=NULL)
 Print version information.

Variables

 PROJECT_NAMESPACE_CXX
 CMake variable of C++ namespace of project.

Detailed Description

Auxiliary implementations for use in C++ source code.


Define Documentation

#define HAVE_STRSTREAM   0

Whether the obsolete string stream classes are available.

Note:
As the strstream implementations are obsolete already for a long time, this macro always evaluates to 0.

Definition at line 73 of file config.h.

#define HAVE_TR1_TUPLE   1

Whether the tr1/tuple header file is available.

Note:
This header file is only more recently supported by compilers and be used by Google Test, for example. If not supported by the compiler, Google Test can use it's own implementation.

Definition at line 90 of file config.h.

#define SBIA_BASIS_NAMESPACE   ::sbia::basis

Full project own namespace identifier.

This macro should preferably be used when referring to the project own namespace. The namespace can then be renamed later on without affecting written source code.

Note:
Namespace identifier may reflect a nested namespace.

Definition at line 106 of file config.h.

#define SBIA_BASIS_NAMESPACE_BEGIN   namespace sbia { namespace basis {

Macro used to enter project own namespace.

Example:

 SBIA_BASIS_NAMESPACE_BEGIN

 // project source code within project own namespace

 SBIA_BASIS_NAMESPACE_END

Definition at line 121 of file config.h.

#define SBIA_BASIS_NAMESPACE_END   } }

Macro used to exit project own namespace.

Example:

 SBIA_BASIS_NAMESPACE_BEGIN

 // project source code within project own namespace

 SBIA_BASIS_NAMESPACE_END

Definition at line 136 of file config.h.


Function Documentation

int sbia::basis::execute_process ( const std::string &  cmd,
bool  quiet = false,
std::ostream *  out = NULL,
bool  allow_fail = false,
int  verbose = 0,
bool  simulate = false 
)

Execute command as subprocess.

This function is a replacement for system() on Unix and is furthermore less platform dependent. The first argument of the given command-line string is mapped to an absolute executable file using get_executable_path() if the given first argument is a know build target name. Otherwise, the command-line is used unmodified.

Parameters:
[in]cmdCommand-line given as double quoted string. Arguments containing whitespaces have to be quoted using double quotes. Use a backslash (\) to escape double quotes inside an argument as well as to escape a backslash itself (required if backslash at end of double quoted argument, e.g., "this argument \\").
[in]quietTurns off output of stdout of child process to stdout of parent process.
[out]outOutput stream where command output is written to.
[in]allow_failIf true, no exception is thrown if the exit code of the child process is non-zero. Otherwise, a SubprocessException object is thrown in that case.
[in]verboseVerbosity of output messages. Does not affect verbosity of executed command.
[in]simulateWhether to simulate command execution only.
Returns:
Exit code of command or -1 if subprocess creation failed.
Exceptions:
SubprocessExceptionIf subprocess creation failed or command returned a non-zero exit code while allow_fail is false.

Definition at line 155 of file stdaux.cxx.

int sbia::basis::execute_process ( std::vector< std::string > &  args,
bool  quiet = false,
std::ostream *  out = NULL,
bool  allow_fail = false,
int  verbose = 0,
bool  simulate = false 
)

Execute command as subprocess.

This function is a replacement for system() on Unix and is furthermore less platform dependent. The first argument of the given command-line string is mapped to an absolute executable file using get_executable_path() if the given first argument is a know build target name. Otherwise, the command-line is used unmodified.

Parameters:
[in,out]argsCommand-line given as argument vector. The first argument has to be either a build target name or the name/path of the command to execute. Note that as a side effect, the first argument of the input vector is replaced by the absolute path of the actual executable file if applicable.
[in]quietTurns off output of stdout of child process to stdout of parent process.
[out]outOutput stream where command output is written to.
[in]allow_failIf true, no exception is thrown if the exit code of the child process is non-zero. Otherwise, a SubprocessException object is thrown in that case.
[in]verboseVerbosity of output messages. Does not affect verbosity of executed command.
[in]simulateWhether to simulate command execution only.
Returns:
Exit code of command or -1 if subprocess creation failed.
Exceptions:
SubprocessExceptionIf subprocess creation failed or command returned a non-zero exit code while allow_fail is false.

Definition at line 163 of file stdaux.cxx.

bool sbia::basis::executing_in_build_tree ( )

Whether the executable was executed from within the build tree.

Returns:
Whether the executable was executed from within the build tree.

Definition at line 70 of file stdaux.cxx.

std::string sbia::basis::get_data_directory ( )

Get absolute path of directory containing auxiliary data.

Returns:
Absolute path of directory containing auxiliary data.

Definition at line 120 of file stdaux.cxx.

std::string sbia::basis::get_executable_path ( const std::string &  target)

Get canonical path of executable file.

This function uses the static instance of the class ExecutableTargetInfo in order to obtain the required information to be able to determine the absolute path of the executable file which was built and/or installed as the specified build target.

Note:
The BASIS path module provides a function also named get_executable_path() which can be used to get the canonical path of the calling executable.
See also:
ExecutableTargetInfo
Parameters:
[in]targetName/UID of build target.
Returns:
Absolute path of executable file or an empty string if the build target is not known.

Definition at line 134 of file stdaux.cxx.

std::string sbia::basis::get_installation_prefix ( )

Get absolute path of installation directory.

This function returns the absolute path of the installation prefix path. If the installation was not moved after a "make install", the returned directory corresponds to the value of the INSTALL_PREFIX CMake variable as specified during the build of the executable file. Note, however, that even when the installation tree was moved after the configuration and build of the software, the correct path is returned as long as the relative directory structure of the installation tree is maintained. This is because the path is determined relative to the directory of the executable itself, knowning in which path this executable is located relative to the INSTALL_PREFIX.

Note:
If the executable is executed from within the build tree, the returned path will not be correct. Therefore, only use this function when executing_in_build_tree() returns false. Otherwise, the configured absolute paths which are valid for the build tree have to be used. Note that the build tree is not supposed to be relocatable in any case as it is only a temporary directory tree and CMake requires it to be not moved anywhere else.
Returns:
Absolute path of top directory of installation tree.

Definition at line 80 of file stdaux.cxx.

std::string sbia::basis::get_libexec_directory ( )

Get absolute path of directory containing auxiliary executables.

Returns:
Absolute path of directory containing auxiliary executables.

Definition at line 100 of file stdaux.cxx.

std::string sbia::basis::get_library_directory ( )

Get absolute path of directory containing libraries.

Returns:
Absolute path of directory containing libraries.

Definition at line 110 of file stdaux.cxx.

std::string sbia::basis::get_runtime_directory ( )

Get absolute path of directory containing runtime executables.

Returns:
Absolute path of directory containing runtime executables.

Definition at line 90 of file stdaux.cxx.

void sbia::basis::print_contact ( const char *  contact = NULL)

Print contact information.

Parameters:
[in]contactName of the contact. Defaults to "SBIA Group <sbia-software at uphs.upenn.edu>".

Definition at line 58 of file stdaux.cxx.

void sbia::basis::print_version ( const char *  name,
const char *  copyright = NULL,
const char *  license = NULL 
)

Print version information.

Parameters:
[in]nameProgram name.
[in]copyrightCopyright notice. Defaults to University of Pennsylvania without year if NULL. If an empty string is given, i.e., copyright = "", no copyright notice is written.
[in]licenseLicense notice. Defaults to official software license used at SBIA if NULL. If an empty string is given, i.e., license = "", no license notice is written.

Definition at line 41 of file stdaux.cxx.


Variable Documentation

CMake variable of C++ namespace of project.

The C++ namespace of a BASIS project is made up of its name in lower case only as well as the namespace the project belongs to, i.e., the namespace of the project this project is a module of.

Example:

 namespace sbia {
 namespace basis {
 // your code goes here
 }
 }

Definition at line 145 of file ProjectSettings.cmake.