📄 messagebuffer.h
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */#ifndef _LOG4CXX_MESSAGE_BUFFER_H#define _LOG4CXX_MESSAGE_BUFFER_H#include <log4cxx/log4cxx.h>#include <log4cxx/logstring.h>#include <sstream>namespace log4cxx { namespace helpers { typedef std::ios_base& (*ios_base_manip)(std::ios_base&); /** * This class is used by the LOG4CXX_INFO and similar * macros to support insertion operators in the message parameter. * The class is not intended for use outside of that context. */ class LOG4CXX_EXPORT CharMessageBuffer { public: /** * Creates a new instance. */ CharMessageBuffer(); /** * Destructor. */ ~CharMessageBuffer(); /** * Appends string to buffer. * @param msg string append. * @return this buffer. */ CharMessageBuffer& operator<<(const std::basic_string<char>& msg); /** * Appends string to buffer. * @param msg string to append. * @return this buffer. */ CharMessageBuffer& operator<<(const char* msg); /** * Appends string to buffer. * @param msg string to append. * @return this buffer. */ CharMessageBuffer& operator<<(char* msg); /** * Appends character to buffer. * @param msg character to append. * @return this buffer. */ CharMessageBuffer& operator<<(const char msg); /** * Insertion operator for STL manipulators such as std::fixed. * @param manip manipulator. * @return encapsulated STL stream. */ std::ostream& operator<<(ios_base_manip manip); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ std::ostream& operator<<(bool val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ std::ostream& operator<<(short val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ std::ostream& operator<<(int val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ std::ostream& operator<<(unsigned int val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ std::ostream& operator<<(long val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ std::ostream& operator<<(unsigned long val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ std::ostream& operator<<(float val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ std::ostream& operator<<(double val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ std::ostream& operator<<(long double val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ std::ostream& operator<<(void* val); /** * Cast to ostream. */ operator std::basic_ostream<char>&(); /** * Get content of buffer. * @param os used only to signal that * the embedded stream was used. */ const std::basic_string<char>& str(std::basic_ostream<char>& os); /** * Get content of buffer. * @param buf used only to signal that * the embedded stream was not used. */ const std::basic_string<char>& str(CharMessageBuffer& buf); /** * Returns true if buffer has an encapsulated STL stream. * @return true if STL stream was created. */ bool hasStream() const; private: /** * Prevent use of default copy constructor. */ CharMessageBuffer(const CharMessageBuffer&); /** * Prevent use of default assignment operator. */ CharMessageBuffer& operator=(const CharMessageBuffer&); /** * Encapsulated std::string. */ std::basic_string<char> buf; /** * Encapsulated stream, created on demand. */ std::basic_ostringstream<char>* stream; };template<class V>std::basic_ostream<char>& operator<<(CharMessageBuffer& os, const V& val) { return ((std::basic_ostream<char>&) os) << val;}#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API || LOG4CXX_LOGCHAR_IS_UNICHAR /** * This class is designed to support insertion operations * in the message argument to the LOG4CXX_INFO and similar * macros and is not designed for general purpose use. */ class LOG4CXX_EXPORT UniCharMessageBuffer { public: /** * Creates a new instance. */ UniCharMessageBuffer(); /** * Destructor. */ ~UniCharMessageBuffer(); typedef std::basic_ostream<UniChar> uostream; /** * Appends string to buffer. * @param msg string append. * @return this buffer. */ UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg); /** * Appends string to buffer. * @param msg string to append. * @return this buffer. */ UniCharMessageBuffer& operator<<(const UniChar* msg); /** * Appends string to buffer. * @param msg string to append. * @return this buffer. */ UniCharMessageBuffer& operator<<(UniChar* msg); /** * Appends character to buffer. * @param msg character to append. * @return this buffer. */ UniCharMessageBuffer& operator<<(const UniChar msg); #if LOG4CXX_CFSTRING_API /** * Appends a string into the buffer and * fixes the buffer to use char characters. * @param msg message to append. * @return encapsulated CharMessageBuffer. */ UniCharMessageBuffer& operator<<(const CFStringRef& msg);#endif /** * Insertion operator for STL manipulators such as std::fixed. * @param manip manipulator. * @return encapsulated STL stream. */ uostream& operator<<(ios_base_manip manip); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ uostream& operator<<(bool val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ uostream& operator<<(short val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ uostream& operator<<(int val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ uostream& operator<<(unsigned int val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ uostream& operator<<(long val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ uostream& operator<<(unsigned long val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ uostream& operator<<(float val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ uostream& operator<<(double val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ uostream& operator<<(long double val); /** * Insertion operator for built-in type. * @param val build in type. * @return encapsulated STL stream. */ uostream& operator<<(void* val); /** * Cast to ostream. */ operator uostream&(); /** * Get content of buffer. * @param os used only to signal that * the embedded stream was used. */ const std::basic_string<UniChar>& str(uostream& os); /** * Get content of buffer. * @param buf used only to signal that * the embedded stream was not used. */ const std::basic_string<UniChar>& str(UniCharMessageBuffer& buf); /** * Returns true if buffer has an encapsulated STL stream. * @return true if STL stream was created. */ bool hasStream() const; private: /** * Prevent use of default copy constructor. */ UniCharMessageBuffer(const UniCharMessageBuffer&); /** * Prevent use of default assignment operator. */ UniCharMessageBuffer& operator=(const UniCharMessageBuffer&); /** * Encapsulated std::string. */ std::basic_string<UniChar> buf; /** * Encapsulated stream, created on demand. */ std::basic_ostringstream<UniChar>* stream; };template<class V>UniCharMessageBuffer::uostream& operator<<(UniCharMessageBuffer& os, const V& val) { return ((UniCharMessageBuffer::uostream&) os) << val;}#endif#if LOG4CXX_WCHAR_T_API /** * This class is designed to support insertion operations * in the message argument to the LOG4CXX_INFO and similar * macros and is not designed for general purpose use. */ class LOG4CXX_EXPORT WideMessageBuffer { public: /** * Creates a new instance. */ WideMessageBuffer(); /** * Destructor. */ ~WideMessageBuffer(); /** * Appends string to buffer. * @param msg string append. * @return this buffer. */ WideMessageBuffer& operator<<(const std::basic_string<wchar_t>& msg); /** * Appends string to buffer. * @param msg string to append. * @return this buffer. */ WideMessageBuffer& operator<<(const wchar_t* msg); /** * Appends string to buffer. * @param msg string to append. * @return this buffer. */ WideMessageBuffer& operator<<(wchar_t* msg); /** * Appends character to buffer. * @param msg character to append. * @return this buffer. */ WideMessageBuffer& operator<<(const wchar_t msg); /** * Insertion operator for STL manipulators such as std::fixed. * @param manip manipulator.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -