00001 /* 00002 * 00003 * Copyright (C) 1994-2005, 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, Andreas Barth 00021 * 00022 * Purpose: Interface of class DcmElement 00023 * 00024 * Last Update: $Author: meichel $ 00025 * Update Date: $Date: 2005/12/08 16:28:11 $ 00026 * Source File: $Source: /share/dicom/cvs-depot/dcmtk/dcmdata/include/dcmtk/dcmdata/dcelem.h,v $ 00027 * CVS/RCS Revision: $Revision: 1.29 $ 00028 * Status: $State: Exp $ 00029 * 00030 * CVS/RCS Log at end of file 00031 * 00032 */ 00033 00034 00035 #ifndef DCELEM_H 00036 #define DCELEM_H 00037 00038 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 00039 00040 #include "dcmtk/dcmdata/dcerror.h" 00041 #include "dcmtk/dcmdata/dctypes.h" 00042 #include "dcmtk/dcmdata/dcobject.h" 00043 #include "dcmtk/ofstd/ofstring.h" 00044 00045 // forward declarations 00046 class DcmInputStreamFactory; 00047 00048 00051 class DcmElement 00052 : public DcmObject 00053 { 00054 00055 public: 00056 00062 DcmElement(const DcmTag &tag, 00063 const Uint32 len = 0); 00064 00068 DcmElement(const DcmElement &old); 00069 00072 virtual ~DcmElement(); 00073 00078 DcmElement &operator=(const DcmElement &obj); 00079 00080 // returns length of element with tag, vr, ... 00081 virtual Uint32 calcElementLength(const E_TransferSyntax xfer, 00082 const E_EncodingType enctype); 00083 00084 // returns length of value 00085 virtual Uint32 getLength(const E_TransferSyntax /*xfer*/ = EXS_LittleEndianImplicit, 00086 const E_EncodingType /*enctype*/ = EET_UndefinedLength) 00087 { 00088 return Length; 00089 } 00090 00091 virtual OFBool isLeaf() const { return OFTrue; } 00092 inline OFBool valueLoaded() { return fValue != NULL || Length == 0; } 00093 00094 virtual void transferInit(); 00095 00096 virtual OFBool canWriteXfer(const E_TransferSyntax newXfer, 00097 const E_TransferSyntax oldXfer); 00098 00114 virtual OFCondition read(DcmInputStream &inStream, 00115 const E_TransferSyntax ixfer, 00116 const E_GrpLenEncoding glenc = EGL_noChange, 00117 const Uint32 maxReadLength = DCM_MaxReadLength); 00118 00140 virtual OFCondition write(DcmOutputStream &outStream, 00141 const E_TransferSyntax oxfer, 00142 const E_EncodingType enctype = EET_UndefinedLength); 00143 00149 virtual OFCondition writeXML(ostream &out, 00150 const size_t flags = 0); 00151 00158 virtual OFCondition writeSignatureFormat(DcmOutputStream &outStream, 00159 const E_TransferSyntax oxfer, 00160 const E_EncodingType enctype = EET_UndefinedLength); 00161 00162 virtual OFCondition clear(); 00163 00164 virtual OFCondition loadAllDataIntoMemory(); 00165 00166 // GET-Operations 00167 00168 // get copies of individual components 00169 virtual OFCondition getUint8(Uint8 &val, const unsigned long pos = 0); 00170 virtual OFCondition getSint16(Sint16 &val, const unsigned long pos = 0); 00171 virtual OFCondition getUint16(Uint16 &val, const unsigned long pos = 0); 00172 virtual OFCondition getSint32(Sint32 &val, const unsigned long pos = 0); 00173 virtual OFCondition getUint32(Uint32 &val, const unsigned long pos = 0); 00174 virtual OFCondition getFloat32(Float32 &val, const unsigned long pos = 0); 00175 virtual OFCondition getFloat64(Float64 &val, const unsigned long pos = 0); 00176 virtual OFCondition getTagVal(DcmTagKey &val, const unsigned long pos = 0); 00177 00178 // Gets a copy of one string value component. For multi-valued 00179 // string attributes (i.e those using \ separators), 00180 // this method extracts the pos component (counting from zero base). 00181 virtual OFCondition getOFString(OFString &str, 00182 const unsigned long pos, 00183 OFBool normalize = OFTrue); 00184 00194 virtual OFCondition getOFStringArray(OFString &value, 00195 OFBool normalize = OFTrue); 00196 00197 // The following get operations do not copy, 00198 // they return a reference of the element value 00199 // The element value remains under control of the element 00200 // and is only valid until the next put.., read, or write 00201 // operation. 00202 virtual OFCondition getString(char *&val); // for strings 00203 virtual OFCondition getUint8Array(Uint8 *&val); // for bytes 00204 virtual OFCondition getSint16Array(Sint16 *&val); 00205 virtual OFCondition getUint16Array(Uint16 *&val); 00206 virtual OFCondition getSint32Array(Sint32 *&val); 00207 virtual OFCondition getUint32Array(Uint32 *&val); 00208 virtual OFCondition getFloat32Array(Float32 *&val); 00209 virtual OFCondition getFloat64Array(Float64 *&val); 00210 00211 // detachValueField detaches the value field from the 00212 // DICOM element. After detaching the calling part of the 00213 // application has total control over the element value, especially 00214 // the value must be deleted from the heap after use. 00215 // The DICOM element remains a copy of the value if the copy 00216 // parameter is OFTrue else the value is erased in the DICOM 00217 // element. 00218 OFCondition detachValueField(OFBool copy = OFFalse); 00219 00220 00221 // PUT-Operations 00222 // Put operations copy the value. 00223 00224 // Sets the value of a complete (possibly multi-valued) string attribute. 00225 virtual OFCondition putOFStringArray(const OFString &stringValue); 00226 00227 // One Value 00228 virtual OFCondition putString(const char *val); 00229 00230 // One Value at a position pos 00231 virtual OFCondition putSint16(const Sint16 val, const unsigned long pos = 0); 00232 virtual OFCondition putUint16(const Uint16 val, const unsigned long pos = 0); 00233 virtual OFCondition putSint32(const Sint32 val, const unsigned long pos = 0); 00234 virtual OFCondition putUint32(const Uint32 val, const unsigned long pos = 0); 00235 virtual OFCondition putFloat32(const Float32 val, const unsigned long pos = 0); 00236 virtual OFCondition putFloat64(const Float64 val, const unsigned long pos = 0); 00237 virtual OFCondition putTagVal(const DcmTagKey &attrTag, const unsigned long pos = 0); 00238 00239 // num Values 00240 virtual OFCondition putUint8Array(const Uint8 *vals, const unsigned long num); 00241 virtual OFCondition putSint16Array(const Sint16 *vals, const unsigned long num); 00242 virtual OFCondition putUint16Array(const Uint16 *vals, const unsigned long num); 00243 virtual OFCondition putSint32Array(const Sint32 *vals, const unsigned long num); 00244 virtual OFCondition putUint32Array(const Uint32 *vals, const unsigned long num); 00245 virtual OFCondition putFloat32Array(const Float32 *vals, const unsigned long num); 00246 virtual OFCondition putFloat64Array(const Float64 *vals, const unsigned long num); 00247 00248 00249 protected: 00250 00251 E_ByteOrder fByteOrder; 00252 00259 void *getValue(const E_ByteOrder newByteOrder = gLocalByteOrder); 00260 00261 00262 OFCondition changeValue(const void *value, // new Value 00263 const Uint32 position, // position in value array 00264 const Uint32 num); // number of new value bytes 00265 00266 OFCondition putValue(const void *value, // new value 00267 const Uint32 length); // number of new value bytes 00268 00269 OFCondition createEmptyValue(const Uint32 length); // number of new value bytes 00270 00271 00272 00273 00283 OFCondition loadValue(DcmInputStream *inStream = NULL); 00284 00285 virtual void postLoadValue(); 00286 00291 virtual Uint8 *newValueField(); 00292 00293 void swapValueField(size_t valueWidth); 00294 00300 virtual void writeXMLStartTag(ostream &out, 00301 const size_t flags, 00302 const char *attrText = NULL); 00303 00308 virtual void writeXMLEndTag(ostream &out, 00309 const size_t flags); 00310 00311 00312 private: 00313 00315 DcmInputStreamFactory *fLoadValue; 00316 00318 Uint8 *fValue; 00319 }; 00320 00321 00322 #endif // DCELEM_H 00323 00324 00325 /* 00326 ** CVS/RCS Log: 00327 ** $Log: dcelem.h,v $ 00328 ** Revision 1.29 2005/12/08 16:28:11 meichel 00329 ** Changed include path schema for all DCMTK header files 00330 ** 00331 ** Revision 1.28 2004/07/01 12:28:25 meichel 00332 ** Introduced virtual clone method for DcmObject and derived classes. 00333 ** 00334 ** Revision 1.27 2003/07/04 13:25:35 meichel 00335 ** Replaced forward declarations for OFString with explicit includes, 00336 ** needed when compiling with HAVE_STD_STRING 00337 ** 00338 ** Revision 1.26 2002/12/09 09:31:14 wilkens 00339 ** Modified/Added doc++ documentation. 00340 ** 00341 ** Revision 1.25 2002/12/06 12:49:09 joergr 00342 ** Enhanced "print()" function by re-working the implementation and replacing 00343 ** the boolean "showFullData" parameter by a more general integer flag. 00344 ** Added doc++ documentation. 00345 ** Made source code formatting more consistent with other modules/files. 00346 ** 00347 ** Revision 1.24 2002/08/27 16:55:31 meichel 00348 ** Initial release of new DICOM I/O stream classes that add support for stream 00349 ** compression (deflated little endian explicit VR transfer syntax) 00350 ** 00351 ** Revision 1.23 2002/04/25 10:06:09 joergr 00352 ** Added/modified getOFStringArray() implementation. 00353 ** Added support for XML output of DICOM objects. 00354 ** 00355 ** Revision 1.22 2001/09/25 17:19:25 meichel 00356 ** Adapted dcmdata to class OFCondition 00357 ** 00358 ** Revision 1.21 2001/06/01 15:48:39 meichel 00359 ** Updated copyright header 00360 ** 00361 ** Revision 1.20 2001/05/10 12:50:21 meichel 00362 ** Added protected createEmptyValue() method in class DcmElement. 00363 ** 00364 ** Revision 1.19 2000/11/07 16:56:06 meichel 00365 ** Initial release of dcmsign module for DICOM Digital Signatures 00366 ** 00367 ** Revision 1.18 2000/03/08 16:26:14 meichel 00368 ** Updated copyright header. 00369 ** 00370 ** Revision 1.17 2000/02/02 14:31:16 joergr 00371 ** Replaced 'delete' statements by 'delete[]' for objects created with 'new[]'. 00372 ** 00373 ** Revision 1.16 1999/03/31 09:24:37 meichel 00374 ** Updated copyright header in module dcmdata 00375 ** 00376 ** Revision 1.15 1998/11/12 16:47:38 meichel 00377 ** Implemented operator= for all classes derived from DcmObject. 00378 ** 00379 ** Revision 1.14 1998/07/15 15:48:47 joergr 00380 ** Removed several compiler warnings reported by gcc 2.8.1 with 00381 ** additional options, e.g. missing copy constructors and assignment 00382 ** operators, initialization of member variables in the body of a 00383 ** constructor instead of the member initialization list, hiding of 00384 ** methods by use of identical names, uninitialized member variables, 00385 ** missing const declaration of char pointers. Replaced tabs by spaces. 00386 ** 00387 ** Revision 1.13 1997/09/11 15:13:10 hewett 00388 ** Modified getOFString method arguments by removing a default value 00389 ** for the pos argument. By requiring the pos argument to be provided 00390 ** ensures that callers realise getOFString only gets one component of 00391 ** a multi-valued string. 00392 ** 00393 ** Revision 1.12 1997/08/29 08:32:38 andreas 00394 ** - Added methods getOFString and getOFStringArray for all 00395 ** string VRs. These methods are able to normalise the value, i. e. 00396 ** to remove leading and trailing spaces. This will be done only if 00397 ** it is described in the standard that these spaces are not relevant. 00398 ** These methods do not test the strings for conformance, this means 00399 ** especially that they do not delete spaces where they are not allowed! 00400 ** getOFStringArray returns the string with all its parts separated by \ 00401 ** and getOFString returns only one value of the string. 00402 ** CAUTION: Currently getString returns a string with trailing 00403 ** spaces removed (if dcmEnableAutomaticInputDataCorrection == OFTrue) and 00404 ** truncates the original string (since it is not copied!). If you rely on this 00405 ** behaviour please change your application now. 00406 ** Future changes will ensure that getString returns the original 00407 ** string from the DICOM object (NULL terminated) inclusive padding. 00408 ** Currently, if you call getOF... before calling getString without 00409 ** normalisation, you can get the original string read from the DICOM object. 00410 ** 00411 ** Revision 1.11 1997/07/31 06:57:59 andreas 00412 ** new protected method swapValueField for DcmElement 00413 ** 00414 ** Revision 1.10 1997/07/21 07:57:53 andreas 00415 ** - New method DcmElement::detachValueField to give control over the 00416 ** value field to the calling part (see dcelem.h) 00417 ** - Replace all boolean types (BOOLEAN, CTNBOOLEAN, DICOM_BOOL, BOOL) 00418 ** with one unique boolean type OFBool. 00419 ** 00420 ** Revision 1.9 1997/05/27 13:48:26 andreas 00421 ** - Add method canWriteXfer to class DcmObject and all derived classes. 00422 ** This method checks whether it is possible to convert the original 00423 ** transfer syntax to an new transfer syntax. The check is used in the 00424 ** dcmconv utility to prohibit the change of a compressed transfer 00425 ** syntax to a uncompressed. 00426 ** 00427 ** Revision 1.8 1997/05/16 08:23:46 andreas 00428 ** - Revised handling of GroupLength elements and support of 00429 ** DataSetTrailingPadding elements. The enumeratio E_GrpLenEncoding 00430 ** got additional enumeration values (for a description see dctypes.h). 00431 ** addGroupLength and removeGroupLength methods are replaced by 00432 ** computeGroupLengthAndPadding. To support Padding, the parameters of 00433 ** element and sequence write functions changed. 00434 ** - Added a new method calcElementLength to calculate the length of an 00435 ** element, item or sequence. For elements it returns the length of 00436 ** tag, length field, vr field, and value length, for item and 00437 ** sequences it returns the length of the whole item. sequence including 00438 ** the Delimitation tag (if appropriate). It can never return 00439 ** UndefinedLength. 00440 ** 00441 ** Revision 1.7 1997/04/18 08:13:28 andreas 00442 ** - The put/get-methods for all VRs did not conform to the C++-Standard 00443 ** draft. Some Compilers (e.g. SUN-C++ Compiler, Metroworks 00444 ** CodeWarrier, etc.) create many warnings concerning the hiding of 00445 ** overloaded get methods in all derived classes of DcmElement. 00446 ** So the interface of all value representation classes in the 00447 ** library are changed rapidly, e.g. 00448 ** OFCondition get(Uint16 & value, const unsigned long pos); 00449 ** becomes 00450 ** OFCondition getUint16(Uint16 & value, const unsigned long pos); 00451 ** All (retired) "returntype get(...)" methods are deleted. 00452 ** For more information see dcmdata/include/dcelem.h 00453 ** 00454 ** Revision 1.6 1996/07/17 12:38:58 andreas 00455 ** new nextObject to iterate a DicomDataset, DicomFileFormat, Item, ... 00456 ** 00457 ** Revision 1.5 1996/04/16 16:01:36 andreas 00458 ** - put methods for AttributeTag with DcmTagKey Parameter 00459 ** - better support for NULL values 00460 ** 00461 ** Revision 1.4 1996/03/12 15:31:56 hewett 00462 ** The base virtual get & put functions now support char*. 00463 ** 00464 ** Revision 1.3 1996/01/05 13:22:55 andreas 00465 ** - changed to support new streaming facilities 00466 ** - more cleanups 00467 ** - merged read / write methods for block and file transfer 00468 ** 00469 */ 00470