You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2007/11/09 19:28:56 UTC

svn commit: r593616 - in /logging/log4cxx/trunk/src/main: cpp/messagebuffer.cpp include/log4cxx/helpers/messagebuffer.h

Author: carnold
Date: Fri Nov  9 10:28:55 2007
New Revision: 593616

URL: http://svn.apache.org/viewvc?rev=593616&view=rev
Log:
LOGCXX-18: move op<<(manip) into class, remove func bodies from messagebuffer.h

Modified:
    logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp
    logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h

Modified: logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp?rev=593616&r1=593615&r2=593616&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp Fri Nov  9 10:28:55 2007
@@ -81,6 +81,11 @@
     return (stream != 0);
 }
 
+std::ostream& CharMessageBuffer::operator<<(ios_base_manip manip) {
+	std::ostream& s = *this;
+	(*manip)(s);
+	return s;
+}
 
 
 
@@ -146,6 +151,11 @@
     return (stream != 0);
 }
 
+std::wostream& WideMessageBuffer::operator<<(ios_base_manip manip) {
+	std::wostream& s = *this;
+	(*manip)(s);
+	return s;
+}
 
 
 MessageBuffer::MessageBuffer()  : wbuf(0){
@@ -158,5 +168,57 @@
 bool MessageBuffer::hasStream() const {
     return cbuf.hasStream() || (wbuf != 0 && wbuf->hasStream());
 }
+
+std::ostream& MessageBuffer::operator<<(ios_base_manip manip) {
+	std::ostream& s = *this;
+	(*manip)(s);
+	return s;
+}
+
+MessageBuffer::operator std::ostream&() {
+	return (std::ostream&) cbuf;
+}
+
+CharMessageBuffer& MessageBuffer::operator<<(const std::string& msg) {
+	return cbuf.operator<<(msg);
+}
+
+CharMessageBuffer& MessageBuffer::operator<<(const char* msg) {
+	return cbuf.operator<<(msg);
+}
+
+CharMessageBuffer& MessageBuffer::operator<<(const char msg) {
+	return cbuf.operator<<(msg);
+}
+
+const std::string& MessageBuffer::str(CharMessageBuffer& buf) {
+	return cbuf.str(buf);
+}
+
+const std::string& MessageBuffer::str(std::ostream& os) {
+	return cbuf.str(os);
+}
+
+WideMessageBuffer& MessageBuffer::operator<<(const std::wstring& msg) {
+	wbuf = new WideMessageBuffer();
+	return (*wbuf) << msg;
+}
+
+WideMessageBuffer& MessageBuffer::operator<<(const wchar_t* msg) {
+	wbuf = new WideMessageBuffer();
+	return (*wbuf) << msg;
+}
+WideMessageBuffer& MessageBuffer::operator<<(const wchar_t msg) {
+	wbuf = new WideMessageBuffer();
+	return (*wbuf) << msg;
+}
+
+const std::wstring& MessageBuffer::str(WideMessageBuffer& buf) {
+	return wbuf->str(buf);
+}
+
+const std::wstring& MessageBuffer::str(std::wostream& os) {
+	return wbuf->str(os);
+}
 
 #endif

Modified: logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h?rev=593616&r1=593615&r2=593616&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h (original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h Fri Nov  9 10:28:55 2007
@@ -27,6 +27,7 @@
 
    namespace helpers {
    
+   typedef std::ios_base& (*ios_base_manip)(std::ios_base&);
 
    /**
     *   This class is used by the LOG4CXX_INFO and similar
@@ -65,6 +66,13 @@
          */
         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);
+
 		/**
 		 *  Cast to ostream.
 		 */
@@ -115,13 +123,6 @@
 	return ((std::basic_ostream<char>&) os) << val;
 }
 
-inline std::basic_ostream<char>& operator<<(CharMessageBuffer& os, std::ios_base& (*manip)(std::ios_base& s)) {
-	std::basic_ostream<char>& s = os;
-	(*manip)(s);
-	return s;
-}
-
-
 #if LOG4CXX_HAS_WCHAR_T
    /**
     *   This class is designed to support insertion operations
@@ -160,7 +161,14 @@
          */
         WideMessageBuffer& operator<<(const wchar_t msg);
 
-		/**
+        /**
+         *   Insertion operator for STL manipulators such as std::fixed.
+         *   @param manip manipulator.
+         *   @return encapsulated STL stream.
+         */
+        std::wostream& operator<<(ios_base_manip manip);
+
+        /**
 		 *  Cast to ostream.
 		 */
 		operator std::basic_ostream<wchar_t>&();
@@ -210,13 +218,6 @@
 	return ((std::basic_ostream<wchar_t>&) os) << val;
 }
 
