Distribution_Service/CC_SDK/Include/basic/StreamHandler.h
2025-11-11 17:46:19 +08:00

38 lines
891 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef STREAM_HANDLER_H
#define STREAM_HANDLER_H
#include <iosfwd>
#include <iostream>
#include <sstream>
#ifdef __OHOS__
#define CC_OHOS_ 1
#include "hilog/log.h"
#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN 0x0728 // 全局domain宏标识业务领域
#define LOG_TAG "CC_SDK" // 全局tag宏标识模块日志tag
#endif
class StreamHandler {
public:
// 构造函数
explicit StreamHandler(std::ostream& stream) : os(stream) {}
// 重载 << 操作符,处理输入值
template <typename T>
StreamHandler& operator<<(const T& value) {
os << value;
return *this;
}
// 专门处理函数触发逻辑
StreamHandler& operator<<(std::ostream& (*func)(std::ostream&)) {
func(os); // 调用传入的函数
return *this;
}
private:
std::ostream& os;
};
inline StreamHandler customCout(std::cout);
#endif