The Sparta Modeling Framework
Loading...
Searching...
No Matches
Printing.hpp File Reference

Helpers for printing and populating vectors. More...

#include <iostream>
#include <string>
#include <ostream>
#include <vector>
#include <sstream>
#include "sparta/utils/SpartaException.hpp"

Go to the source code of this file.

Namespaces

namespace  sparta
 Macros for handling exponential backoff.
 

Enumerations

enum  sparta::utils::DisplayBase { BASE_DEC = 0 , sparta::utils::BASE_HEX = 1 , sparta::utils::BASE_OCT = 2 }
 Numeric display options used by Parameter printing routines. More...
 

Functions

std::ios_base::fmtflags sparta::utils::setIOSFlags (std::ios_base &stream, DisplayBase base)
 Configure an ios stream to use given numeric base from sparta::DisplayBase.
 
template<class T >
std::string sparta::utils::stringize_value (const std::vector< T > &v, DisplayBase base=BASE_DEC, const std::string &string_quote="")
 Converting a vector of intrinsic types (and std::string) to a string.
 
template<class T , class U >
std::string sparta::utils::stringize_value (const std::pair< T, U > &p, DisplayBase base=BASE_DEC, const std::string &string_quote="")
 Converting a stl pair of intrinsic types (and std::string) to a string.
 
template<class... Ts>
std::string sparta::utils::stringize_value (const std::tuple< Ts... > &t, DisplayBase base=BASE_DEC, const std::string &string_quote="")
 Converting a stl tuple of intrinsic types (and std::string) to a string.
 
template<class T >
std::string sparta::utils::stringize_value (const T &o, DisplayBase base=BASE_DEC, const std::string &string_quote="")
 Overload of stringize_value that supports intrinisic types as well as std::string.
 
template<>
std::string sparta::utils::stringize_value< std::string > (const std::string &o, DisplayBase base, const std::string &string_quote)
 Specialization for printing strings.
 
std::vector< std::string > & sparta::utils::operator<< (std::vector< std::string > &v, const char *e)
 Specialization for populating STL vector of string with char*s.
 
template<class T , class U >
std::vector< T > & sparta::utils::operator<< (std::vector< T > &v, U &e)
 Helper for populating STL vectors.
 
template<class T , class U >
std::vector< T > & sparta::utils::operator<< (std::vector< T > &v, const U &e)
 Helper for populating STL vector.
 
template<class T , std::size_t... Is>
void sparta::utils::stringize_tuple (std::stringstream &ss, const T &t, DisplayBase base, const std::string &string_quote, std::index_sequence< Is... >)
 Helper for printing STL tuple.
 
template<class Ch , class T , class Tr >
std::basic_ostream< Ch, Tr > & std::operator<< (std::basic_ostream< Ch, Tr > &out, std::vector< T > const &v)
 Vector printer.
 
template<class Ch , class T , class U , class Tr >
std::basic_ostream< Ch, Tr > & std::operator<< (std::basic_ostream< Ch, Tr > &out, std::pair< T, U > const &p)
 Pair Printer.
 
template<class Ch , class... Ts, class Tr >
std::basic_ostream< Ch, Tr > & std::operator<< (std::basic_ostream< Ch, Tr > &out, std::tuple< Ts... > const &t)
 Tuple Printer.
 
std::vector< std::string > & operator<< (std::vector< std::string > &v, const char *e)
 Specialization for populating STL vector of string with char*s.
 
template<class T , class U >
std::vector< T > & operator<< (std::vector< T > &v, U &e)
 Helper for populating STL vectors.
 
template<class T , class U >
std::vector< T > & operator<< (std::vector< T > &v, const U &e)
 Helper for populating STL vector.
 

Detailed Description

Helpers for printing and populating vectors.

Definition in file Printing.hpp.

Enumeration Type Documentation

◆ DisplayBase

Numeric display options used by Parameter printing routines.

Warning
When Adding fields, sparta::setIOSFlags must also be updated.
Enumerator
BASE_HEX 

Decimal display.

BASE_OCT 

Hex display.

Definition at line 27 of file Printing.hpp.

Function Documentation

◆ operator<<() [1/9]

template<class Ch , class T , class U , class Tr >
std::basic_ostream< Ch, Tr > & std::operator<< ( std::basic_ostream< Ch, Tr > &  out,
std::pair< T, U > const &  p 
)
inline

Pair Printer.

Definition at line 193 of file Printing.hpp.

◆ operator<<() [2/9]

template<class Ch , class... Ts, class Tr >
std::basic_ostream< Ch, Tr > & std::operator<< ( std::basic_ostream< Ch, Tr > &  out,
std::tuple< Ts... > const &  t 
)
inline

Tuple Printer.

Definition at line 193 of file Printing.hpp.

◆ operator<<() [3/9]

template<class Ch , class T , class Tr >
std::basic_ostream< Ch, Tr > & std::operator<< ( std::basic_ostream< Ch, Tr > &  out,
std::vector< T > const &  v 
)
inline

Vector printer.

Definition at line 193 of file Printing.hpp.

◆ operator<<() [4/9]

std::vector< std::string > & operator<< ( std::vector< std::string > &  v,
const char *  e 
)
inline