-inline std::basic_ostream<wchar_t>& operator<<(WideMessageBuffer& os, std::ios_base& (*manip)(std::ios_base& s)) {
-	std::basic_ostream<wchar_t>& s = os;
-	(*manip)(s);
-	return s;
-}
-
-
 
    /**
     *   This class is used by the LOG4CXX_INFO and similar
@@ -237,9 +238,7 @@
 		/**
 		 *  Cast to ostream.
 		 */
-		inline operator std::ostream&() {
-			return (std::ostream&) cbuf;
-        }
+		operator std::ostream&();
 
 	   /**
          *   Appends a string into the buffer and
@@ -247,18 +246,14 @@
          *   @param msg message to append.
          *   @return encapsulated CharMessageBuffer.
          */
-        inline CharMessageBuffer& operator<<(const std::string& msg) {
-			return cbuf.operator<<(msg);
-		}
+        CharMessageBuffer& operator<<(const std::string& msg);
         /**
          *   Appends a string into the buffer and
          *   fixes the buffer to use char characters.
          *   @param msg message to append.
          *   @return encapsulated CharMessageBuffer.
          */
-        inline CharMessageBuffer& operator<<(const char* msg) {
-			return cbuf.operator<<(msg);
-		}
+        CharMessageBuffer& operator<<(const char* msg);
 
         /**
          *   Appends a string into the buffer and
@@ -266,9 +261,7 @@
          *   @param msg message to append.
          *   @return encapsulated CharMessageBuffer.
          */
-        inline CharMessageBuffer& operator<<(const char msg) {
-			return cbuf.operator<<(msg);
-		}
+        CharMessageBuffer& operator<<(const char msg);
 
 		/**
 		 *   Get content of buffer.
@@ -276,9 +269,7 @@
 		 *       the character type and that
 		 *       the embedded stream was not used.
 		 */
-		inline const std::string& str(CharMessageBuffer& buf) {
-			return cbuf.str(buf);
-		}
+		const std::string& str(CharMessageBuffer& buf);
 
 		/**
 		 *   Get content of buffer.
@@ -286,9 +277,7 @@
 		 *       the character type and that
 		 *       the embedded stream was used.
 		 */
-		inline const std::string& str(std::ostream& os) {
-			return cbuf.str(os);
-		}
+		const std::string& str(std::ostream& os);
 
 	   /**
          *   Appends a string into the buffer and
@@ -296,30 +285,28 @@
          *   @param msg message to append.
          *   @return encapsulated CharMessageBuffer.
          */
-        inline WideMessageBuffer& operator<<(const std::wstring& msg) {
-			wbuf = new WideMessageBuffer();
-			return (*wbuf) << msg;
-		}
+        WideMessageBuffer& operator<<(const std::wstring& msg);
         /**
          *   Appends a string into the buffer and
          *   fixes the buffer to use char characters.
          *   @param msg message to append.
          *   @return encapsulated CharMessageBuffer.
          */
-        inline WideMessageBuffer& operator<<(const wchar_t* msg) {
-			wbuf = new WideMessageBuffer();
-			return (*wbuf) << msg;
-		}
+        WideMessageBuffer& operator<<(const wchar_t* msg);
         /**
          *   Appends a string into the buffer and
          *   fixes the buffer to use char characters.
          *   @param msg message to append.
          *   @return encapsulated CharMessageBuffer.
          */
-        inline WideMessageBuffer& operator<<(const wchar_t msg) {
-			wbuf = new WideMessageBuffer();
-			return (*wbuf) << msg;
-		}
+        WideMessageBuffer& operator<<(const wchar_t msg);
+
+        /**
+         *   Insertion operator for STL manipulators such as std::fixed.
+         *   @param manip manipulator.
+         *   @return encapsulated STL stream.
+         */
+        std::ostream& operator<<(ios_base_manip manip);
 
 		/**
 		 *   Get content of buffer.
@@ -327,9 +314,7 @@
 		 *       the character type and that
 		 *       the embedded stream was not used.
 		 */
-		inline const std::wstring& str(WideMessageBuffer& buf) {
-			return wbuf->str(buf);
-		}
+		const std::wstring& str(WideMessageBuffer& buf);
 
 		/**
 		 *   Get content of buffer.
@@ -337,9 +322,7 @@
 		 *       the character type and that
 		 *       the embedded stream was used.
 		 */
-		inline const std::wstring& str(std::wostream& os) {
-			return wbuf->str(os);
-		}
+		const std::wstring& str(std::wostream& os);
 
         /**
          *  Returns true if buffer has an encapsulated STL stream.
@@ -371,12 +354,6 @@
 template<class V>
 std::ostream& operator<<(MessageBuffer& os, const V& val) {
 	return ((std::ostream&) os) << val;
-}
-
-inline std::ostream& operator<<(MessageBuffer& os, std::ios_base& (*manip)(std::ios_base& s)) {
-	std::ostream& s = os;
-	(*manip)(s);
-	return s;
 }
 
 #if LOG4CXX_LOGCHAR_IS_UTF8