USB_Config_Vendor/CC_SDK/Include/basic/StreamHandler.h

38 lines
891 B
C
Raw Permalink Normal View History

2026-02-03 14:36:30 +08:00
#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