Specialization for populating STL vector of string with char*s.

Definition at line 1 of file Printing.hpp.

◆ operator<<() [5/9]

std::vector< std::string > & sparta::utils::operator<< ( std::vector< std::string > &  v,
const char *  e 
)
inline

Specialization for populating STL vector of string with char*s.

Definition at line 161 of file Printing.hpp.

◆ operator<<() [6/9]

template<class T , class U >
std::vector< T > & operator<< ( std::vector< T > &  v,
const U &  e 
)
inline

Helper for populating STL vector.

Definition at line 1 of file Printing.hpp.

◆ operator<<() [7/9]

template<class T , class U >
std::vector< T > & sparta::utils::operator<< ( std::vector< T > &  v,
const U &  e 
)
inline

Helper for populating STL vector.

Definition at line 161 of file Printing.hpp.

◆ operator<<() [8/9]

template<class T , class U >
std::vector< T > & operator<< ( std::vector< T > &  v,
U &  e 
)
inline

Helper for populating STL vectors.

Definition at line 1 of file Printing.hpp.

◆ operator<<() [9/9]

template<class T , class U >
std::vector< T > & sparta::utils::operator<< ( std::vector< T > &  v,
U &  e 
)
inline

Helper for populating STL vectors.

Definition at line 161 of file Printing.hpp.

◆ setIOSFlags()

std::ios_base::fmtflags sparta::utils::setIOSFlags ( std::ios_base &  stream,
DisplayBase  base 
)
inline

Configure an ios stream to use given numeric base from sparta::DisplayBase.

Parameters
streamStream reference to configure with given sparta::DisplayBase base.
basesparta::DisplayBase describing the new formatting.
Note
Also enables showbase (e.g. '0xf' instead of 'f') and boolalpha (true instead of 1 for bools).
Exceptions
SpartaExceptionif base is not a supported type.

Definition at line 43 of file Printing.hpp.

Here is the call graph for this function:

◆ stringize_tuple()

template<class T , std::size_t... Is>
void sparta::utils::stringize_tuple ( std::stringstream &  ss,
const T &  t,
DisplayBase  base,
const std::string &  string_quote,
std::index_sequence< Is... >   
)
inline

Helper for printing STL tuple.

Definition at line 193 of file Printing.hpp.

◆ stringize_value() [1/4]

template<class T , class U >
std::string sparta::utils::stringize_value ( const std::pair< T, U > &  p,
DisplayBase  base = BASE_DEC,
const std::string &  string_quote = "" 
)
inline

Converting a stl pair of intrinsic types (and std::string) to a string.

Template Parameters
Tfirst type in pair to stringize
Usecond type in pair to stringize
Parameters
ppair to print (of type <T,U>)
baseBase of displayed integers
string_quoteQuote sequence for printing strings; defaults to no quoting
Returns
std::string of form "first:second"

Definition at line 111 of file Printing.hpp.

Here is the call graph for this function:

◆ stringize_value() [2/4]

template<class... Ts>
std::string sparta::utils::stringize_value ( const std::tuple< Ts... > &  t,
DisplayBase  base = BASE_DEC,
const std::string &  string_quote = "" 
)
inline

Converting a stl tuple of intrinsic types (and std::string) to a string.

Template Parameters
Tstypes of tuple
Parameters
ttuple to print
baseBase of displayed integers
string_quoteQuote sequence for printing strings; defaults to no quoting
Returns
std::string of form "t[0]:t[1]:...:t[N-1]"

Definition at line 131 of file Printing.hpp.

Here is the call graph for this function:

◆ stringize_value() [3/4]

template<class T >
std::string sparta::utils::stringize_value ( const std::vector< T > &  v,
DisplayBase  base = BASE_DEC,
const std::string &  string_quote = "" 
)
inline

Converting a vector of intrinsic types (and std::string) to a string.

Template Parameters
Ttype of vector to stringize
Parameters
vvector to print (value_type=T)
baseBase of displayed integers
string_quoteQuote sequence for printing strings; defaults to no quoting
Returns
std::string of form "[el0, el1, ..., elN-1]"
Note
This is used internally by Parameter for self-printing, but can be used to print vectors for any purpose
std::vector<int32_t> v; v.push_back(1); v.push_back(2);
std::cout << sparta::stringize_value(v, sparta::BASE_HEX) << std::endl;

Definition at line 80 of file Printing.hpp.

Here is the call graph for this function:

◆ stringize_value() [4/4]

template<class T >
std::string sparta::utils::stringize_value ( const T &  o,
DisplayBase  base = BASE_DEC,
const std::string &  string_quote = "" 
)
inline

Overload of stringize_value that supports intrinisic types as well as std::string.

See also
sparta::stringize_value

Invoking stringize_value with a non-std::vector type will invoke this method.

Definition at line 149 of file Printing.hpp.

Here is the call graph for this function:

◆ stringize_value< std::string >()

template<>
std::string sparta::utils::stringize_value< std::string > ( const std::string &  o,
DisplayBase  base,
const std::string &  string_quote 
)
inline

Specialization for printing strings.

Definition at line 161 of file Printing.hpp.