# gdcmFileMetaInformation.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 #ifndef GDCMFILEMETAINFORMATION_H
    00016 #define GDCMFILEMETAINFORMATION_H
    00017
    00018 #include "gdcmPreamble.h"
    00019 #include "gdcmDataSet.h"
    00020 #include "gdcmDataElement.h"
    00021 #include "gdcmMediaStorage.h"
    00022 #include "gdcmTransferSyntax.h"
    00023 #include "gdcmExplicitDataElement.h"
    00024
    00025 namespace gdcm
    00026 {
    00041 class GDCM_EXPORT FileMetaInformation : public DataSet
    00042 {
    00043 public:
    00044   // FIXME: TransferSyntax::TS_END -> TransferSyntax::ImplicitDataElement
    00045   FileMetaInformation():DataSetTS(TransferSyntax::TS_END),MetaInformationTS(TransferSyntax::Unknown),DataSetMS(MediaStorage::MS_END) {}
    00046  ~FileMetaInformation() { };
    00047
    00048   friend std::ostream &operator<<(std::ostream &_os, const FileMetaInformation &_val);
    00049
    00050   bool IsValid() const { return true; }
    00051
    00052   TransferSyntax::NegociatedType GetMetaInformationTS() const { return MetaInformationTS; }
    00053   void SetDataSetTransferSyntax(const TransferSyntax &ts);
    00054   const TransferSyntax &GetDataSetTransferSyntax() const { return DataSetTS; }
    00055   MediaStorage GetMediaStorage() const;
    00056
    00057   // FIXME: no virtual function means: duplicate code...
    00058   void Insert(const DataElement& de) {
    00059     if( de.GetTag().GetGroup() == 0x0002 )
    00060       {
    00061       InsertDataElement( de );
    00062       }
    00063     else
    00064       {
    00065       gdcmErrorMacro( "Cannot add element with group != 0x0002 in the file meta header: " << de );
    00066       }
    00067   }
    00068   void Replace(const DataElement& de) {
    00069     Remove(de.GetTag());
    00070     Insert(de);
    00071   }
    00072
    00074   std::istream &Read(std::istream &is);
    00075   std::istream &ReadCompat(std::istream &is);
    00076
    00078   std::ostream &Write(std::ostream &os) const;
    00079
    00081   void FillFromDataSet(DataSet const &ds);
    00082
    00084   const Preamble &GetPreamble() const { return P; }
    00085   Preamble &GetPreamble() { return P; }
    00086   void SetPreamble(const Preamble &p) { P = p; }
    00087
    00089   static void SetImplementationClassUID(const char * imp);
    00090   static void AppendImplementationClassUID(const char * imp);
    00091   static const char *GetImplementationClassUID();
    00092   static void SetImplementationVersionName(const char * version);
    00093   static const char *GetImplementationVersionName();
    00094   static void SetSourceApplicationEntityTitle(const char * title);
    00095   static const char *GetSourceApplicationEntityTitle();
    00096
    00097   FileMetaInformation(FileMetaInformation const &fmi):DataSet(fmi)
    00098     {
    00099     DataSetTS = fmi.DataSetTS;
    00100     MetaInformationTS = fmi.MetaInformationTS;
    00101     DataSetMS = fmi.DataSetMS;
    00102     }
    00103
    00104     VL GetFullLength() const {
    00105       return P.GetLength() + DataSet::GetLength<ExplicitDataElement>();
    00106     }
    00107
    00108 protected:
    00109   void ComputeDataSetTransferSyntax(); // FIXME
    00110
    00111   template <typename TSwap>
    00112   std::istream &ReadCompatInternal(std::istream &is);
    00113
    00114   void Default();
    00115   void ComputeDataSetMediaStorageSOPClass();
    00116
    00117   TransferSyntax DataSetTS;
    00118   TransferSyntax::NegociatedType MetaInformationTS;
    00119   MediaStorage::MSType DataSetMS;
    00120
    00121 protected:
    00122   static const char * GetFileMetaInformationVersion();
    00123   static const char * GetGDCMImplementationClassUID();
    00124   static const char * GetGDCMImplementationVersionName();
    00125   static const char * GetGDCMSourceApplicationEntityTitle();
    00126
    00127 private:
    00128   Preamble P;
    00129
    00130 //static stuff:
    00131   static const char GDCM_FILE_META_INFORMATION_VERSION[];
    00132   static const char GDCM_IMPLEMENTATION_CLASS_UID[];
    00133   static const char GDCM_IMPLEMENTATION_VERSION_NAME[];
    00134   static const char GDCM_SOURCE_APPLICATION_ENTITY_TITLE[];
    00135   static std::string ImplementationClassUID;
    00136   static std::string ImplementationVersionName;
    00137   static std::string SourceApplicationEntityTitle;
    00138 };
    00139 //-----------------------------------------------------------------------------
    00140 inline std::ostream& operator<<(std::ostream &os, const FileMetaInformation &val)
    00141 {
    00142   os << val.GetPreamble() << std::endl;
    00143   val.Print( os );
    00144   return os;
    00145 }
    00146
    00147 } // end namespace gdcm
    00148
    00149 #endif //GDCMFILEMETAINFORMATION_H