Author: carnold
Date: Thu Nov 8 00:33:24 2007
New Revision: 593064
URL: http://svn.apache.org/viewvc?rev=593064&view=rev
Log:
LOGCXX-18: Works VC7, ambiguity with VC6
Modified:
logging/log4cxx/trunk/src/examples/cpp/stream.cpp
logging/log4cxx/trunk/src/main/cpp/logstream.cpp
logging/log4cxx/trunk/src/main/include/log4cxx/stream.h
Modified: logging/log4cxx/trunk/src/examples/cpp/stream.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/examples/cpp/stream.cpp?rev=593064&r1=593063&r2=593064&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/examples/cpp/stream.cpp (original)
+++ logging/log4cxx/trunk/src/examples/cpp/stream.cpp Thu Nov 8 00:33:24 2007
@@ -25,7 +25,7 @@
using namespace log4cxx;
using namespace log4cxx::helpers;
-int xmain()
+int main()
{
setlocale(LC_ALL, "");
int result = EXIT_SUCCESS;
Modified: logging/log4cxx/trunk/src/main/cpp/logstream.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/logstream.cpp?rev=593064&r1=593063&r2=593064&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/logstream.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/logstream.cpp Thu Nov 8 00:33:24 2007
@@ -21,6 +21,16 @@
using namespace log4cxx;
+logstream_base::logstream_ios_base::logstream_ios_base(std::ios_base::fmtflags
initval,
+ int initsize) {
+ memset(this, 0, sizeof(*this));
+ flags(initval);
+ precision(initsize);
+ width(initsize);
+
+}
+
+
logstream_base::logstream_base(const LoggerPtr& log,
const LevelPtr& lvl) : initset((std::ios_base::fmtflags) -1, 1),
initclear((std::ios_base::fmtflags) 0, 0), logger(log), level(lvl),
location(), fillchar(0), fillset(false) {
@@ -30,22 +40,11 @@
logstream_base::~logstream_base() {
}
-logstream_base& logstream_base::operator<<(std::ios_base&
(*manip)(std::ios_base&)) {
+void logstream_base::insert(std::ios_base& (*manip)(std::ios_base&)) {
get_stream_state(initclear, initset, fillchar, fillset);
(*manip)(initset);
(*manip)(initclear);
refresh_stream_state();
- return *this;
-}
-
-logstream_base& logstream_base::operator<<(logstream_base&
(*manip)(logstream_base&)) {
- (*manip)(*this);
- return *this;
-}
-
-logstream_base& logstream_base::operator<<(const LevelPtr& level) {
- setLevel(level);
- return *this;
}
bool logstream_base::set_stream_state(std::ios_base& dest, int& dstchar) {
@@ -63,16 +62,21 @@
return fillset;
}
-logstream_base& logstream_base::log(logstream_base& stream) {
- stream.log();
+logstream_base& logstream_base::endmsg(logstream_base& stream) {
+ stream.end_message();
return stream;
}
-void logstream_base::log() {
+void logstream_base::end_message() {
if (isEnabled()) {
log(logger, level, location);
}
erase();
+}
+
+
+logstream_base& logstream_base::nop(logstream_base& stream) {
+ return stream;
}
@@ -162,8 +166,213 @@
}
}
-logstream_base& logstream_base::operator<<(const log4cxx::spi::LocationInfo&
newlocation) {
- setLocation(newlocation);
- return *this;
-}
-
+
+logstream::logstream(const log4cxx::LoggerPtr& logger,
+ const log4cxx::LevelPtr& level) : logstream_base(logger,
level), stream(0) {
+}
+
+logstream::logstream(const Ch* loggerName,
+ const log4cxx::LevelPtr& level)
+ :
logstream_base(log4cxx::Logger::getLogger(loggerName), level), stream(0) {
+}
+
+
+logstream::logstream(const std::basic_string<Ch>& loggerName,
+ const log4cxx::LevelPtr& level) :
logstream_base(log4cxx::Logger::getLogger(loggerName), level), stream(0) {
+}
+
+logstream::~logstream() {
+ delete stream;
+}
+
+logstream& logstream::operator<<(logstream_base& (*manip)(logstream_base&)) {
+ (*manip)(*this);
+ return *this;
+}
+
+logstream& logstream::operator<<(const LevelPtr& level) {
+ setLevel(level);
+ return *this;
+}
+
+logstream& logstream::operator<<(const log4cxx::spi::LocationInfo&
newlocation) {
+ setLocation(newlocation);
+ return *this;
+}
+
+logstream& logstream::operator>>(const log4cxx::spi::LocationInfo&
newlocation) {
+ setLocation(newlocation);
+ return *this;
+}
+
+
+
+
+logstream& logstream::operator<<(std::ios_base& (*manip)(std::ios_base&)) {
+ logstream_base::insert(manip);
+ return *this;
+}
+
+logstream::operator std::basic_ostream<char>&() {
+ if (stream == 0) {
+ stream = new std::basic_stringstream<Ch>();
+ refresh_stream_state();
+ }
+ return *stream;
+}
+
+void logstream::log(LoggerPtr& logger,
+ const LevelPtr& level,
+ const log4cxx::spi::LocationInfo& location) {
+ if (stream != 0) {
+ std::basic_string<Ch> msg = stream->str();
+ if (!msg.empty()) {
+ logger->log(level, msg, location);
+ }
+ }
+}
+
+
+void logstream::erase() {
+ if (stream != 0) {
+ std::basic_string<Ch> emptyStr;
+ stream->str(emptyStr);
+ }
+}
+
+
+void logstream::get_stream_state(std::ios_base& base,
+ std::ios_base& mask,
+ int& fill,
+ bool& fillSet) const {
+ if (stream != 0) {
+ std::ios_base::fmtflags flags = stream->flags();
+ base.flags(flags);
+ mask.flags(flags);
+ int width = stream->width();
+ base.width(width);
+ mask.width(width);
+ int precision = stream->precision();
+ base.precision(precision);
+ mask.precision(precision);
+ fill = stream->fill();
+ fillSet = true;
+ }
+}
+
+void logstream::refresh_stream_state() {
+ if (stream != 0) {
+ int fillchar;
+ if(logstream_base::set_stream_state(*stream, fillchar)) {
+ stream->fill(fillchar);
+ }
+ }
+}
+
+
+#if LOG4CXX_HAS_WCHAR_T
+
+wlogstream::wlogstream(const log4cxx::LoggerPtr& logger,
+ const log4cxx::LevelPtr& level) : logstream_base(logger,
level), stream(0) {
+}
+
+wlogstream::wlogstream(const Ch* loggerName,
+ const log4cxx::LevelPtr& level)
+ :
logstream_base(log4cxx::Logger::getLogger(loggerName), level), stream(0) {
+}
+
+
+wlogstream::wlogstream(const std::basic_string<Ch>& loggerName,
+ const log4cxx::LevelPtr& level) :
logstream_base(log4cxx::Logger::getLogger(loggerName), level), stream(0) {
+}
+
+wlogstream::~wlogstream() {
+ delete stream;
+}
+
+wlogstream& wlogstream::operator<<(logstream_base& (*manip)(logstream_base&)) {
+ (*manip)(*this);
+ return *this;
+}
+
+wlogstream& wlogstream::operator<<(const LevelPtr& level) {
+ setLevel(level);
+ return *this;
+}
+
+wlogstream& wlogstream::operator<<(const log4cxx::spi::LocationInfo&
newlocation) {
+ setLocation(newlocation);
+ return *this;
+}
+
+wlogstream& wlogstream::operator>>(const log4cxx::spi::LocationInfo&
newlocation) {
+ setLocation(newlocation);
+ return *this;
+}
+
+
+
+
+wlogstream& wlogstream::operator<<(std::ios_base& (*manip)(std::ios_base&)) {
+ logstream_base::insert(manip);
+ return *this;
+}
+
+wlogstream::operator std::basic_ostream<wchar_t>&() {
+ if (stream == 0) {
+ stream = new std::basic_stringstream<Ch>();
+ refresh_stream_state();
+ }
+ return *stream;
+}
+
+void wlogstream::log(LoggerPtr& logger,
+ const LevelPtr& level,
+ const log4cxx::spi::LocationInfo& location) {
+ if (stream != 0) {
+ std::basic_string<Ch> msg = stream->str();
+ if (!msg.empty()) {
+ logger->log(level, msg, location);
+ }
+ }
+}
+
+
+void wlogstream::erase() {
+ if (stream != 0) {
+ std::basic_string<Ch> emptyStr;
+ stream->str(emptyStr);
+ }
+}
+
+
+void wlogstream::get_stream_state(std::ios_base& base,
+ std::ios_base& mask,
+ int& fill,
+ bool& fillSet) const {
+ if (stream != 0) {
+ std::ios_base::fmtflags flags = stream->flags();
+ base.flags(flags);
+ mask.flags(flags);
+ int width = stream->width();
+ base.width(width);
+ mask.width(width);
+ int precision = stream->precision();
+ base.precision(precision);
+ mask.precision(precision);
+ fill = stream->fill();
+ fillSet = true;
+ }
+}
+
+void wlogstream::refresh_stream_state() {
+ if (stream != 0) {
+ int fillchar;
+ if(logstream_base::set_stream_state(*stream, fillchar)) {
+ stream->fill(fillchar);
+ }
+ }
+}
+#endif
+
+
Modified: logging/log4cxx/trunk/src/main/include/log4cxx/stream.h
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/stream.h?rev=593064&r1=593063&r2=593064&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/stream.h (original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/stream.h Thu Nov 8 00:33:24
2007
@@ -24,7 +24,8 @@
namespace log4cxx
{
- /**
+
+ /**
* Base class for the basic_logstream template which attempts
* to emulate std::basic_ostream but attempts to short-circuit
* unnecessary operations.
@@ -50,19 +51,7 @@
/**
* Insertion operator for std::fixed and similar manipulators.
*/
- logstream_base& operator<<(std::ios_base&
(*manip)(std::ios_base&));
- /**
- * Insertion operator for logstream_base::log.
- */
- logstream_base& operator<<(logstream_base&
(*manip)(logstream_base&));
- /**
- * Insertion operator for level.
- */
- logstream_base& operator<<(const log4cxx::LevelPtr& level);
- /**
- * Insertion operator for location.
- */
- logstream_base& operator<<(const log4cxx::spi::LocationInfo&
location);
+ void insert(std::ios_base& (*manip)(std::ios_base&));
/**
* get precision.
@@ -106,15 +95,22 @@
/**
- * log manipulator.
+ * end of message manipulator, triggers logging.
*/
- static logstream_base& log(logstream_base&);
+ static logstream_base& endmsg(logstream_base&);
+
/**
- * log operation.
+ * end of message action.
*/
- void log();
-
+ void end_message();
+
+ /**
+ * no operation manipulator, used to workaround compiler defects.
+ */
+ static logstream_base& nop(logstream_base&);
+
+
/**
* Set the level.
* @param level level
@@ -185,12 +181,7 @@
class logstream_ios_base : public std::ios_base {
public:
logstream_ios_base(std::ios_base::fmtflags initval,
- int initsize) {
- flags(initval);
- precision(initsize);
- width(initsize);
-
- }
+ int initsize);
} initset, initclear;
/**
* fill character.
@@ -218,83 +209,180 @@
log4cxx::spi::LocationInfo location;
};
-
+ typedef logstream_base& (*logstream_manipulator)(logstream_base&);
+
/**
- * Template for a STL-like stream API for log4cxx. Instances of
log4cxx::basic_logstream
- * are emphatically not for use by multiple threads and in general
should be short-lived
+ * An STL-like stream API for log4cxx using char as the character
type.
+ *. Instances of log4cxx::logstream
+ * are not designedfor use by multiple threads and in general should
be short-lived
* function scoped objects. Using log4cxx::basic_logstream as a
class member or
* static instance should be avoided in the same manner as you would
avoid placing a std::ostringstream
* in those locations. Insertion operations are generally
short-circuited if the
* level for the stream is not the same of higher that the level of
the associated logger.
*/
- template <class Ch>
- class LOG4CXX_EXPORT basic_logstream : public logstream_base {
+ class LOG4CXX_EXPORT logstream : public logstream_base {
+ typedef char Ch;
public:
/**
* Constructor.
*/
- inline basic_logstream(const log4cxx::LoggerPtr& logger,
- const log4cxx::LevelPtr& level) : logstream_base(logger,
level), stream(0) {
- }
+ logstream(const log4cxx::LoggerPtr& logger,
+ const log4cxx::LevelPtr& level);
/**
* Constructor.
*/
- inline basic_logstream(const Ch* loggerName,
- const log4cxx::LevelPtr& level) :
logstream_base(log4cxx::Logger::getLogger(loggerName), level), stream(0) {
- }
+ logstream(const Ch* loggerName,
+ const log4cxx::LevelPtr& level);
/**
* Constructor.
*/
- inline basic_logstream(const std::basic_string<Ch>& loggerName,
- const log4cxx::LevelPtr& level) :
logstream_base(log4cxx::Logger::getLogger(loggerName), level), stream(0) {
- }
+ logstream(const std::basic_string<Ch>& loggerName,
+ const log4cxx::LevelPtr& level);
- inline ~basic_logstream() {
- }
+ ~logstream();
/**
* Insertion operator for std::fixed and similar manipulators.
*/
- inline basic_logstream& operator<<(std::ios_base&
(*manip)(std::ios_base&)) {
- logstream_base::operator<<(manip);
- return *this;
- }
+ logstream& operator<<(std::ios_base& (*manip)(std::ios_base&));
/**
- * Insertion operator for logstream_base::log.
+ * Insertion operator for logstream_base::endmsg.
*/
- inline basic_logstream& operator<<(logstream_base&
(*manip)(logstream_base&)) {
- logstream_base::operator<<(manip);
- return *this;
- }
+ logstream& operator<<(logstream_manipulator manip);
+
+ /**
+ * Insertion operator for level.
+ */
+ logstream& operator<<(const log4cxx::LevelPtr& level);
+ /**
+ * Insertion operator for location.
+ */
+ logstream& operator<<(const log4cxx::spi::LocationInfo& location);
+
+ /**
+ * Alias for insertion operator for location. Kludge to avoid
+ * inappropriate compiler ambiguity.
+ */
+ logstream& operator>>(const log4cxx::spi::LocationInfo& location);
/**
- * Insertion operator for level.
+ * Template to allow any class with an std::basic_ostream inserter
+ * to be applied to this class.
*/
- inline basic_logstream& operator<<(const log4cxx::LevelPtr& level)
{
- logstream_base::operator<<(level);
+ template <class V>
+ inline logstream& operator<<(const V& val) {
+ if (LOG4CXX_UNLIKELY(isEnabled())) {
+ ((std::basic_ostream<Ch>&) *this) << val;
+ }
return *this;
}
+
+
+ /**
+ * Cast operator to provide access to embedded
std::basic_ostream.
+ */
+ operator std::basic_ostream<Ch>&();
+
+ protected:
+ /**
+ * [EMAIL PROTECTED]
+ */
+ virtual void log(LoggerPtr& logger,
+ const LevelPtr& level,
+ const log4cxx::spi::LocationInfo& location);
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ virtual void erase();
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ virtual void get_stream_state(std::ios_base& base,
+ std::ios_base& mask,
+ int& fill,
+ bool& fillSet) const;
+ /**
+ * [EMAIL PROTECTED]
+ */
+ virtual void refresh_stream_state();
+
+
+ private:
+ std::basic_stringstream<Ch>* stream;
+
+ };
+
+#if LOG4CXX_HAS_WCHAR_T
+ /**
+ * An STL-like stream API for log4cxx using wchar_t as the character
type.
+ *. Instances of log4cxx::logstream
+ * are not designedfor use by multiple threads and in general should
be short-lived
+ * function scoped objects. Using log4cxx::basic_logstream as a
class member or
+ * static instance should be avoided in the same manner as you would
avoid placing a std::ostringstream
+ * in those locations. Insertion operations are generally
short-circuited if the
+ * level for the stream is not the same of higher that the level of
the associated logger.
+ */
+ class LOG4CXX_EXPORT wlogstream : public logstream_base {
+ typedef wchar_t Ch;
+ public:
+ /**
+ * Constructor.
+ */
+ wlogstream(const log4cxx::LoggerPtr& logger,
+ const log4cxx::LevelPtr& level);
+
+ /**
+ * Constructor.
+ */
+ wlogstream(const Ch* loggerName,
+ const log4cxx::LevelPtr& level);
+
+ /**
+ * Constructor.
+ */
+ wlogstream(const std::basic_string<Ch>& loggerName,
+ const log4cxx::LevelPtr& level);
+
+ ~wlogstream();
+
+ /**
+ * Insertion operator for std::fixed and similar manipulators.
+ */
+ wlogstream& operator<<(std::ios_base& (*manip)(std::ios_base&));
+
+ /**
+ * Insertion operator for wlogstream_base::endmsg.
+ */
+ wlogstream& operator<<(logstream_base&
(*manip)(logstream_base&));
+
+ /**
+ * Insertion operator for level.
+ */
+ wlogstream& operator<<(const log4cxx::LevelPtr& level);
/**
* Insertion operator for location.
*/
- inline basic_logstream& operator<<(const
log4cxx::spi::LocationInfo& location) {
- logstream_base::operator<<(location);
- return *this;
- }
+ wlogstream& operator<<(const log4cxx::spi::LocationInfo& location);
+ /**
+ * Alias for insertion operator for location. Kludge to avoid
+ * inappropriate compiler ambiguity.
+ */
+ wlogstream& operator>>(const log4cxx::spi::LocationInfo&
location);
/**
* Template to allow any class with an std::basic_ostream inserter
* to be applied to this class.
*/
template <class V>
- inline basic_logstream& operator<<(const V& val) {
+ inline wlogstream& operator<<(const V& val) {
if (LOG4CXX_UNLIKELY(isEnabled())) {
- std::basic_ostream<Ch>& os = *this;
- os << val;
+ ((std::basic_ostream<Ch>&) *this) << val;
}
return *this;
}
@@ -303,13 +391,7 @@
/**
* Cast operator to provide access to embedded
std::basic_ostream.
*/
- inline operator std::basic_ostream<Ch>&() {
- if (stream == 0) {
- stream = new std::basic_stringstream<Ch>();
- refresh_stream_state();
- }
- return *stream;
- }
+ operator std::basic_ostream<Ch>&();
protected:
/**
@@ -317,24 +399,12 @@
*/
virtual void log(LoggerPtr& logger,
const LevelPtr& level,
- const log4cxx::spi::LocationInfo& location) {
- if (stream != 0) {
- std::basic_string<Ch> msg = stream->str();
- if (!msg.empty()) {
- logger->log(level, msg, location);
- }
- }
- }
+ const log4cxx::spi::LocationInfo& location);
/**
* [EMAIL PROTECTED]
*/
- virtual void erase() {
- if (stream != 0) {
- std::basic_string<Ch> emptyStr;
- stream->str(emptyStr);
- }
- }
+ virtual void erase();
/**
* [EMAIL PROTECTED]
@@ -342,42 +412,17 @@
virtual void get_stream_state(std::ios_base& base,
std::ios_base& mask,
int& fill,
- bool& fillSet) const {
- if (stream != 0) {
- std::ios_base::fmtflags flags = stream->flags();
- base.flags(flags);
- mask.flags(flags);
- int width = stream->width();
- base.width(width);
- mask.width(width);
- int precision = stream->precision();
- base.precision(precision);
- mask.precision(precision);
- fill = stream->fill();
- fillSet = true;
- }
- }
+ bool& fillSet) const;
/**
* [EMAIL PROTECTED]
*/
- virtual void refresh_stream_state() {
- if (stream != 0) {
- int fillchar;
- if(logstream_base::set_stream_state(*stream, fillchar)) {
- stream->fill(fillchar);
- }
- }
- }
+ virtual void refresh_stream_state();
private:
std::basic_stringstream<Ch>* stream;
};
-
- typedef basic_logstream<char> logstream;
-#if LOG4CXX_HAS_WCHAR_T
- typedef basic_logstream<wchar_t> wlogstream;
#endif
@@ -385,7 +430,11 @@
#if !defined(LOG4CXX_ENDMSG)
-#define LOG4CXX_ENDMSG LOG4CXX_LOCATION << log4cxx::logstream_base::log;
+#if defined(_MSC_VER) && _MSC_VER <= 1200
+#define LOG4CXX_ENDMSG LOG4CXX_LOCATION << (log4cxx::logstream_manipulator)
log4cxx::logstream_base::endmsg;
+#else
+#define LOG4CXX_ENDMSG LOG4CXX_LOCATION << log4cxx::logstream_base::endmsg;
+#endif
#endif