Commit c1d1a2a6 authored by Brad King's avatar Brad King
Browse files

ENH: Re-factored the inclusion of C++ streams because some source files need...

ENH: Re-factored the inclusion of C++ streams because some source files need only the stream forward declarations.  Should improve compile time.
parent ce572ae7
......@@ -57,6 +57,7 @@ vtkHexahedron.cxx
vtkHomogeneousTransform.cxx
vtkIdList.cxx
vtkIdListCollection.cxx
vtkIdType.cxx
vtkIdTypeArray.cxx
vtkIdentityTransform.cxx
vtkImageData.cxx
......@@ -85,6 +86,8 @@ vtkMultiPartExtentTranslator.cxx
vtkMultiThreader.cxx
vtkMutexLock.cxx
vtkNonLinearCell.cxx
vtkOStrStreamWrapper.cxx
vtkOStreamWrapper.cxx
vtkObject.cxx
vtkObjectBase.cxx
vtkObjectFactory.cxx
......@@ -208,9 +211,12 @@ SET_SOURCE_FILES_PROPERTIES(
vtkContainer
vtkDebugLeaksManager
vtkErrorCode
vtkIdType.cxx
vtkImageIterator
vtkImageProgressIterator
vtkLargeInteger
vtkOStrStreamWrapper.cxx
vtkOStreamWrapper.cxx
vtkOldStyleCallbackCommand
vtkString
WRAP_EXCLUDE
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkIOStream.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkIOStream - Include C++ iostreams as used by VTK.
// .SECTION Description
// VTK supports both ANSI and old-style streams. This header includes
// the proper streams according to VTK_USE_ANSI_STDLIB.
#ifndef __vtkIOStream_h
#define __vtkIOStream_h
#include "vtkConfigure.h"
#ifdef VTK_USE_ANSI_STDLIB
# include <iostream> // Include real ansi istream and ostream.
# include <strstream> // Include real ansi strstreams.
# include <fstream> // Include real ansi ifstream and ofstream.
# include <iomanip> // Include real ansi io manipulators.
// Need these in global namespace so the same code will work with ansi
// and old-style streams.
using std::dec;
using std::hex;
using std::setw;
using std::cerr;
using std::cout;
using std::cin;
using std::ios;
using std::endl;
using std::ends;
using std::ostream;
using std::istream;
using std::ostrstream;
using std::istrstream;
using std::strstream;
using std::ofstream;
using std::ifstream;
using std::fstream;
#else
// Include old-style streams.
# ifdef _WIN32_WCE
# include "vtkWinCE.h" // Include mini-streams for Windows CE.
# else
# include <iostream.h> // Include old-style istream and ostream.
# if defined(_MSC_VER)
# include <strstrea.h> // Include old-style strstream from MSVC.
# else
# include <strstream.h> // Include old-style strstream.
# endif
# include <fstream.h> // Include old-style ifstream and ofstream.
# endif
#endif
#endif // __vtkIOStream_h
/*=========================================================================
Program: Visualization Toolkit
Module: vtkIOStreamFwd.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkIOStreamFwd - Forward-declare C++ iostreams as used by VTK.
// .SECTION Description
// VTK supports both ANSI and old-style streams. This header
// forward-declares the proper streams according to
// VTK_USE_ANSI_STDLIB.
#ifndef __vtkIOStreamFwd_h
#define __vtkIOStreamFwd_h
#include "vtkConfigure.h"
#ifdef VTK_USE_ANSI_STDLIB
// Forward-declare ansi streams.
# include <iosfwd>
using std::ios;
using std::streambuf;
using std::istream;
using std::ostream;
using std::iostream;
using std::filebuf;
using std::ifstream;
using std::ofstream;
using std::fstream;
#else
// Forward-declare non-ansi streams.
class ios;
class streambuf;
class istream;
class ostream;
class iostream;
class filebuf;
class ifstream;
class ofstream;
class fstream;
#endif
#endif // __vtkIOStreamFwd_h
/*=========================================================================
Program: Visualization Toolkit
Module: vtkIdType.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSystemIncludes.h" // Cannot include vtkIdType.h directly.
#include "vtkIOStream.h"
//----------------------------------------------------------------------------
ostream& operator << (ostream& os, vtkIdTypeHolder idh)
{
#if defined(VTK_USE_64BIT_IDS) && defined(_WIN32)
// _i64toa can use up to 33 bytes (32 + null terminator).
char buf[33];
// Convert to string representation in base 10.
return (os << _i64toa(idh.Value, buf, 10));
#else
return (os << idh.Value);
#endif
}
//----------------------------------------------------------------------------
istream& operator >> (istream& is, vtkIdTypeHolder idh)
{
#if defined(VTK_USE_64BIT_IDS) && defined(_WIN32)
// Up to 33 bytes may be needed (32 + null terminator).
char buf[33];
is.width(33);
// Read the string representation from the input.
if(is >> buf)
{
// Convert from string representation to integer.
idh.Value = _atoi64(buf);
}
return is;
#else
return (is >> idh.Value);
#endif
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkIdType.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkIdType - Integer type used for point and cell IDs.
// .SECTION Description
// vtkIdType is the integer type used for point and cell
// identification. This type may be either 32-bit or 64-bit,
// depending on whether VTK_USE_64BIT_IDS is defined.
#ifndef __vtkIdType_h
#define __vtkIdType_h
#ifndef __VTK_SYSTEM_INCLUDES__INSIDE
Do_not_include_vtkIdType_directly__vtkSystemIncludes_includes_it;
#endif
// Choose an implementation for vtkIdType.
#define VTK_HAS_ID_TYPE
#ifdef VTK_USE_64BIT_IDS
# define VTK_ID_TYPE_IS_NOT_BASIC_TYPE
# ifdef _WIN32
typedef __int64 vtkIdType;
# define VTK_NEED_ID_TYPE_STREAM_OPERATORS
# else // _WIN32
typedef long long vtkIdType;
# define VTK_NEED_ID_TYPE_STREAM_OPERATORS
# endif // _WIN32
#else // VTK_USE_64BIT_IDS
typedef int vtkIdType;
#endif // VTK_USE_64BIT_IDS
// Define a wrapper class so that we can define streaming operators
// for vtkIdType without conflicting with other libraries'
// implementations.
class VTK_COMMON_EXPORT vtkIdTypeHolder
{
public:
vtkIdTypeHolder(vtkIdType& v): Value(v) {}
vtkIdType& Value;
private:
vtkIdTypeHolder& operator=(const vtkIdTypeHolder&); // Not Implemented.
};
VTK_COMMON_EXPORT ostream& operator << (ostream& os, vtkIdTypeHolder idh);
VTK_COMMON_EXPORT istream& operator >> (istream& is, vtkIdTypeHolder idh);
#endif
......@@ -50,7 +50,7 @@ vtkIndent vtkIndent::GetNextIndent()
}
// Print out the indentation. Basically output a bunch of spaces.
ostream& operator<<(ostream& os, vtkIndent& ind)
ostream& operator<<(ostream& os, const vtkIndent& ind)
{
os << blanks + (VTK_NUMBER_OF_BLANKS-ind.Indent) ;
return os;
......
......@@ -26,6 +26,9 @@
#include "vtkSystemIncludes.h"
class vtkIndent;
VTK_COMMON_EXPORT ostream& operator<<(ostream& os, const vtkIndent& o);
class VTK_COMMON_EXPORT vtkIndent
{
public:
......@@ -43,7 +46,7 @@ public:
//BTX
// Description:
// Print out the indentation. Basically output a bunch of spaces.
friend VTK_COMMON_EXPORT ostream& operator<<(ostream& os, vtkIndent& o);
friend VTK_COMMON_EXPORT ostream& operator<<(ostream& os, const vtkIndent& o);
//ETX
protected:
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOStrStreamWrapper.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSystemIncludes.h" // Cannot include vtkOStrStreamWrapper.h directly.
// Need strcpy.
#include <string.h>
// Use ANSI ostrstream or ostringstream.
#ifdef VTK_USE_ANSI_STDLIB
# ifndef VTK_NO_ANSI_STRING_STREAM
# include <sstream>
using std::ostringstream;
# else
# include <strstream>
using std::ostrstream;
using std::ends;
# endif
// Use old-style strstream.
#else
# ifdef _WIN32_WCE
# include "vtkWinCE.h"
# else
# if defined(_MSC_VER)
# include <strstrea.h>
# else
# include <strstream.h>
# endif
# endif // Win CE
#endif
//----------------------------------------------------------------------------
#if defined(VTK_USE_ANSI_STDLIB) && !defined(VTK_NO_ANSI_STRING_STREAM)
vtkOStrStreamWrapper::vtkOStrStreamWrapper():
vtkOStreamWrapper(*(new ostringstream))
{
this->Result = 0;
this->Frozen = 0;
}
#else
vtkOStrStreamWrapper::vtkOStrStreamWrapper():
vtkOStreamWrapper(*(new ostrstream))
{
this->Result = 0;
this->Frozen = 0;
}
#endif
//----------------------------------------------------------------------------
vtkOStrStreamWrapper::~vtkOStrStreamWrapper()
{
if(this->Result && !this->Frozen)
{
delete [] this->Result;
}
delete &this->ostr;
}
//----------------------------------------------------------------------------
#if defined(VTK_USE_ANSI_STDLIB) && !defined(VTK_NO_ANSI_STRING_STREAM)
char* vtkOStrStreamWrapper::str()
{
if(!this->Result)
{
std::string s = static_cast<ostringstream*>(&this->ostr)->str();
this->Result = new char[s.length()+1];
strcpy(this->Result, s.c_str());
this->freeze();
}
return this->Result;
}
#else
char* vtkOStrStreamWrapper::str()
{
if(!this->Result)
{
this->ostr << ends;
this->Result = static_cast<ostrstream*>(&this->ostr)->str();
this->freeze();
}
return this->Result;
}
#endif
//----------------------------------------------------------------------------
vtkOStrStreamWrapper* vtkOStrStreamWrapper::rdbuf()
{
return this;
}
//----------------------------------------------------------------------------
void vtkOStrStreamWrapper::freeze()
{
this->freeze(1);
}
//----------------------------------------------------------------------------
void vtkOStrStreamWrapper::freeze(int f)
{
this->Frozen = f;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOStrStreamWrapper.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkOStrStreamWrapper - Wrapper for ostrstream. Internal VTK use only.
// .SECTION Description
// Provides a wrapper around the C++ ostrstream class so that VTK
// source files need not include the full C++ streams library. This
// is intended to prevent cluttering of the translation unit and speed
// up compilation. Experimentation has revealed between 10% and 60%
// less time for compilation depending on the platform. This wrapper
// is used by the macros in vtkSetGet.h.
#ifndef __vtkOStrStreamWrapper_h
#define __vtkOStrStreamWrapper_h
#ifndef __VTK_SYSTEM_INCLUDES__INSIDE
Do_not_include_vtkOStrStreamWrapper_directly__vtkSystemIncludes_includes_it;
#endif
class VTK_COMMON_EXPORT vtkOStrStreamWrapper: public vtkOStreamWrapper
{
public:
// Description:
// Constructor.
vtkOStrStreamWrapper();
// Description:
// Destructor frees all used memory.
~vtkOStrStreamWrapper();
// Description:
// Get the string that has been written. This call transfers
// ownership of the returned memory to the caller. Call
// rdbuf()->freeze(0) to return ownership to the vtkOStrStreamWrapper.
char* str();
// Description:
// Returns a pointer to this class. This is a hack so that the old
// ostrstream's s.rdbuf()->freeze(0) can work.
vtkOStrStreamWrapper* rdbuf();
// Description:
// Set whether the memory is frozen. The vtkOStrStreamWrapper will free
// the memory returned by str() only if it is not frozen.
void freeze();
void freeze(int);
protected:
// The pointer returned by str().
char* Result;
// Whether the caller of str() owns the memory.
int Frozen;
private:
vtkOStrStreamWrapper(const vtkOStrStreamWrapper& r); // Not Implemented.
vtkOStrStreamWrapper& operator=(const vtkOStrStreamWrapper&); // Not Implemented.
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOStreamWrapper.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSystemIncludes.h" // Cannot include vtkOStreamWrapper.h directly.
#include "vtkIndent.h"
#include "vtkLargeInteger.h"
#include "vtkObjectBase.h"
#include "vtkIOStream.h"
#define VTKOSTREAM_OPERATOR(type) \
vtkOStreamWrapper& vtkOStreamWrapper::operator << (type a) \
{ this->ostr << a; return *this; }
#define VTKOSTREAM_OPERATOR_FUNC(arg) \
vtkOStreamWrapper& vtkOStreamWrapper::operator << (arg) \
{ this->ostr << a; return *this; }
//----------------------------------------------------------------------------
vtkOStreamWrapper::vtkOStreamWrapper(ostream& os): ostr(os)
{
}
//----------------------------------------------------------------------------
vtkOStreamWrapper::vtkOStreamWrapper(vtkOStreamWrapper& r): ostr(r.ostr)
{
}
//----------------------------------------------------------------------------
VTKOSTREAM_OPERATOR(const vtkIndent&);
VTKOSTREAM_OPERATOR(vtkObjectBase&);
VTKOSTREAM_OPERATOR(const vtkLargeInteger&);
VTKOSTREAM_OPERATOR(ostream&);
VTKOSTREAM_OPERATOR(const char*);
VTKOSTREAM_OPERATOR(void*);
VTKOSTREAM_OPERATOR(char);
VTKOSTREAM_OPERATOR(short);
VTKOSTREAM_OPERATOR(int);
VTKOSTREAM_OPERATOR(long);
VTKOSTREAM_OPERATOR(unsigned char);
VTKOSTREAM_OPERATOR(unsigned short);
VTKOSTREAM_OPERATOR(unsigned int);
VTKOSTREAM_OPERATOR(unsigned long);
VTKOSTREAM_OPERATOR(float);
VTKOSTREAM_OPERATOR(double);
#ifdef VTK_NEED_ID_TYPE_STREAM_OPERATORS
vtkOStreamWrapper& vtkOStreamWrapper::operator << (vtkIdType a)
{
this->ostr << vtkIdTypeHolder(a);
return *this;
}
#endif
VTKOSTREAM_OPERATOR_FUNC(void (*a)(void*));
VTKOSTREAM_OPERATOR_FUNC(void* (*a)(void*));
VTKOSTREAM_OPERATOR_FUNC(int (*a)(void*));
VTKOSTREAM_OPERATOR_FUNC(int* (*a)(void*));
VTKOSTREAM_OPERATOR_FUNC(float* (*a)(void*));
VTKOSTREAM_OPERATOR_FUNC(const char* (*a)(void*));
VTKOSTREAM_OPERATOR_FUNC(void (*a)(void*, int*));
VTKOSTREAM_OPERATOR_FUNC(ostream& (&a)(ostream&));
VTKOSTREAM_OPERATOR_FUNC(ios& (&a)(ios&));
//----------------------------------------------------------------------------
vtkOStreamWrapper& vtkOStreamWrapper::write(const char* str,
unsigned long size)
{
this->ostr.write(str, size);
return *this;
}
//----------------------------------------------------------------------------
ostream& vtkOStreamWrapper::GetOStream()
{
return this->ostr;
}
//----------------------------------------------------------------------------
vtkOStreamWrapper::operator ostream&()
{
return this->ostr;
}
//----------------------------------------------------------------------------
vtkOStreamWrapper::operator int()
{
return this->ostr? 1:0;
}
//----------------------------------------------------------------------------
void vtkOStreamWrapper::flush()
{
this->ostr.flush();
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOStreamWrapper.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkOStreamWrapper - Wrapper for C++ ostream. Internal VTK use only.
// .SECTION Description
// Provides a wrapper around the C++ ostream so that VTK source files
// need not include the full C++ streams library. This is intended to
// prevent cluttering of the translation unit and speed up
// compilation. Experimentation has revealed between 10% and 60% less
// time for compilation depending on the platform. This wrapper is
// used by the macros in vtkSetGet.h.
#ifndef __vtkOStreamWrapper_h
#define __vtkOStreamWrapper_h