# gdcmWriter.h

Go to the documentation of this file.

    00001 /*=========================================================================
    00002
    00003   Program: GDCM (Grassroots DICOM). A DICOM library
    00004   Module:  $URL$
    00005
    00006   Copyright (c) 2006-2010 Mathieu Malaterre
    00007   All rights reserved.
    00008   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
    00009
    00010      This software is distributed WITHOUT ANY WARRANTY; without even
    00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00012      PURPOSE.  See the above copyright notice for more information.
    00013
    00014 =========================================================================*/
    00015
    00016 #ifndef GDCMWRITER_H
    00017 #define GDCMWRITER_H
    00018
    00019 #include "gdcmFile.h"
    00020
    00021 namespace gdcm
    00022 {
    00023
    00024 class FileMetaInformation;
    00048 class GDCM_EXPORT Writer
    00049 {
    00050 public:
    00051   Writer():F(new File),CheckFileMetaInformation(true) {
    00052     Stream = NULL;
    00053     Ofstream = NULL;
    00054   }
    00055   virtual ~Writer();
    00056
    00058   virtual bool Write(); // Execute()
    00059
    00061   void SetFileName(const char *filename) {
    00062     //std::cerr << "Stream: " << filename << std::endl;
    00063     //std::cerr << "Ofstream: " << Ofstream << std::endl;
    00064     if (Ofstream && Ofstream->is_open())
    00065       {
    00066       Ofstream->close();
    00067       delete Ofstream;
    00068       }
    00069     Ofstream = new std::ofstream();
    00070     Ofstream->open(filename, std::ios::out | std::ios::binary );
    00071     assert( Ofstream->is_open() );
    00072     assert( !Ofstream->fail() );
    00073     //std::cerr << Stream.is_open() << std::endl;
    00074     Stream = Ofstream;
    00075   }
    00077   void SetStream(std::ostream &output_stream) {
    00078     Stream = &output_stream;
    00079   }
    00080
    00082   void SetFile(const File& f) { F = f; }
    00083   File &GetFile() { return *F; }
    00084
    00086   void SetCheckFileMetaInformation(bool b) { CheckFileMetaInformation = b; }
    00087   void CheckFileMetaInformationOff() { CheckFileMetaInformation = false; }
    00088   void CheckFileMetaInformationOn() { CheckFileMetaInformation = true; }
    00089
    00090 protected:
    00091   std::ostream *Stream;
    00092   std::ofstream *Ofstream;
    00093
    00094 private:
    00095   SmartPointer<File> F;
    00096   bool CheckFileMetaInformation;
    00097 };
    00098
    00099 } // end namespace gdcm
    00100
    00101 #endif //GDCMWRITER_H