Quick Links: |
#include <bsls_bslsourcenameparserutil.h>
Public Types | |
enum | SourceTypes { k_MASK_KIND = 0x3, k_MASK_TEST = 0x2, k_HEADER = 0x0, k_IMPL = 0x1, k_TTEST = 0x2, k_GTEST = 0x3, k_IS_MULTIFILE_TEST = 0x4, k_IS_SUBORDINATE_TEST = 0x8, k_IS_CPP03_GENERATED = 0x10 } |
Static Public Member Functions | |
static int | getComponentName (const char **componentNamePtr, size_t *componentNameLength, const char *sourceName, unsigned *type_p=0) |
static const char * | errorMessage (int errorCode) |
This struct
provides a namespace for static
utility functions that parse source file names (as may be reported by the __FILE__
macro), including Lakos-style component source and test driver names.
See Component bsls_bslsourcenameparserutil
Bit masks and constants that describe the meaning of the type_p
parameter of getComponentName
below. Only some bits of the lowest significant word are used at the moment: .. 7 6 5 4 3 2 10 |r|r|r|3|S|M|KK|
K - two bits describing the extension (kind)
M - a bit that is set only the file is a test driver source file, and it is a multi-file test driver that has a "segment" of (normally) decimal digits, e.g., "abcx_name.14.g.cpp".
S - a bit that is set if the file belongs to a subordinate test driver, a file that has "_test", followed by non-underscore characters (except if it is also a generated simulation file for C++03, see below)
3 - a bit that is set if the file name is a generated simulation file for C++03 (simulates some C++11 features such as variadic templates up to a certain number of parameters etc)
r - all other bits are reserved for future use .. For example "abcx_name_testq_cpp03.g.cpp" will be
static int bsls::BslSourceNameParserUtil::getComponentName | ( | const char ** | componentNamePtr, | |
size_t * | componentNameLength, | |||
const char * | sourceName, | |||
unsigned * | type_p = 0 | |||
) | [static] |
Parse the specified Lakos-style sourceName
source file name with optional path portion to find the component name part. Return zero on success and a non-zero value if parsing failed. In case of success, fill the specified componentNamePtr
with a pointer to the first character, and the specified componentNameLength
with the number of character of the component name found. Optionally specify type_p
. When type_p
is not 0 set the bits of the pointed unsigned
, according to SourceTypes
, that describe the type of the source file that was parsed.
This function does not validate its input, it assumes that it is a valid Lakos-style component source or test driver file name, or one of the special names defined by John Lakos: Large Scale C++ Design (application, adapter, etc). If SourceName
is not as such, the function may return a non-zero error value, or it may report success with its output is unspecified.
Subordinate test component sources are special, as they should not contain code, only their test drivers. The component name reported for subordinate test drivers is the main component name.
Use the errorMessage
function (in this utility) to get a static, brief English textual description of a negative return value.
static const char* bsls::BslSourceNameParserUtil::errorMessage | ( | int | errorCode | ) | [static] |
Return a static, brief English error message that describes the specified negative parsing errorCode
. The behavior is undefined unless errorCode < 0
and was returned by one of the parsing methods (of this utility) that states in its contract to use this method to get the description of an error code.