BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslim::Printer Class Reference

#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
 

Detailed Description

This class implements a mechanism used to format data as required by the standard BDE print method contract.

See bslim_printer

Constructor & Destructor Documentation

◆ 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.

◆ ~Printer()

bslim::Printer::~Printer ( )

Member Function Documentation

◆ absLevel()

int bslim::Printer::absLevel ( ) const

Return the absolute value of the formatting level supplied at construction.

◆ end()

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.

◆ print()

template<class TYPE >
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:

  • If TYPE is a fundamental type, output data to the stream.
  • If 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.
  • If 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.
  • If 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.
  • If 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.

◆ printAttribute() [1/3]

template<class ITERATOR >
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).

◆ printAttribute() [2/3]

template<class ITERATOR , class PRINT_FUNCTOR >
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:

bsl::ostream& (*)(bsl::ostream& stream,
const TYPE& data,
int level,
int spacesPerLevel() const

◆ printAttribute() [3/3]

template<class TYPE >
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:

  • If TYPE is a fundamental type, output data to the stream.
  • If TYPE is a fixed length array (Element[NUM]) and not a char array, print out all the elements of the array.
  • If TYPE is void * orconst void *', or function pointer, print the address value of data in hexadecimal format if it is not 0, and print the string "NULL" otherwise.
  • If 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.
  • If 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.
  • If TYPE is a bsl::pair object, print out the two elements of the pair.
  • If TYPE is a bslstl::StringRef object, print the referenced string enclosed in quotes (possibly including embedded 0s).
  • If 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.
  • If 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.

◆ printEndIndentation()

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.

◆ printForeign()

template<class TYPE , class PRINT_FUNCTOR >
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:

bsl::ostream& (*)(bsl::ostream& stream,
const TYPE& data,
int level,

◆ printHexAddr()

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.

◆ printIndentation()

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.

◆ printOrNull() [1/3]

template<class TYPE >
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.

◆ printOrNull() [2/3]

template<>
void bslim::Printer::printOrNull ( const void *const &  address,
const char *  name 
) const
inline

◆ printOrNull() [3/3]

template<>
void bslim::Printer::printOrNull ( void *const &  address,
const char *  name 
) const
inline

◆ printValue() [1/3]

template<class ITERATOR >
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).

◆ printValue() [2/3]

template<class ITERATOR , class PRINT_FUNCTOR >
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:

bsl::ostream& (*)(bsl::ostream& stream,
const TYPE& data,
int level,

◆ printValue() [3/3]

template<class TYPE >
void bslim::Printer::printValue ( const TYPE &  data) const
inline

Format to the output stream supplied at construction the specified data. Format data based on the parameterized TYPE:

  • If TYPE is a fundamental type, output data to the stream.
  • If TYPE is a fixed length array (Element[NUM]) and not a char array, print out all the elements of the array.
  • If TYPE is void * orconst void *', or function pointer, print the address value of data in hexadecimal format if it is not 0, and print the string "NULL" otherwise.
  • If 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.
  • If 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.
  • If TYPE is a bsl::pair object, print out the two elements of the pair.
  • If TYPE is a bslstl::StringRef object, print the referenced string enclosed in quotes (possibly including embedded 0s).
  • If 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.
  • If 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.

◆ spacesPerLevel()

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.

◆ start()

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.

◆ suppressInitialIndentFlag()

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.


The documentation for this class was generated from the following file: