DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20684>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20684

Suggestion to optionally avoid a dependency on iostreams

           Summary: Suggestion to optionally avoid a dependency on iostreams
           Product: Xerces-C++
           Version: Nightly build (please specify the date)
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Miscellaneous
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


Xerces has - at least in Visual C++ - only one dependency on the standard C++
library, and that is the use of cout (iostream) in StdOutFormatTarget. The
run-time support for the standard C++ library, again in Visual C++, is
implemented in a separate run-time library (MSVCP7x.DLL for VC++ 7.x) than
the CRT (MSVCR7x.DLL). If one were able to avoid using cout, the Xerces DLL
would not need to import anything from MSVCP7x.DLL, thus both freeing some
memory and startup initialization resources, as well as relieving the Xerces
users from having to distribute this DLL with their applications. The CRT
stream I/O is most cases also faster than the iostreams, and hardly ever any
slower.

Below is the important parts of a modified version of StdOutFormatTarget.cpp
(taken from the CVS on June 11) that conditionally uses either iostreams or the CRT's 
stream I/O, based on the state of the made up preprocessor definition
"XERCES_USE_IOSTREAMS". What do you think? Would it be possible to add it to
the Xerces sources, or does it break some design rationale?

#include <xercesc/framework/StdOutFormatTarget.hpp>

#if defined(XERCES_USE_IOSTREAMS)
 #if defined(XERCES_NEW_IOSTREAMS)
 #include <iostream>
 #else
 #include <iostream.h>
 #endif
#else
 #include <stdio.h>
#endif

XERCES_CPP_NAMESPACE_BEGIN

StdOutFormatTarget::StdOutFormatTarget()
{}

StdOutFormatTarget::~StdOutFormatTarget()
{}

void StdOutFormatTarget::flush()
{
#if defined(XERCES_USE_IOSTREAMS)
    XERCES_STD_QUALIFIER cout.flush();
#else
    fflush(stdout);
#endif
}

void StdOutFormatTarget::writeChars(const XMLByte* const  toWrite
                                  , const unsigned int    count
                                  , XMLFormatter* const   formatter)
{
#if defined(XERCES_USE_IOSTREAMS)
    // Surprisingly, Solaris was the only platform on which
    // required the char* cast to print out the string correctly.
    // Without the cast, it was printing the pointer value in hex.
    // Quite annoying, considering every other platform printed
    // the string with the explicit cast to char* below.
    XERCES_STD_QUALIFIER cout.write((char *) toWrite, (int) count);
    XERCES_STD_QUALIFIER cout.flush();
#else
    fwrite(toWrite, sizeof(XMLByte), (size_t)count, stdout);
    fflush(stdout);
#endif
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to