Usage of the LogString type

To avoid many #ifdefs in the log4cxx source code, several macros exist which can be used to work with the LogString type. Usually these macros are used to convert between the internal LogString representation and external string representations like char* or wchar_t*.

Creating a LogString from a string literal

The macro LOG4CXX_STR must be used to create string and character literals. The type generated by LOG4CXX_STR is compatible to the LogString type.

Example:

LogString getValue() {
  return LOG4CXX_STR("Some Value");
}

Converting a LogString into an std::string

LOG4CXX_ENCODE_CHAR(var, src);

This macro creates a local variable called var of type std::string and writes the contents of the src parameter of type LogString into this variable.

Converting an std::string into a LogString

LOG4CXX_DECODE_CHAR(var, src);

This macro creates a local variable called var of type LogString and writes the contents of the src parameter of type std::string into this variable.

Converting a LogString into an std::wstring

LOG4CXX_ENCODE_WCHAR(var, src);

This macro creates a local variable called var of type std::wstring and writes the contents of the src parameter of type LogString into this variable.

Converting an std::wstring into a LogString

LOG4CXX_DECODE_WCHAR

This macro creates a local variable called var of type LogString and writes the contents of the src parameter of type std::wstring into this variable.

logStringUsage (last edited 2009-09-20 23:45:57 by localhost)