Solar/common.h
2025-09-03 22:38:18 +02:00

48 lines
2.2 KiB
C++

#ifndef __SOLAR_COMMON // include GUARD
#define __SOLAR_COMMON
namespace solar
{
#define FLAGBITS ~0x0FFF // bitwise one's complement (sort column info fits into lower three nibbles)
#define SORTCASE 0x0001000 // case sensitive
#define SORTREVERSE 0x0002000 // reverse order
#define WILDNULL 0x0004000 // zero denotes wildcard, i.e. anything is equal to zero
#define STOPCOMPARE 0x0080000 // stop compare after this column if both items to be compared are valid and a compare was possible
#define SEARCHWILD 0x0100000 // do wildcard comparison (only searchkey should contain wildcards)
#define num_compare(a, b) ((a) > (b)) ? +1 : ((a) < (b)) ? -1 : 0
#define bool_compare(a, b) ((!(a) && !(b)) || ((a) && (b))) ? 0 : (a) ? +1 : -1
#define max(a, b) ((a) > (b)) ? (a) : (b)
#define min(a, b) ((a) < (b)) ? (a) : (b)
typedef unsigned int uint;
typedef std::vector<uint8_t> byte_vector;
struct publish_spec_t
{
int on_count; // how many times a duplicate of this frame was received; used to signal publish
int interval; // used for checking whether updateinterval has expired, i.e. to force a publish
int timeout; // used for checking whether timeout has expired, i.e. frame has become stale
publish_spec_t(int on_count, int interval, int timeout)
: on_count(on_count), interval(interval), timeout(timeout) {}
};
inline std::string ltrim(const std::string& str, const std::string& chars = " \t\n\r\f\v")
{
size_t start = str.find_first_not_of(chars);
return (start == std::string::npos) ? "" : str.substr(start);
}
inline std::string rtrim(const std::string& str, const std::string& chars = " \t\n\r\f\v")
{
size_t end = str.find_last_not_of(chars);
return (end == std::string::npos) ? "" : str.substr(0, end + 1);
}
inline std::string trim(const std::string& str, const std::string& chars = " \t\n\r\f\v")
{
return rtrim(ltrim(str, chars), chars);
}
} // namespace solar
#endif // __SOLAR_COMMON