ofstd/include/dcmtk/ofstd/ofstream.h

00001 /*
00002  *
00003  *  Copyright (C) 2002-2010, OFFIS e.V.
00004  *  All rights reserved.  See COPYRIGHT file for details.
00005  *
00006  *  This software and supporting documentation were developed by
00007  *
00008  *    OFFIS e.V.
00009  *    R&D Division Health
00010  *    Escherweg 2
00011  *    D-26121 Oldenburg, Germany
00012  *
00013  *
00014  *  Module:  ofstd
00015  *
00016  *  Author:  Andreas Barth
00017  *
00018  *  Purpose: C++ header to handle standard and old stream libraries.
00019  *
00020  *  Last Update:      $Author: joergr $
00021  *  Update Date:      $Date: 2010-10-14 13:15:50 $
00022  *  CVS/RCS Revision: $Revision: 1.11 $
00023  *  Status:           $State: Exp $
00024  *
00025  *  CVS/RCS Log at end of file
00026  *
00027  */
00028 
00029 
00030 #ifndef OFSTREAM_H
00031 #define OFSTREAM_H
00032 
00033 #include "dcmtk/config/osconfig.h"
00034 
00035 #ifdef USE_STD_CXX_INCLUDES
00036 
00037 #include <iostream>
00038 #ifdef HAVE_IOS
00039 #include <ios>
00040 #endif
00041 #include <fstream>
00042 #include <iomanip>
00043 // For standard STREAMS library: preference for standard stringstream
00044 #if defined(HAVE_SSTREAM)
00045 #include <sstream>
00046 #define USE_STRINGSTREAM
00047 #elif defined(HAVE_STRSTREAM)
00048 #include <strstream>
00049 #else
00050 #error DCMTK needs stringstream or strstream type
00051 #endif
00052 
00053 /* DCMTK by default does not anymore pollute the default namespace by 
00054  * importing namespace std. Earlier releases did this to simplify compatibility
00055  * with older compilers where STL classes were not consistently defined
00056  * in namespace std. We now have configure macros which should care for this.
00057  * If user code still relies on namespace std to be included, compile with
00058  * macro USING_STD_NAMESPACE defined.
00059  */
00060 #ifdef USING_STD_NAMESPACE
00061 namespace std { }
00062 using namespace std;
00063 #endif
00064 
00065 #else /* USE_STD_CXX_INCLUDES */
00066 
00067 #include <iostream.h>
00068 #include <fstream.h>
00069 // For old STREAMS library: preference for strstream
00070 #if defined(HAVE_STRSTREA_H) || defined(HAVE_STRSTREAM_H)
00071 #ifdef HAVE_STRSTREA_H
00072 #include <strstrea.h>
00073 #else
00074 #include <strstream.h>
00075 #endif
00076 #elif defined(HAVE_SSTREAM_H)
00077 #include <sstream.h>
00078 #define USE_STRINGSTREAM
00079 #else
00080 #error DCMTK needs stringstream or strstream type
00081 #endif
00082 #include <iomanip.h>
00083 
00084 #endif 
00085 
00086 #ifdef USE_STRINGSTREAM
00087 
00088 // define STD_NAMESPACE to std:: if the standard namespace exists
00089 #ifndef STD_NAMESPACE
00090 #ifdef HAVE_STD_NAMESPACE
00091 #define STD_NAMESPACE std::
00092 #else
00093 #define STD_NAMESPACE
00094 #endif
00095 #endif
00096 
00097 #define OFendl STD_NAMESPACE endl
00098 
00099 typedef STD_NAMESPACE stringstream OFStringStream;
00100 typedef STD_NAMESPACE ostringstream OFOStringStream;
00101 typedef STD_NAMESPACE istringstream OFIStringStream;
00102 
00103 #define OFStringStream_ends ""
00104 #define OFSTRINGSTREAM_GETOFSTRING(oss, string) \
00105     OFString string((oss).str().c_str());
00106 // The following two macros define a block structure. Please note that variables
00107 // declared between xxx_GETSTR and xxx_FREESTR are only valid within this scope.
00108 #define OFSTRINGSTREAM_GETSTR(oss, chptr) \
00109 { \
00110     STD_NAMESPACE string chptr##__ = (oss).str(); \
00111     const char *chptr = chptr##__.c_str();
00112 #define OFSTRINGSTREAM_FREESTR(chptr) \
00113 }
00114 
00115 #else /* USE_STRINGSTREAM */
00116 
00117 typedef strstream OFStringStream;
00118 typedef ostrstream OFOStringStream;
00119 typedef istrstream OFIStringStream;
00120 
00121 #define OFStringStream_ends ends
00122 #define OFSTRINGSTREAM_GETOFSTRING(oss, string) \
00123     char * string##__ = (oss).str(); \
00124     OFString string(string##__); \
00125     delete[] string##__;
00126 // The following two macros define a block structure. Please note that variables
00127 // declared between xxx_GETSTR and xxx_FREESTR are only valid within this scope.
00128 #define OFSTRINGSTREAM_GETSTR(oss, chptr) \
00129 { \
00130     const char *chptr = (oss).str();
00131 #define OFSTRINGSTREAM_FREESTR(chptr) \
00132     delete[] (char *)chptr; \
00133 }
00134 
00135 #endif /* USE_STRINGSTREAM */
00136 
00137 #endif /* USE_STD_CXX_INCLUDES */
00138 
00139 
00140 /*
00141  * CVS/RCS Log:
00142  * $Log: ofstream.h,v $
00143  * Revision 1.11  2010-10-14 13:15:50  joergr
00144  * Updated copyright header. Added reference to COPYRIGHT file.
00145  *
00146  * Revision 1.10  2007/02/19 15:16:16  meichel
00147  * Namespace std is not imported into the default namespace anymore,
00148  *   unless DCMTK is compiled with macro USING_STD_NAMESPACE defined.
00149  *
00150  * Revision 1.9  2006/08/15 15:52:23  meichel
00151  * Updated all code in module dcmdata to correctly compile when
00152  *   all standard C++ classes remain in namespace std.
00153  *
00154  * Revision 1.8  2006/08/14 16:42:02  meichel
00155  * Defined two new macros: STD_NAMESPACE is defined to std:: if the standard
00156  *   namespace exists and empty otherwise. OFendl is defined as std::endl if
00157  *   the standard namespace exists and as endl otherwise.
00158  *
00159  * Revision 1.7  2005/12/08 16:06:06  meichel
00160  * Changed include path schema for all DCMTK header files
00161  *
00162  * Revision 1.6  2004/05/07 10:46:32  meichel
00163  * Removed unneeded semicolon, reported by gcc 3.4
00164  *
00165  * Revision 1.5  2004/01/16 10:30:12  joergr
00166  * Removed acknowledgements with e-mail addresses from CVS log.
00167  *
00168  * Revision 1.4  2003/12/05 10:37:41  joergr
00169  * Removed leading underscore characters from preprocessor symbols (reserved
00170  * symbols). Updated copyright date where appropriate.
00171  *
00172  * Revision 1.3  2002/12/11 15:54:48  meichel
00173  * Added empty namespace std declaration, needed on MSVC.
00174  *
00175  * Revision 1.2  2002/05/02 14:05:50  joergr
00176  * Added support for standard and non-standard string streams (which one is
00177  * supported is detected automatically via the configure mechanism).
00178  *
00179  * Revision 1.1  2002/04/16 13:36:03  joergr
00180  * Added configurable support for C++ ANSI standard includes (e.g. streams).
00181  *
00182  */


Generated on 6 Jan 2011 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.5.1