print / printn
Abstract
print()
, printn()
, printn_all()
and printn_fflv()
print values of variable.
printn()
, printn_all()
and printn_fflv()
are macro functions and able to apply variables can print by for_printn()
.
print()
, printn()
, printn_all()
and printn_fflv()
は変数の値を表示する.
printn()
, printn_all()
and printn_fflv()
はマクロ関数で,for_printn()
で表示できる変数に適用できる.
name of macro function | descriptions |
---|---|
print() |
print values of variable. 変数の値を出力します. |
printn() |
print values of variable with variable name. 変数の値を,変数名を付与して出力します. |
printn_all() |
print values of variable with variable name, function name and function line number. 変数の値を,変数名と関数名,関数の行番号を付与して出力します. |
printn_fflv() |
print values of variable with variable name, function name, function line number, path to the function and implemented file name. 変数の値を,変数名と関数名,関数の行番号,実装のファイルのファイル名とパス,を付与して出力します. |
Header file
namespace sstd{
void print(const void* rhs);
void print(const bool rhs);
void print(const char rhs);
void print(const int8 rhs);
void print(const int16 rhs);
void print(const int32 rhs);
void print(const int64 rhs);
void print(const uint8 rhs);
void print(const uint16 rhs);
void print(const uint32 rhs);
void print(const uint64 rhs);
void print(const float rhs);
void print(const double rhs);
void print(const char* rhs);
void print(const std::string& rhs);
template <typename T>
void print(const std::vector<T>& rhs);
template <typename T_lhs, typename T_rhs>
void print(const std::unordered_map<T_lhs, T_rhs>& rhs);
void for_printn( void* rhs);
void for_printn( bool rhs);
void for_printn( char rhs);
void for_printn( int8 rhs);
void for_printn( int16 rhs);
void for_printn( int32 rhs);
void for_printn( int64 rhs);
void for_printn(uint8 rhs);
void for_printn(uint16 rhs);
void for_printn(uint32 rhs);
void for_printn(uint64 rhs);
void for_printn( float rhs);
void for_printn(double rhs);
void for_printn(const char* rhs);
void for_printn(const std::string& rhs);
template <typename T>
void for_printn(const std::vector<T>& rhs);
template <typename T_lhs, typename T_rhs>
void for_printn(const std::unordered_map<T_lhs, T_rhs>& rhs);
//---
// for #define
inline void printn_dummy(){}
inline void printn(...){}
inline void printn_all(...){}
}
#define printn(var) printn_dummy();{printf("%s", #var);sstd::for_printn(var);}
#define printn_all(var) printn_dummy();{printf("%s(%d): %s", __func__, __LINE__, #var);sstd::for_printn(var);}
#define printn_fflv(var) printn_dummy();{printf("%s: %s(%d): %s", __FILE__, __func__, __LINE__, #var);sstd::for_printn(var);}
Usage
print(), printn(), printn_all(), printn_fflv()
- main.cpp
#include <sstd/sstd.hpp> int main(){ int i = 0; sstd::print(i); sstd::printn(i); sstd::printn_all(i); sstd::printn_fflv(i); }
- Execution result
0 i = 0 main(7): i = 0 .././tmp/.._._docs_src_docs_src_print_print.md_86.cpp/.._._docs_src_docs_src_print_print.md_86.cpp: main(8): i = 0
print void* (pointer) type
Normal case
- main.cpp
#include <sstd/sstd.hpp> int main(){ int num = 123; sstd::printn(&num); }
- Execution result
&num = 0x7fff1edd4114
char* case
- main.cpp
#include <sstd/sstd.hpp> int main(){ const char *pC = "abc"; sstd::printn((void*)pC); // To print a pointer address, sstd::print requires to cast char* to void*. sstd::printn(pC); // when the case not cast to void*, sstd::print treats the variable as a string. }
- Execution result
(void*)pC = 0x558fa713500d pC = "abc"
print bool type
- main.cpp
#include <sstd/sstd.hpp> int main(){ bool TF_t = true; sstd::printn(TF_t); bool TF_f = false; sstd::printn(TF_f); }
- Execution result
TF_t = true TF_f = false
print std::vector<T> type
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<std::string> vS = {"a", "b", "c"}; sstd::printn(vS); std::vector<std::vector<std::string>> vvS = {{"a", "b", "c"}, {"d", "e", "f"}}; sstd::printn(vvS); printf("\n"); // any depth vector<T>. T is bool, char, (u)int8-16-32-64, float, double, char* and std::string. std::vector<std::vector<std::vector<std::vector<int>>>> v4_int = {{{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}}, {{{9, 10}, {11, 12}}, {{13, 14}, {15, 16}}}}; sstd::printn(v4_int); }
- Execution result
vS = ["a" "b" "c"] vvS = [["a" "b" "c"] ["d" "e" "f"]] v4_int = [[[[1 2] [3 4]] [[5 6] [7 8]]] [[[9 10] [11 12]] [[13 14] [15 16]]]]
print std::unordered_map<T_lhs, T_rhs> type
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::unordered_map<std::string, std::vector<uint>> table; table["abc"] = {123, 456}; table["def"] = {456, 789}; sstd::printn(table); }
- Execution result
table = [ [key: "def", value: [456 789]], [key: "abc", value: [123 456]] ]
print sstd::mat_r<T> type
- main.cpp
#include <sstd/sstd.hpp> int main(){ sstd::mat_r<double> m = {{1,2,3}, {4,5,6}, {7,8,9}}; sstd::printn(m); }
- Execution result
m = 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 8.000000 9.000000
Implementation
- Source: sstd/src/print/print.cpp
- Header: sstd/src/print/print.hpp
- Test: test/src_test/print/print_printn_printn_all.cpp