actsim-cluster-agent/include/util.h
2024-01-05 12:11:58 -05:00

58 lines
No EOL
1.6 KiB
C++

/*************************************************************************
*
* Copyright (c) 2023 Fabian Posch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
**************************************************************************
*/
#ifndef __UTIL_H__
#define __UTIL_H__
#include <iostream>
#include <string>
// debugging util print functions
#ifdef DEBUG
#define DEBUG_PRINT(msg) std::cerr << "Info: " << msg << std::endl;
#else
#define DEBUG_PRINT(msg) do {} while (0)
#endif
#define ENUM_CLASS_OPS(T, lookup_table) \
\
inline std::string to_string(T const &value) { \
std::string str = "unknown"; \
\
for (auto& it : lookup_table) { \
if (it.second == value) { \
str = it.first; \
break; \
} \
} \
\
return str; \
}; \
\
inline std::ostream& operator<<(std::ostream& os, T const &rhs) { \
os << to_string(rhs); \
return os; \
};
#endif