ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
FmtTable Class Reference

#include <formatter.h>

Collaboration diagram for FmtTable:

Classes

struct  Alignments
 
struct  Delimiters
 
struct  Frames
 

Public Types

enum class  Align { LEFT , RIGHT , CENTER }
 

Public Member Functions

 FmtTable (const std::vector< std::string > &titles, const size_t nrows, const std::vector< std::string > &fmts, const size_t indent=0, const Alignments &aligns={}, const Frames &frames={}, const Delimiters &delimiters={})
 Construct a new Fmt Table object.
 
 ~FmtTable ()
 
template<typename T >
FmtTableoperator<< (const std::vector< T > &src)
 import data from std::vector
 
template<typename T >
void set_value (const size_t &i, const size_t &j, const T &value)
 Set the value object.
 
std::vector< std::string > relax_col_width (const std::vector< std::string > &col, const std::string &title="", const Align valign=Align::RIGHT, const Align talign=Align::CENTER)
 adjust the width of each column
 
std::string concat_title (const std::vector< std::string > &titles) const
 concatenate titles into a string
 
std::string concat_row (const std::vector< std::string > &row, const char &pos) const
 concatenate a row into a string
 
std::string str ()
 to get the table as a string
 
void str (const std::string &s)
 
void iter_set (const size_t val)
 

Private Types

typedef FmtCore core
 

Private Member Functions

template<typename T >
void set_value (const size_t &i, const size_t &j, const char &dir, const std::vector< T > &src)
 Set the value object from std::vector.
 

Private Attributes

struct FmtTable::Alignments aligns_
 
struct FmtTable::Frames frames_
 
struct FmtTable::Delimiters delimiters_
 
size_t j_ = 0
 
std::vector< std::string > titles_
 
NDArray< std::string > data_
 
std::vector< std::string > fmts_
 
size_t indent_ = 0
 

Member Typedef Documentation

◆ core

typedef FmtCore FmtTable::core
private

Member Enumeration Documentation

◆ Align

enum class FmtTable::Align
strong
Enumerator
LEFT 
RIGHT 
CENTER 

Constructor & Destructor Documentation

◆ FmtTable()

FmtTable::FmtTable ( const std::vector< std::string > &  titles,
const size_t  nrows,
const std::vector< std::string > &  fmts,
const size_t  indent = 0,
const Alignments aligns = {},
const Frames frames = {},
const Delimiters delimiters = {} 
)
inline

Construct a new Fmt Table object.

Parameters
titlestitles, its size should be the same as the number of columns
nrowsnumber of rows
fmtsformat strings for each column, its size should be the same as the number of columns
indentindent for each column, default is 0
alignsAlignments instance, for alignment of values and titles, e.g. {Align::LEFT, Align::RIGHT} for left alignment of values and right alignment of titles
framesFrames instance, can be constructed with initializer_list<char> like {'-', '-', '-', ' ', ' '}, for up, middle, down, left and right frames
delimitersDelimiters instance, can be constructed with initializer_list<char> like {'-', ' '}, for horizontal and vertical delimiters

◆ ~FmtTable()

FmtTable::~FmtTable ( )
inline

Member Function Documentation

◆ concat_row()

std::string FmtTable::concat_row ( const std::vector< std::string > &  row,
const char &  pos 
) const
inline

concatenate a row into a string

Parameters
rowrow to concatenate
posposition, can be 't' for top, 'b' for bottom, 'n' for normal
Returns
std::string
Here is the caller graph for this function:

◆ concat_title()

std::string FmtTable::concat_title ( const std::vector< std::string > &  titles) const
inline

concatenate titles into a string

Parameters
titlestitles to concatenate
Returns
std::string
Here is the caller graph for this function:

◆ iter_set()

void FmtTable::iter_set ( const size_t  val)
inline

◆ operator<<()

template<typename T >
FmtTable & FmtTable::operator<< ( const std::vector< T > &  src)
inline

import data from std::vector

Template Parameters
Tdatatype of the data
Parameters
srcsource data
Returns
FmtTable& itself
Here is the call graph for this function:

◆ relax_col_width()

std::vector< std::string > FmtTable::relax_col_width ( const std::vector< std::string > &  col,
const std::string &  title = "",
const Align  valign = Align::RIGHT,
const Align  talign = Align::CENTER 
)
inline

adjust the width of each column

Parameters
colcol to relax, organized as std::vector<std::string>
titletitle of the column
vlyotvalue layout, can be Align::LEFT, Align::RIGHT, Align::CENTER
tlyottitle layout, can be Align::LEFT, Align::RIGHT, Align::CENTER
Returns
std::vector<std::string> newly relaxed column
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_value() [1/2]

template<typename T >
void FmtTable::set_value ( const size_t &  i,
const size_t &  j,
const char &  dir,
const std::vector< T > &  src 
)
inlineprivate

Set the value object from std::vector.

Template Parameters
Tdatatype of the data
Parameters
irow index
jcolumn index
dirdirection, if 'v' then vertical, if 'h' then horizontal
srcsource data

◆ set_value() [2/2]

template<typename T >
void FmtTable::set_value ( const size_t &  i,
const size_t &  j,
const T value 
)
inline

Set the value object.

Template Parameters
Tdatatype of the data
Parameters
irow index
jcol index
valuevalue to set
Here is the call graph for this function:
Here is the caller graph for this function:

◆ str() [1/2]

std::string FmtTable::str ( )
inline

to get the table as a string

Returns
std::string
Here is the call graph for this function:
Here is the caller graph for this function:

◆ str() [2/2]

void FmtTable::str ( const std::string &  s)
inline

Member Data Documentation

◆ aligns_

struct FmtTable::Alignments FmtTable::aligns_
private

◆ data_

NDArray<std::string> FmtTable::data_
private

◆ delimiters_

struct FmtTable::Delimiters FmtTable::delimiters_
private

◆ fmts_

std::vector<std::string> FmtTable::fmts_
private

◆ frames_

struct FmtTable::Frames FmtTable::frames_
private

◆ indent_

size_t FmtTable::indent_ = 0
private

◆ j_

size_t FmtTable::j_ = 0
private

◆ titles_

std::vector<std::string> FmtTable::titles_
private

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