---
title: llarp::Printer
summary: A general-purpose, stateful printer class. 

---

# llarp::Printer



A general-purpose, stateful printer class. 


`#include <printer.hpp>`

## Public Types

|                | Name           |
| -------------- | -------------- |
| template <typename Type \> <br>using std::function< std::ostream &(std::ostream &, const Type &, int, int)> | **[PrintFunction](Classes/classllarp_1_1Printer.md#using-printfunction)**  |

## Public Functions

|                | Name           |
| -------------- | -------------- |
| | **[Printer](Classes/classllarp_1_1Printer.md#function-printer)**(std::ostream & stream, int level, int spaces)<br>Create a printer.  |
| | **[~Printer](Classes/classllarp_1_1Printer.md#function-~printer)**() |
| template <typename Type \> <br>void | **[printAttribute](Classes/classllarp_1_1Printer.md#function-printattribute)**(std::string_view name, const Type & value) const<br>Print the given `data` to the stream, using the following strategies:  |
| template <typename Type \> <br>void | **[printAttributeAsHex](Classes/classllarp_1_1Printer.md#function-printattributeashex)**(std::string_view name, const Type & value) const |
| template <typename InputIt \> <br>void | **[printAttribute](Classes/classllarp_1_1Printer.md#function-printattribute)**(std::string_view name, const InputIt & begin, const InputIt & end) const |
| template <typename Type \> <br>void | **[printValue](Classes/classllarp_1_1Printer.md#function-printvalue)**(const Type & value) const |
| template <typename InputIt \> <br>void | **[printValue](Classes/classllarp_1_1Printer.md#function-printvalue)**(const InputIt & begin, const InputIt & end) const |
| template <typename Type \> <br>void | **[printForeignAttribute](Classes/classllarp_1_1Printer.md#function-printforeignattribute)**(std::string_view name, const Type & value, const PrintFunction< Type > & printFunction) const |
| template <typename Type \> <br>void | **[printForeignValue](Classes/classllarp_1_1Printer.md#function-printforeignvalue)**(const Type & value, const PrintFunction< Type > & printFunction) const |
| void | **[printHexAddr](Classes/classllarp_1_1Printer.md#function-printhexaddr)**(std::string_view name, const void * address) const |
| void | **[printHexAddr](Classes/classllarp_1_1Printer.md#function-printhexaddr)**(const void * address) const |
| template <class Type \> <br>void | **[printOrNull](Classes/classllarp_1_1Printer.md#function-printornull)**(std::string_view name, const Type & address) const |
| template <class Type \> <br>void | **[printOrNull](Classes/classllarp_1_1Printer.md#function-printornull)**(const Type & address) const |
| void | **[printOrNull](Classes/classllarp_1_1Printer.md#function-printornull)**(std::string_view name, const void *const & address) const |
| void | **[printOrNull](Classes/classllarp_1_1Printer.md#function-printornull)**(std::string_view name, void *const & address) const |
| void | **[printOrNull](Classes/classllarp_1_1Printer.md#function-printornull)**(const void *const & address) const |
| void | **[printOrNull](Classes/classllarp_1_1Printer.md#function-printornull)**(void *const & address) const |

## Public Types Documentation

### using PrintFunction

```cpp
template <typename Type >
using llarp::Printer::PrintFunction =  std::function<std::ostream&(std::ostream&, const Type&, int, int)>;
```


## Public Functions Documentation

### function Printer

```cpp
Printer(
    std::ostream & stream,
    int level,
    int spaces
)
```

Create a printer. 



* level: the indentation level to use. If negative, suppress indentation on the first line.
* spaces: the number of spaces to indent. If negative, put all output on a single line 


### function ~Printer

```cpp
~Printer()
```


### function printAttribute

```cpp
template <typename Type >
inline void printAttribute(
    std::string_view name,
    const Type & value
) const
```

Print the given `data` to the stream, using the following strategies: 



* If `Type` is fundamental, print to stream
* If `Type` is a C-style array (and not a char array), print each element to the stream
* If `Type` is a `void *`, `const void *` or function pointer, and not null, print in hex format or print "null".
* If `Type` is a `char *`, a `const char *`, a C-style char array, a `std::string` or `std::string_view` print the string wrapped in `"`.
* If `Type` is a pointer type, print the pointer, followed by the value if not-null.
* If `Type` is a pair/tuple type, print the elements of the tuple.
* If `Type` has STL-style iterators, print all elements in the container.
* If `Type` is any other type, call the `print` method on that type. 


### function printAttributeAsHex

```cpp
template <typename Type >
inline void printAttributeAsHex(
    std::string_view name,
    const Type & value
) const
```


### function printAttribute

```cpp
template <typename InputIt >
inline void printAttribute(
    std::string_view name,
    const InputIt & begin,
    const InputIt & end
) const
```


### function printValue

```cpp
template <typename Type >
inline void printValue(
    const Type & value
) const
```


### function printValue

```cpp
template <typename InputIt >
inline void printValue(
    const InputIt & begin,
    const InputIt & end
) const
```


### function printForeignAttribute

```cpp
template <typename Type >
inline void printForeignAttribute(
    std::string_view name,
    const Type & value,
    const PrintFunction< Type > & printFunction
) const
```


### function printForeignValue

```cpp
template <typename Type >
inline void printForeignValue(
    const Type & value,
    const PrintFunction< Type > & printFunction
) const
```


### function printHexAddr

```cpp
void printHexAddr(
    std::string_view name,
    const void * address
) const
```


### function printHexAddr

```cpp
void printHexAddr(
    const void * address
) const
```


### function printOrNull

```cpp
template <class Type >
inline void printOrNull(
    std::string_view name,
    const Type & address
) const
```


### function printOrNull

```cpp
template <class Type >
inline void printOrNull(
    const Type & address
) const
```


### function printOrNull

```cpp
inline void printOrNull(
    std::string_view name,
    const void *const & address
) const
```


### function printOrNull

```cpp
inline void printOrNull(
    std::string_view name,
    void *const & address
) const
```


### function printOrNull

```cpp
inline void printOrNull(
    const void *const & address
) const
```


### function printOrNull

```cpp
inline void printOrNull(
    void *const & address
) const
```


-------------------------------

Updated on 2022-04-18 at 19:54:44 +0000