Skip to content

Commit 68e33b7

Browse files
committed
Clickhouse - introduce common
1 parent b82041a commit 68e33b7

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @file
3+
* @author Michal Sedlak <[email protected]>
4+
* @brief Common functionality and general utilities
5+
* @date 2025
6+
*
7+
* Copyright(c) 2025 CESNET z.s.p.o.
8+
* SPDX-License-Identifier: BSD-3-Clause
9+
*/
10+
11+
#include "common.h"
12+
13+
#include <cctype>
14+
15+
std::string to_lower(std::string str)
16+
{
17+
for (auto &c : str) {
18+
c = std::tolower(c);
19+
}
20+
return str;
21+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @file
3+
* @author Michal Sedlak <[email protected]>
4+
* @brief Common functionality and general utilities
5+
* @date 2025
6+
*
7+
* Copyright(c) 2025 CESNET z.s.p.o.
8+
* SPDX-License-Identifier: BSD-3-Clause
9+
*/
10+
#pragma once
11+
12+
#include "clickhouse.h"
13+
14+
#include <fmt/core.h>
15+
#include <ipfixcol2.h>
16+
17+
#include <stdexcept>
18+
19+
/**
20+
* @class Nonmoveable
21+
* @brief Classes that will inherit from this class will be immovable
22+
*/
23+
struct Nonmoveable {
24+
Nonmoveable() = default;
25+
Nonmoveable(Nonmoveable&&) = delete;
26+
Nonmoveable& operator=(Nonmoveable&&) = delete;
27+
};
28+
29+
/**
30+
* @class Noncopyable
31+
* @brief Classes that will inherit from this class will not be able to be copied
32+
*/
33+
struct Noncopyable {
34+
Noncopyable() = default;
35+
Noncopyable(const Noncopyable&) = delete;
36+
Noncopyable& operator=(const Noncopyable&) = delete;
37+
};
38+
39+
/**
40+
* @class Error
41+
* @brief An exception type that will be thrown by the plugin
42+
*/
43+
class Error : public std::runtime_error {
44+
public:
45+
template <typename ...Args>
46+
Error(Args&& ...args) : std::runtime_error(fmt::format(args...)) {}
47+
};
48+
49+
50+
class Logger {
51+
public:
52+
Logger(const ipx_ctx_t *ctx) : m_ctx(ctx) {}
53+
template <typename ...Args> void info (const char *fmt, Args... args) { IPX_CTX_INFO (m_ctx, fmt, args..., 0); }
54+
template <typename ...Args> void warning(const char *fmt, Args... args) { IPX_CTX_WARNING(m_ctx, fmt, args..., 0); }
55+
template <typename ...Args> void error (const char *fmt, Args... args) { IPX_CTX_ERROR (m_ctx, fmt, args..., 0); }
56+
template <typename ...Args> void debug (const char *fmt, Args... args) { IPX_CTX_DEBUG (m_ctx, fmt, args..., 0); }
57+
58+
private:
59+
const ipx_ctx_t *m_ctx;
60+
};
61+
62+
63+
/**
64+
* @brief Convert string to lowercase
65+
*
66+
* @param str The string
67+
*/
68+
std::string to_lower(std::string s);

0 commit comments

Comments
 (0)