BDE 4.14.0 Production release
|
#include <bslim_printer.h>
Public Member Functions | |
Printer (bsl::ostream *stream, int level, int spacesPerLevel) | |
~Printer () | |
Destroy this Printer object. | |
int | absLevel () const |
void | end (bool suppressBracket=false) const |
template<class TYPE > | |
void | print (const TYPE &data, const char *name) const |
template<class TYPE > | |
void | printAttribute (const bslstl::StringRef &name, const TYPE &data) const |
template<class ITERATOR > | |
void | printAttribute (const bslstl::StringRef &name, const ITERATOR &begin, const ITERATOR &end) const |
template<class ITERATOR , class PRINT_FUNCTOR > | |
void | printAttribute (const bslstl::StringRef &name, const ITERATOR &begin, const ITERATOR &end, const PRINT_FUNCTOR &printFunctionObject) const |
void | printEndIndentation () const |
template<class TYPE , class PRINT_FUNCTOR > | |
void | printForeign (const TYPE &data, const PRINT_FUNCTOR &printFunctionObject, const char *name) const |
void | printHexAddr (const void *address, const char *name) const |
void | printIndentation () const |
template<class TYPE > | |
void | printOrNull (const TYPE &address, const char *name) const |
template<class TYPE > | |
void | printValue (const TYPE &data) const |
template<class ITERATOR > | |
void | printValue (const ITERATOR &begin, const ITERATOR &end) const |
template<class ITERATOR , class PRINT_FUNCTOR > | |
void | printValue (const ITERATOR &begin, const ITERATOR &end, const PRINT_FUNCTOR &printFunctionObject) const |
int | spacesPerLevel () const |
void | start (bool suppressBracket=false) const |
bool | suppressInitialIndentFlag () const |
template<> | |
void | printOrNull (const void *const &address, const char *name) const |
template<> | |
void | printOrNull (void *const &address, const char *name) const |
This class implements a mechanism used to format data as required by the standard BDE print
method contract.
See bslim_printer
bslim::Printer::Printer | ( | bsl::ostream * | stream, |
int | level, | ||
int | spacesPerLevel | ||
) |
Create a Printer
object that will print to the specified stream
in a format dictated by the values of the specified level
and spacesPerLevel
, as per the contract of the standard BDE print
method. The behavior is undefined unless stream
is valid.
bslim::Printer::~Printer | ( | ) |
int bslim::Printer::absLevel | ( | ) | const |
Return the absolute value of the formatting level supplied at construction.
void bslim::Printer::end | ( | bool | suppressBracket = false | ) | const |
If spacesPerLevel() >= 0
, print a newline character to the output stream supplied at construction. If the optionally specified suppressBracket
is false, print a closing square bracket, indented by absLevel() * spacesPerLevel()
blank spaces.
void bslim::Printer::print | ( | const TYPE & | data, |
const char * | name | ||
) | const |
[DEPRECATED – use printAttribute
instead, or printValue
if no name is wanted.]
Format to the output stream supplied at construction the specified data
, prefixed by the specified name
if name
is not 0. Format data
based on the parameterized TYPE
:
TYPE
is a fundamental type, output data
to the stream.TYPE
is char *
or const char *
, print data
to the stream as a null-terminated C-style string enclosed in quotes if data
is not 0, and print the string "NULL" otherwise.TYPE
is void *
or const void *
, print the address value of data
in hexadecimal format if it is not 0, and print the string "NULL" otherwise.TYPE
is a pointer type (other than the, potentially const-qualified, char *
or void *
), print the address value of data
in hexadecimal format, then format the object at that address if data
is not 0, and print the string "NULL" otherwise. There will be a compile-time error if data
is a pointer to a user-defined type that does not provide a standard print
method.TYPE
is any other type, call the standard print
method on data
, specifying one additional level of indentation than the current one. There will be a compile-time error if TYPE
does not provide a standard print
method.If spacesPerLevel() < 0
, format data
on a single line. Otherwise, indent data
by (absLevel() + 1) * spacesPerLevel()
blank spaces. The behavior is undefined if TYPE
is a char *
, but not a null-terminated string.
void bslim::Printer::printAttribute | ( | const bslstl::StringRef & | name, |
const ITERATOR & | begin, | ||
const ITERATOR & | end | ||
) | const |
Format to the output stream supplied at construction, the specified name
followed by the range of values starting at the specified begin
position and ending immediately before the specified end
position. The parameterized ITERATOR
type must support operator++
, operator*
, and operator==
. This function will call printValue
on each element in the range [begin, end)
.
void bslim::Printer::printAttribute | ( | const bslstl::StringRef & | name, |
const ITERATOR & | begin, | ||
const ITERATOR & | end, | ||
const PRINT_FUNCTOR & | printFunctionObject | ||
) | const |
Print to the output stream supplied at construction the specified name
and then call the specified printFunctionObject
with the range of values starting at the specified begin
position and ending immediately before the specified end
position, the stream supplied at construction, absLevel() + 1
, and spacesPerLevel()
. The parameterized PRINT_FUNCTOR
must be an invocable type whose arguments match the following function signature:
void bslim::Printer::printAttribute | ( | const bslstl::StringRef & | name, |
const TYPE & | data | ||
) | const |
Format to the output stream supplied at construction the specified data
, prefixed by the specified name
. Format data
based on the parameterized TYPE
:
TYPE
is a fundamental type, output data
to the stream.TYPE
is a fixed length array (Element[NUM]
) and not a char array, print out all the elements of the array.TYPE
is void * or
const void *', or function pointer, print the address value of data
in hexadecimal format if it is not 0, and print the string "NULL" otherwise.TYPE
is char *
, const char *
, char [*]
, or 'const char [*]
or bsl::string
print data
to the stream as a null-terminated C-style string enclosed in quotes if data
is not 0, and print the string "NULL" otherwise.TYPE
is a pointer type (other than the, potentially const-qualified, char *
or void *
), print the address value of data
in hexadecimal format, then format the object at that address if data
is not 0, and print the string "NULL" otherwise. There will be a compile-time error if data
is a pointer to a user-defined type that does not provide a standard print
method.TYPE
is a bsl::pair
object, print out the two elements of the pair.TYPE
is a bslstl::StringRef
object, print the referenced string enclosed in quotes (possibly including embedded 0s).TYPE
has STL iterators (this includes all STL sequence and associative containers: vector, deque, list, set, map, multiset, multimap, unordered_set, unordered_map, unordered_multiset, and unordered_multimap), print all the objects in the container.TYPE
is any other type, call the standard print
method on data
, specifying one additional level of indentation than the current one. There will be a compile-time error if TYPE
does not provide a standard print
method.If spacesPerLevel() < 0
, format data
on a single line. Otherwise, indent data
by (absLevel() + 1) * spacesPerLevel()
blank spaces. The behavior is undefined if TYPE
is a char *
, but not a null-terminated string.
void bslim::Printer::printEndIndentation | ( | ) | const |
Print to the output stream supplied at construction absLevel() * spacesPerLevel()
blank spaces if spacesPerLevel() >= 0
, and print a single blank space otherwise.
void bslim::Printer::printForeign | ( | const TYPE & | data, |
const PRINT_FUNCTOR & | printFunctionObject, | ||
const char * | name | ||
) | const |
Print to the output stream supplied at construction the specified name
, if name is not 0, and then call the specified printFunctionObject
with the specified data
, the stream
supplied at construction, absLevel() + 1
, and spacesPerLevel()
. The parameterized PRINT_FUNCTOR
must be an invocable type whose arguments match the following function signature:
void bslim::Printer::printHexAddr | ( | const void * | address, |
const char * | name | ||
) | const |
Write to the output stream supplied at construction the specified address
in a hexadecimal format, if address
is not 0, and print the string "NULL" otherwise, prefixed by the specified name
if name
is not 0. If spacesPerLevel() < 0
, print on a single line. If spacesPerLevel() >= 0
, indent by (absLevel() + 1) * spacesPerLevel()
blank spaces.
void bslim::Printer::printIndentation | ( | ) | const |
Print to the output stream supplied at construction (absLevel() + 1) * spacesPerLevel()
blank spaces if spacesPerLevel() >= 0
, and print a single blank space otherwise.
void bslim::Printer::printOrNull | ( | const TYPE & | address, |
const char * | name | ||
) | const |
Format to the output stream supplied at construction the object at the specified address
, if address
is not 0, and print the string "NULL" otherwise, prefixed by the specified name
if name
is not 0. If spacesPerLevel() < 0
, print on a single line. If spacesPerLevel() >= 0
, indent by (absLevel() + 1) * spacesPerLevel()
blank spaces. The behavior is undefined unless TYPE
is a pointer type.
|
inline |
|
inline |
void bslim::Printer::printValue | ( | const ITERATOR & | begin, |
const ITERATOR & | end | ||
) | const |
Format to the output stream supplied at construction, the range of values starting at the specified begin
position and ending immediately before the specified end
position. The parameterized ITERATOR
type must support operator++
, operator*
, and operator==
. This function will call printValue
on each element in the range [begin, end)
.
void bslim::Printer::printValue | ( | const ITERATOR & | begin, |
const ITERATOR & | end, | ||
const PRINT_FUNCTOR & | printFunctionObject | ||
) | const |
Print to the output stream supplied at construction the specified name
, if name is not 0, and then call the specified printFunctionObject
with the range of values starting at the specified begin
position and ending immediately before the specified end
position, the stream
supplied at construction, absLevel() + 1
, and spacesPerLevel()
. The parameterized PRINT_FUNCTOR
must be an invocable type whose arguments match the following function signature:
|
inline |
Format to the output stream supplied at construction the specified data
. Format data
based on the parameterized TYPE
:
TYPE
is a fundamental type, output data
to the stream.TYPE
is a fixed length array (Element[NUM]
) and not a char array, print out all the elements of the array.TYPE
is void * or
const void *', or function pointer, print the address value of data
in hexadecimal format if it is not 0, and print the string "NULL" otherwise.TYPE
is char *
, const char *
, char [*]
, or 'const char [*]
or bsl::string
print data
to the stream as a null-terminated C-style string enclosed in quotes if data
is not 0, and print the string "NULL" otherwise.TYPE
is a pointer type (other than the, potentially const-qualified, char *
or void *
), print the address value of data
in hexadecimal format, then format the object at that address if data
is not 0, and print the string "NULL" otherwise. There will be a compile-time error if data
is a pointer to a user-defined type that does not provide a standard print
method.TYPE
is a bsl::pair
object, print out the two elements of the pair.TYPE
is a bslstl::StringRef
object, print the referenced string enclosed in quotes (possibly including embedded 0s).TYPE
has STL iterators (this includes all STL sequence and associative containers: vector, deque, list, set, map, multiset, multimap, unordered_set, unordered_map, unordered_multiset, and unordered_multimap), print all the objects in the container.TYPE
is any other type, call the standard print
method on data
, specifying one additional level of indentation than the current one. There will be a compile-time error if TYPE
does not provide a standard print
method.If spacesPerLevel() < 0
, format data
on a single line. Otherwise, indent data
by (absLevel() + 1) * spacesPerLevel()
blank spaces. The behavior is undefined if TYPE
is a char *
, but not a null-terminated string.
int bslim::Printer::spacesPerLevel | ( | ) | const |
Return the number of whitespace characters to output for each level of indentation. The number of whitespace characters for each level of indentation is configured using the spacesPerLevel
supplied at construction.
void bslim::Printer::start | ( | bool | suppressBracket = false | ) | const |
Print to the output stream supplied at construction absLevel() * spacesPerLevel()
blank spaces if the suppressInitialIndentFlag
is false
, and suppress the initial indentation otherwise. If the optionally specified suppressBracket
is false
, print an opening square bracket.
bool bslim::Printer::suppressInitialIndentFlag | ( | ) | const |
Return true
if the initial output indentation will be suppressed, and false
otherwise. The initial indentation will be suppressed if the level
supplied at construction is negative.