123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #ifndef LOC_LOG_H
- #define LOC_LOG_H
- #include <ctype.h>
- #include <stdlib.h>
- #include <string>
- #include <loc_pla.h>
- #include "loc_target.h"
- #include "loc_misc_utils.h"
- #ifdef NO_UNORDERED_SET_OR_MAP
- #include <map>
- using std::map;
- #define unordered_map map
- #else
- #include <unordered_map>
- using std::unordered_map;
- #endif
- using std::string;
- typedef unordered_map<int64_t, string> NameValTbl;
- #define NAME_VAL(x) {x, "" #x ""}
- #define DECLARE_TBL(T) static const NameValTbl T##_tbl
- extern const string gEmptyStr;
- extern const string gUnknownStr;
- #define CHECK_MASK(type, value, mask_var, mask) \
- (((mask_var) & (mask)) ? (type) (value) : (type) (-1))
- #define LOC_TABLE_SIZE(table) (sizeof(table)/sizeof((table)[0]))
- #define FIELDVAL_DEC(field) \
- loc_put_tag_val(#field, to_string(field))
- #define FIELDVAL_DEC_ARR(field) \
- loc_put_tag_val(#field, \
- loc_parenthesize(loc_prim_arr_to_string(field, \
- sizeof(field)/sizeof(field[0]))))
- #define FIELDVAL_HEX(field) \
- loc_put_tag_val(#field, to_string_hex(field))
- #define FIELDVAL_HEX_ARR(field) \
- loc_put_tag_val(#field, \
- loc_parenthesize(loc_prim_arr_to_string(field, \
- sizeof(field)/sizeof(field[0]), \
- false)))
- #define FIELDVAL_ENUM(field, tbl) \
- loc_put_tag_val(#field, \
- loc_get_name_from_tbl(tbl, field, gUnknownStr))
- #define FIELDVAL_MASK(field, tbl) \
- loc_put_tag_val(#field, \
- to_string_hex((uint64_t)field) + " " + \
- loc_parenthesize(loc_get_bit_defs(field, tbl)))
- inline static const string& loc_get_name_from_tbl(const NameValTbl& tbl, int64_t key,
- const string& defalt = gEmptyStr) {
- auto item = tbl.find(key);
- if (item != tbl.end()) {
- return item->second;
- } else {
- return defalt;
- }
- }
- inline string loc_put_tag_val(const string& tag, const string& val, const string& eol = "\n") {
- return tag + ": " + val + eol;
- }
- inline string loc_parenthesize(const string& str) {
- return "(" + str + ")";
- }
- inline const char* loc_get_name_from_val(const NameValTbl& table, int64_t value) {
- return loc_get_name_from_tbl(table, value, gUnknownStr).c_str();
- }
- inline const char* log_succ_fail_string(int is_succ) {
- return is_succ? "successful" : "failed";
- }
- string loc_get_bit_defs(uint64_t mask, const NameValTbl& tbl);
- uint64_t loc_get_least_bit(uint64_t& mask, bool clearThebit = true);
- const char* loc_get_msg_q_status(int status);
- const char* loc_get_target_name(unsigned int target);
- char *loc_get_time(char *time_string, size_t buf_size);
- #endif
|