Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

dcobject.h

00001 /*
00002  *
00003  *  Copyright (C) 1994-2003, OFFIS
00004  *
00005  *  This software and supporting documentation were developed by
00006  *
00007  *    Kuratorium OFFIS e.V.
00008  *    Healthcare Information and Communication Systems
00009  *    Escherweg 2
00010  *    D-26121 Oldenburg, Germany
00011  *
00012  *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY
00013  *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR
00014  *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR
00015  *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
00016  *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
00017  *
00018  *  Module:  dcmdata
00019  *
00020  *  Author:  Gerd Ehlers
00021  *
00022  *  Purpose:
00023  *  This file contains the interface to routines which provide
00024  *  DICOM object encoding/decoding, search and lookup facilities.
00025  *
00026  *  Last Update:      $Author: wilkens $
00027  *  Update Date:      $Date: 2004/04/27 09:21:01 $
00028  *  Source File:      $Source: /share/dicom/cvs-depot/dcmtk/dcmdata/include/dcobject.h,v $
00029  *  CVS/RCS Revision: $Revision: 1.36 $
00030  *  Status:           $State: Exp $
00031  *
00032  *  CVS/RCS Log at end of file
00033  *
00034  */
00035 
00036 
00037 #ifndef DCOBJECT_H
00038 #define DCOBJECT_H
00039 
00040 #include "osconfig.h"    /* make sure OS specific configuration is included first */
00041 
00042 #include "ofconsol.h"
00043 #include "ofglobal.h"
00044 #include "dcerror.h"
00045 #include "dctypes.h"
00046 #include "dcxfer.h"
00047 #include "dctag.h"
00048 #include "dclist.h"
00049 #include "dcstack.h"
00050 
00051 
00052 // forward declarations
00053 class DcmOutputStream;
00054 class DcmInputStream;
00055 
00056 
00057 // Undefined Length Identifier now defined in dctypes.h
00058 
00059 // Maxinum number of read bytes for a Value Element
00060 const Uint32 DCM_MaxReadLength = 4096;
00061 
00062 // Maximum length of tag and length in a DICOM element
00063 const Uint32 DCM_TagInfoLength = 12;
00064 
00065 // Optimum line length if not all data printed
00066 const Uint32 DCM_OptPrintLineLength = 70;
00067 
00068 // Optimum value length if not all data printed
00069 const Uint32 DCM_OptPrintValueLength = 40;
00070 
00071 
00072 /*
00073 ** Should automatic correction be applied to input data (e.g. stripping
00074 ** of padding blanks, removal of blanks in UIDs, etc).
00075 */
00076 extern OFGlobal<OFBool> dcmEnableAutomaticInputDataCorrection; /* default OFTrue */
00077 
00078 
00079 /*
00080 ** Handling of illegal odd-length attributes: If flag is true, odd lengths
00081 ** are respected (i.e. an odd number of bytes is read from the input stream.)
00082 ** After successful reading, padding to even number of bytes is enforced
00083 ** by adding a zero pad byte if dcmEnableAutomaticInputDataCorrection is true.
00084 ** Otherwise the odd number of bytes remains as read.
00085 **
00086 ** If flag is false, old (pre DCMTK 3.5.2) behaviour applies: The length field
00087 ** implicitly incremented and an even number of bytes is read from the stream.
00088 */
00089 extern OFGlobal<OFBool> dcmAcceptOddAttributeLength; /* default OFTrue */
00090 
00091 
00094 class DcmObject
00095 {
00096 
00097   public:
00098 
00104     DcmObject(const DcmTag &tag,
00105               const Uint32 len = 0);
00106 
00110     DcmObject(const DcmObject &obj);
00111 
00114     virtual ~DcmObject();
00115 
00120     DcmObject &operator=(const DcmObject &obj);
00121 
00125     virtual DcmEVR ident() const = 0;
00126 
00127     // current value representation. If object was read from a stream
00128     // getVR returns the read value representation. It is possible that
00129     // this vr is not the same as mentioned in the data dictionary
00130     // (e.g. private tags, encapsulated data ...)
00131     inline DcmEVR getVR() const { return Tag.getEVR(); }
00132 
00133     inline OFBool isaString() const { return Tag.getVR().isaString(); }
00134 
00135     virtual OFBool isLeaf() const = 0;
00136 
00144     virtual void print(ostream &out,
00145                        const size_t flags = 0,
00146                        const int level = 0,
00147                        const char *pixelFileName = NULL,
00148                        size_t *pixelCounter = NULL) = 0;
00149 
00150     inline OFCondition error() const { return errorFlag; }
00151 
00152     inline E_TransferState transferState() const { return fTransferState; }
00153     virtual void transferInit(void);
00154     virtual void transferEnd(void);
00155 
00156     inline Uint16 getGTag() const { return Tag.getGTag(); }
00157     inline Uint16 getETag() const { return Tag.getETag(); }
00158     inline const DcmTag &getTag() const { return Tag; }
00159     inline void setGTag(Uint16 gtag) { Tag.setGroup(gtag); }
00160 
00161     virtual OFCondition setVR(DcmEVR /*vr*/) { return EC_IllegalCall; }
00162     virtual unsigned long getVM() = 0;
00163 
00164     // calculate length of Dicom element
00165     virtual Uint32 calcElementLength(const E_TransferSyntax xfer,
00166                                      const E_EncodingType enctype) = 0;
00167 
00168     // returns value length
00169     virtual Uint32 getLength(const E_TransferSyntax xfer = EXS_LittleEndianImplicit,
00170                              const E_EncodingType enctype = EET_UndefinedLength) = 0;
00171 
00172     virtual OFBool canWriteXfer(const E_TransferSyntax newXfer,
00173                                 const E_TransferSyntax oldXfer) = 0;
00174 
00175     virtual OFCondition read(DcmInputStream &inStream,
00176                              const E_TransferSyntax ixfer,
00177                              const E_GrpLenEncoding glenc = EGL_noChange,
00178                              const Uint32 maxReadLength = DCM_MaxReadLength) = 0;
00179 
00186     virtual OFCondition write(DcmOutputStream &outStream,
00187                               const E_TransferSyntax oxfer,
00188                               const E_EncodingType enctype = EET_UndefinedLength) = 0;
00189 
00195     virtual OFCondition writeXML(ostream &out,
00196                                  const size_t flags = 0);
00197 
00204     virtual OFCondition writeSignatureFormat(DcmOutputStream &outStream,
00205                                              const E_TransferSyntax oxfer,
00206                                              const E_EncodingType enctype = EET_UndefinedLength) = 0;
00207 
00211     virtual OFBool isSignable() const;
00212 
00216     virtual OFBool containsUnknownVR() const;
00217 
00218     virtual OFCondition clear() = 0;
00219     virtual OFCondition verify(const OFBool autocorrect = OFFalse) = 0;
00220 
00221     virtual DcmObject *nextInContainer(const DcmObject *obj);
00222 
00223     virtual OFCondition nextObject(DcmStack &stack,
00224                                    const OFBool intoSub);
00225 
00226     virtual OFCondition search(const DcmTagKey &xtag,             // in
00227                                DcmStack &resultStack,             // inout
00228                                E_SearchMode mode = ESM_fromHere,  // in
00229                                OFBool searchIntoSub = OFTrue);    // in
00230 
00231     virtual OFCondition searchErrors(DcmStack &resultStack);      // inout
00232 
00233     virtual OFCondition loadAllDataIntoMemory() = 0;
00234 
00235 
00236  protected:
00237 
00244     void printNestingLevel(ostream &out,
00245                            const size_t flags,
00246                            const int level);
00247 
00256     void printInfoLineStart(ostream &out,
00257                             const size_t flags,
00258                             const int level,
00259                             DcmTag *tag = NULL);
00260 
00270     void printInfoLineEnd(ostream &out,
00271                           const size_t flags,
00272                           const unsigned long printedLength = 0xffffffff /*no padding*/,
00273                           DcmTag *tag = NULL);
00274 
00284     virtual void printInfoLine(ostream &out,
00285                                const size_t flags,
00286                                const int level = 0,
00287                                const char *info = NULL,
00288                                DcmTag *tag = NULL);
00289 
00290     static OFCondition writeTag(DcmOutputStream &outStream,
00291                                 const DcmTag &tag,
00292                                 const E_TransferSyntax oxfer); // in
00293 
00294     virtual OFCondition writeTagAndLength(DcmOutputStream &outStream,
00295                                           const E_TransferSyntax oxfer, // in
00296                                           Uint32 &writtenBytes) const;  // out
00297 
00304     virtual Uint32 getTagAndLengthSize(const E_TransferSyntax oxfer) const;
00305 
00306     /* member variables */
00307     DcmTag Tag;
00308     Uint32 Length;
00309     E_TransferState fTransferState;
00310     OFCondition errorFlag;  // defined after fTransferState to workaround
00311                             // memory layout problem with Borland C++
00312     Uint32 fTransferredBytes;
00313  }; // class DcmObject
00314 
00315 
00316 #endif // DCOBJECT_H
00317 
00318 
00319 /*
00320  * CVS/RCS Log:
00321  * $Log: dcobject.h,v $
00322  * Revision 1.36  2004/04/27 09:21:01  wilkens
00323  * Fixed a bug in dcelem.cc which occurs when one is serializing a dataset
00324  * (that contains an attribute whose length value is coded with 2 bytes) into
00325  * a given buffer. Although the number of available bytes in the buffer was
00326  * sufficient, the dataset->write(...) method would always return
00327  * EC_StreamNotifyClient to indicate that there are not sufficient bytes
00328  * available in the buffer. This code modification fixes the problem.
00329  *
00330  * Revision 1.35  2003/06/12 13:33:21  joergr
00331  * Fixed inconsistent API documentation reported by Doxygen.
00332  *
00333  * Revision 1.34  2002/12/06 12:49:11  joergr
00334  * Enhanced "print()" function by re-working the implementation and replacing
00335  * the boolean "showFullData" parameter by a more general integer flag.
00336  * Added doc++ documentation.
00337  * Made source code formatting more consistent with other modules/files.
00338  *
00339  * Revision 1.33  2002/08/27 16:55:35  meichel
00340  * Initial release of new DICOM I/O stream classes that add support for stream
00341  *   compression (deflated little endian explicit VR transfer syntax)
00342  *
00343  * Revision 1.32  2002/08/20 12:18:35  meichel
00344  * Changed parameter list of loadFile and saveFile methods in class
00345  *   DcmFileFormat. Removed loadFile and saveFile from class DcmObject.
00346  *
00347  * Revision 1.31  2002/07/08 14:45:20  meichel
00348  * Improved dcmdata behaviour when reading odd tag length. Depending on the
00349  *   global boolean flag dcmAcceptOddAttributeLength, the parser now either accepts
00350  *   odd length attributes or implements the old behaviour, i.e. assumes a real
00351  *   length larger by one.
00352  *
00353  * Revision 1.30  2002/04/25 09:38:47  joergr
00354  * Added support for XML output of DICOM objects.
00355  *
00356  * Revision 1.29  2002/04/11 12:23:46  joergr
00357  * Added new methods for loading and saving DICOM files.
00358  *
00359  * Revision 1.28  2001/11/16 15:54:39  meichel
00360  * Adapted digital signature code to final text of supplement 41.
00361  *
00362  * Revision 1.27  2001/09/25 17:19:27  meichel
00363  * Adapted dcmdata to class OFCondition
00364  *
00365  * Revision 1.26  2001/06/01 15:48:41  meichel
00366  * Updated copyright header
00367  *
00368  * Revision 1.25  2000/11/07 16:56:07  meichel
00369  * Initial release of dcmsign module for DICOM Digital Signatures
00370  *
00371  * Revision 1.24  2000/04/14 16:02:39  meichel
00372  * Global flag dcmEnableAutomaticInputDataCorrection now derived from OFGlobal
00373  *   and, thus, safe for use in multi-thread applications.
00374  *
00375  * Revision 1.23  2000/03/08 16:26:16  meichel
00376  * Updated copyright header.
00377  *
00378  * Revision 1.22  2000/03/03 14:05:24  meichel
00379  * Implemented library support for redirecting error messages into memory
00380  *   instead of printing them to stdout/stderr for GUI applications.
00381  *
00382  * Revision 1.21  2000/02/10 10:50:52  joergr
00383  * Added new feature to dcmdump (enhanced print method of dcmdata): write
00384  * pixel data/item value fields to raw files.
00385  *
00386  * Revision 1.20  2000/02/01 10:12:02  meichel
00387  * Avoiding to include <stdlib.h> as extern "C" on Borland C++ Builder 4,
00388  *   workaround for bug in compiler header files.
00389  *
00390  * Revision 1.19  1999/03/31 09:24:42  meichel
00391  * Updated copyright header in module dcmdata
00392  *
00393  *
00394  */


Generated on 8 Dec 2004 for OFFIS DCMTK Version 3.5.3 by Doxygen 1.3.9.1