00001 /* 00002 * 00003 * Copyright (C) 1994-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: dcmdata 00015 * 00016 * Author: Andrew Hewett 00017 * 00018 * Purpose: Basis class for dicom tags. 00019 * 00020 * Last Update: $Author: joergr $ 00021 * Update Date: $Date: 2010-10-21 07:52:40 $ 00022 * CVS/RCS Revision: $Revision: 1.23 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 00026 * 00027 */ 00028 00029 #ifndef DCMTAGKEY_H 00030 #define DCMTAGKEY_H 1 00031 00032 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 00033 00034 #include "dcmtk/ofstd/ofstream.h" 00035 #include "dcmtk/ofstd/ofstring.h" 00036 00037 /* 00038 ** Defines 00039 */ 00040 00042 #define DCM_UndefinedTagKey DcmTagKey(0xffff, 0xffff) 00043 00046 class DcmTagKey 00047 { 00048 public: 00049 00052 DcmTagKey(); 00053 00057 DcmTagKey(const DcmTagKey& key); 00058 00063 DcmTagKey(Uint16 g, Uint16 e); 00064 00067 virtual ~DcmTagKey(); 00068 00072 void set(const DcmTagKey& key); 00073 00078 void set(Uint16 g, Uint16 e); 00079 00083 void setGroup(Uint16 g); 00084 00088 void setElement(Uint16 e); 00089 00093 Uint16 getGroup() const; 00094 00098 Uint16 getElement() const; 00099 00104 OFBool isGroupLength() const; 00105 00110 OFBool isPrivate() const; 00111 00117 OFBool isPrivateReservation() const; 00118 00123 OFBool hasValidGroup() const; 00124 00129 Uint32 hash() const; // generate simple hash code 00130 00136 DcmTagKey& operator = (const DcmTagKey& key); 00137 00143 int operator == (const DcmTagKey& key) const; 00144 00150 int operator != (const DcmTagKey& key) const; 00151 00157 int operator < (const DcmTagKey& key) const; 00158 00164 int operator > (const DcmTagKey& key) const; 00165 00171 int operator <= (const DcmTagKey& key) const; 00172 00178 int operator >= (const DcmTagKey& key) const; 00179 00180 friend STD_NAMESPACE ostream& operator<<(STD_NAMESPACE ostream& s, const DcmTagKey& k); 00181 00185 OFString toString() const; 00186 00191 OFBool isSignableTag() const; 00192 00193 protected: 00194 00196 int groupLT(const DcmTagKey& key) const; 00197 00199 int groupGT(const DcmTagKey& key) const; 00200 00202 int groupEQ(const DcmTagKey& key) const; 00203 00205 int elementLT(const DcmTagKey& key) const; 00206 00208 int elementGT(const DcmTagKey& key) const; 00209 00211 int elementEQ(const DcmTagKey& key) const; 00212 00213 private: 00214 00216 Uint16 group; 00218 Uint16 element; 00219 00220 }; 00221 00227 STD_NAMESPACE ostream& operator<<(STD_NAMESPACE ostream& s, const DcmTagKey& k); 00228 00229 /* 00230 ** inline versions of functions 00231 */ 00232 00233 /* constructors and destructor */ 00234 00235 inline 00236 DcmTagKey::DcmTagKey() 00237 : group(0xffff), 00238 element(0xffff) 00239 { 00240 } 00241 00242 inline 00243 DcmTagKey::DcmTagKey(const DcmTagKey& key) 00244 : group(key.group), 00245 element(key.element) 00246 { 00247 } 00248 00249 inline 00250 DcmTagKey::DcmTagKey(Uint16 g, Uint16 e) 00251 : group(g), 00252 element(e) 00253 { 00254 } 00255 00256 inline 00257 DcmTagKey::~DcmTagKey() 00258 { 00259 } 00260 00261 /* access methods */ 00262 00263 inline void 00264 DcmTagKey::set(const DcmTagKey& key) 00265 { 00266 group = key.group; 00267 element = key.element; 00268 } 00269 00270 inline void 00271 DcmTagKey::set(Uint16 g, Uint16 e) 00272 { 00273 group = g; 00274 element = e; 00275 } 00276 00277 inline void 00278 DcmTagKey::setGroup(Uint16 g) 00279 { 00280 group = g; 00281 } 00282 00283 inline void 00284 DcmTagKey::setElement(Uint16 e) 00285 { 00286 element = e; 00287 } 00288 00289 inline Uint16 00290 DcmTagKey::getGroup() const 00291 { 00292 return group; 00293 } 00294 00295 inline Uint16 00296 DcmTagKey::getElement() const 00297 { 00298 return element; 00299 } 00300 00301 inline OFBool 00302 DcmTagKey::isGroupLength() const 00303 { 00304 return (element == 0) && hasValidGroup(); 00305 } 00306 00307 inline OFBool 00308 DcmTagKey::isPrivate() const 00309 { 00310 return ((group & 1) != 0 ) && hasValidGroup(); 00311 } 00312 00313 inline OFBool 00314 DcmTagKey::isPrivateReservation() const 00315 { 00316 // private reservation has element number ranging from 0x0010 to 0x00FF 00317 return isPrivate() && (element >= 0x10) && (element <= 0xFF); 00318 } 00319 00320 inline OFBool 00321 DcmTagKey::hasValidGroup() const 00322 { 00323 // group numbers 1, 3, 5, 7 and 0xFFFF are illegal in DICOM 00324 if (((group & 1) != 0) && ((group <= 7) || (group == 0xFFFF))) 00325 return OFFalse; 00326 else 00327 return OFTrue; 00328 } 00329 00330 inline DcmTagKey& 00331 DcmTagKey::operator=(const DcmTagKey& key) 00332 { 00333 set(key); 00334 return *this; 00335 } 00336 00337 /* Simple Hash Function */ 00338 00339 inline Uint32 00340 DcmTagKey::hash() const 00341 { 00342 // generate simple hash code 00343 return (((getGroup() << 16) & 0xffff0000) | (getElement() & 0xffff)); 00344 } 00345 00346 /* Comparisons */ 00347 00348 inline int 00349 DcmTagKey::groupLT(const DcmTagKey& key) const 00350 { 00351 return (getGroup() < key.getGroup()); 00352 } 00353 00354 inline int 00355 DcmTagKey::groupGT(const DcmTagKey& key) const 00356 { 00357 return (getGroup() > key.getGroup()); 00358 } 00359 00360 inline int 00361 DcmTagKey::groupEQ(const DcmTagKey& key) const 00362 { 00363 return getGroup() == key.getGroup(); 00364 } 00365 00366 inline int 00367 DcmTagKey::elementLT(const DcmTagKey& key) const 00368 { 00369 return (getElement() < key.getElement()); 00370 } 00371 00372 inline int 00373 DcmTagKey::elementGT(const DcmTagKey& key) const 00374 { 00375 return (getElement() > key.getElement()); 00376 } 00377 00378 inline int 00379 DcmTagKey::elementEQ(const DcmTagKey& key) const 00380 { 00381 return getElement() == key.getElement(); 00382 } 00383 00384 inline int 00385 DcmTagKey::operator == (const DcmTagKey& key) const 00386 { 00387 return ( groupEQ(key) && elementEQ(key) ); 00388 } 00389 00390 inline int 00391 DcmTagKey::operator != (const DcmTagKey& key) const 00392 { 00393 return !(*this == key); 00394 } 00395 00396 inline int 00397 DcmTagKey::operator < (const DcmTagKey& key) const 00398 { 00399 return (groupLT(key) || (groupEQ(key) && elementLT(key))); 00400 } 00401 00402 inline int 00403 DcmTagKey::operator > (const DcmTagKey& key) const 00404 { 00405 return (groupGT(key) || (groupEQ(key) && elementGT(key))); 00406 } 00407 00408 inline int 00409 DcmTagKey::operator <= (const DcmTagKey& key) const 00410 { 00411 return (*this < key) || (*this == key); 00412 } 00413 00414 inline int 00415 DcmTagKey::operator >= (const DcmTagKey& key) const 00416 { 00417 return (*this > key) || (*this == key); 00418 } 00419 00420 #endif 00421 00422 00423 /* 00424 ** CVS/RCS Log: 00425 ** $Log: dctagkey.h,v $ 00426 ** Revision 1.23 2010-10-21 07:52:40 joergr 00427 ** Added virtual destructor in order to avoid warnings reported by gcc with 00428 ** additional flags. 00429 ** 00430 ** Revision 1.22 2010-10-14 13:15:42 joergr 00431 ** Updated copyright header. Added reference to COPYRIGHT file. 00432 ** 00433 ** Revision 1.21 2010-03-01 09:08:44 uli 00434 ** Removed some unnecessary include directives in the headers. 00435 ** 00436 ** Revision 1.20 2009-04-20 16:00:08 joergr 00437 ** Added method that checks whether the tag key is a valid group length element. 00438 ** 00439 ** Revision 1.19 2009-01-15 16:06:27 onken 00440 ** Added convenience methods for private tag handling. Added doxygen 00441 ** documentation for not or badly documented member functions. 00442 ** 00443 ** Revision 1.18 2007-11-29 14:30:35 meichel 00444 ** Updated doxygen API documentation 00445 ** 00446 ** Revision 1.17 2006/08/15 15:49:56 meichel 00447 ** Updated all code in module dcmdata to correctly compile when 00448 ** all standard C++ classes remain in namespace std. 00449 ** 00450 ** Revision 1.16 2005/12/08 16:28:45 meichel 00451 ** Changed include path schema for all DCMTK header files 00452 ** 00453 ** Revision 1.15 2004/01/16 14:08:00 joergr 00454 ** Removed acknowledgements with e-mail addresses from CVS log. 00455 ** 00456 ** Revision 1.14 2003/11/13 14:06:36 meichel 00457 ** Fixed definition of DCM_UndefinedTagKey 00458 ** 00459 ** Revision 1.13 2003/11/05 15:56:31 meichel 00460 ** Added declaration of operator<< for DcmTagKeys. 00461 ** Fixes compilation issue on Visual C++ 6.0 SP 0. 00462 ** 00463 ** Revision 1.12 2002/04/16 13:41:44 joergr 00464 ** Added configurable support for C++ ANSI standard includes (e.g. streams). 00465 ** 00466 ** Revision 1.11 2001/11/19 15:23:11 meichel 00467 ** Cleaned up signature code to avoid some gcc warnings. 00468 ** 00469 ** Revision 1.10 2001/11/16 15:54:40 meichel 00470 ** Adapted digital signature code to final text of supplement 41. 00471 ** 00472 ** Revision 1.9 2001/06/01 15:48:45 meichel 00473 ** Updated copyright header 00474 ** 00475 ** Revision 1.8 2000/11/07 16:56:10 meichel 00476 ** Initial release of dcmsign module for DICOM Digital Signatures 00477 ** 00478 ** Revision 1.7 2000/03/08 16:26:19 meichel 00479 ** Updated copyright header. 00480 ** 00481 ** Revision 1.6 2000/02/07 14:45:16 meichel 00482 ** Removed const qualifier from DcmTagKey::toString(), avoids warning on Irix. 00483 ** 00484 ** Revision 1.5 1999/03/31 09:24:49 meichel 00485 ** Updated copyright header in module dcmdata 00486 ** 00487 ** Revision 1.4 1999/03/17 11:08:54 meichel 00488 ** added method DcmTagKey::toString() 00489 ** 00490 ** Revision 1.3 1998/07/15 15:48:54 joergr 00491 ** Removed several compiler warnings reported by gcc 2.8.1 with 00492 ** additional options, e.g. missing copy constructors and assignment 00493 ** operators, initialization of member variables in the body of a 00494 ** constructor instead of the member initialization list, hiding of 00495 ** methods by use of identical names, uninitialized member variables, 00496 ** missing const declaration of char pointers. Replaced tabs by spaces. 00497 ** 00498 ** Revision 1.2 1997/08/26 13:45:54 hewett 00499 ** Added simple hash function method. 00500 ** 00501 ** Revision 1.1 1995/11/23 16:38:04 hewett 00502 ** Updated for loadable data dictionary + some cleanup (more to do). 00503 ** 00504 */