OFFIS DCMTK  Version 3.6.0
dvcache.h
1 /*
2  *
3  * Copyright (C) 1998-2010, OFFIS e.V.
4  * All rights reserved. See COPYRIGHT file for details.
5  *
6  * This software and supporting documentation were developed by
7  *
8  * OFFIS e.V.
9  * R&D Division Health
10  * Escherweg 2
11  * D-26121 Oldenburg, Germany
12  *
13  *
14  * Module: dcmpstat
15  *
16  * Author: Joerg Riesmeier
17  *
18  * Purpose: Classes for caching of the image database (Header/Source)
19  *
20  * Last Update: $Author: joergr $
21  * Update Date: $Date: 2010-10-14 13:16:35 $
22  * CVS/RCS Revision: $Revision: 1.20 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 
30 #ifndef DVCACHE_H
31 #define DVCACHE_H
32 
33 #include "dcmtk/config/osconfig.h"
34 
35 #include "dcmtk/ofstd/oflist.h"
36 #include "dcmtk/ofstd/ofstring.h"
37 #include "dcmtk/dcmqrdb/dcmqrdbi.h" /* for DVIFhierarchyStatus */
38 
39 
40 /*--------------------*
41  * type definitions *
42  *--------------------*/
43 
46 enum DVPSInstanceType
47 {
49  DVPSI_image,
51  DVPSI_presentationState,
53  DVPSI_structuredReport,
55  DVPSI_storedPrint,
57  DVPSI_hardcopyGrayscale
58 };
59 
60 
61 /*---------------------*
62  * class declaration *
63  *---------------------*/
64 
71 {
72 
73  public:
74 
77  struct ItemStruct
78  {
89  ItemStruct(const OFString &uid,
90  const int pos,
91  const DVIFhierarchyStatus status,
92  const DVPSInstanceType type,
93  const int size,
94  const OFString &filename)
95  : UID(uid),
96  Pos(pos),
97  Status(status),
98  Type(type),
99  ImageSize(size),
100  Filename(filename),
101  Checked(OFFalse),
102  Description(),
103  Label(),
104  List()
105  {}
106 
110  int Pos;
112  DVIFhierarchyStatus Status;
114  DVPSInstanceType Type;
120  OFBool Checked;
127  };
128 
132  : List(),
133  Iterator(),
134  OldIterator()
135  {
136  Iterator = OldIterator = List.end();
137  }
138 
142  {
143  clear();
144  }
145 
149  inline void clear()
150  {
151  Iterator = List.begin();
152  OFListIterator(ItemStruct *) last = List.end();
153  while (Iterator != last)
154  {
155  delete (*Iterator);
156  Iterator = List.erase(Iterator);
157  }
158  List.clear();
159  Iterator = OldIterator = List.end();
160  }
161 
166  inline OFBool empty() const
167  {
168  return List.empty();
169  }
170 
175  inline Uint32 getCount() const
176  {
177  return List.size();
178  }
179 
186  inline OFBool gotoItem(Uint32 idx)
187  {
188  OFBool result = OFFalse;
189  Iterator = List.begin();
190  OFListIterator(ItemStruct *) last = List.end();
191  while (Iterator != last)
192  {
193  if (idx == 0)
194  {
195  result = OFTrue;
196  break;
197  }
198  idx--;
199  ++Iterator;
200  }
201  return result;
202  }
203 
208  inline OFBool gotoFirst()
209  {
210  OldIterator = Iterator;
211  Iterator = List.begin();
212  return (Iterator != List.end());
213  }
214 
219  inline OFBool gotoNext()
220  {
221  OFListIterator(ItemStruct *) last = List.end();
222  if (Iterator != last)
223  Iterator++;
224  return (Iterator != last);
225  }
226 
232  inline OFBool reset()
233  {
234  OFBool result = OFFalse;
235  OFListIterator(ItemStruct *) last = List.end();
236  if (OldIterator != last)
237  {
238  Iterator = OldIterator;
239  OldIterator = last;
240  result = OFTrue;
241  }
242  return result;
243  }
244 
251  inline OFBool isElem(const OFString &uid)
252  {
253  OFBool result = OFFalse;
254  Iterator = List.begin();
255  OFListIterator(ItemStruct *) last = List.end();
256  while (Iterator != last)
257  {
258  const ItemStruct *item = (*Iterator);
259  if (item != NULL)
260  {
261  if (item->UID == uid)
262  {
263  result = OFTrue;
264  break;
265  }
266  }
267  ++Iterator;
268  }
269  return result;
270  }
271 
276  inline int getPos() const
277  {
278  const ItemStruct *item = getItem();
279  return (item != NULL) ? item->Pos : 0;
280  }
281 
286  inline DVIFhierarchyStatus getStatus() const
287  {
288  const ItemStruct *item = getItem();
289  return (item != NULL) ? item->Status : DVIF_objectIsNew;
290  }
291 
296  inline DVPSInstanceType getType() const
297  {
298  const ItemStruct *item = getItem();
299  return (item != NULL) ? item->Type : DVPSI_image;
300  }
301 
306  inline int getImageSize() const
307  {
308  const ItemStruct *item = getItem();
309  return (item != NULL) ? item->ImageSize : 0;
310  }
311 
316  inline const char *getFilename() const
317  {
318  const ItemStruct *item = getItem();
319  return (item != NULL) ? item->Filename.c_str() : (const char *)NULL;
320  }
321 
326  inline ItemStruct *getItem() const
327  {
328  OFListConstIterator(ItemStruct *) it = Iterator;
329  return (it != List.end()) ? (*Iterator) : (ItemStruct *)NULL;
330  }
331 
342  inline void addItem(const OFString &uid,
343  const int pos,
344  const DVIFhierarchyStatus status,
345  const DVPSInstanceType type,
346  const int size,
347  const OFString &filename)
348  {
349  ItemStruct *item = new ItemStruct(uid, pos, status, type, size, filename);
350  List.push_back(item);
351  Iterator = --List.end(); // set to new position
352  }
353 
358  inline DVIFhierarchyStatus updateStatus()
359  {
360  OFListIterator(ItemStruct *) first = List.begin();
361  OFListIterator(ItemStruct *) last = List.end();
362  OFListIterator(ItemStruct *) iter = first;
363  DVIFhierarchyStatus status = DVIF_objectIsNew;
364  while (iter != last)
365  {
366  ItemStruct *item = (*iter);
367  if (item != NULL)
368  {
369  switch (item->Status)
370  {
371  case DVIF_objectIsNew:
372  if (status == DVIF_objectIsNotNew)
373  status = DVIF_objectContainsNewSubobjects;
374  break;
375  case DVIF_objectIsNotNew:
376  case DVIF_objectContainsNewSubobjects:
377  if (iter == first)
378  status = DVIF_objectIsNotNew;
379  else if (status == DVIF_objectIsNew)
380  status = DVIF_objectContainsNewSubobjects;
381  break;
382  }
383  }
384  ++iter;
385  }
386  return status;
387  }
388 
389 
390  protected:
391 
395  OFListIterator(ItemStruct *) Iterator;
397  OFListIterator(ItemStruct *) OldIterator;
398 };
399 
400 
401 /* ------------------------------ */
402 
403 
410 {
411 
412  public:
413 
416  struct ItemStruct
417  {
425  ItemStruct(const OFString &uid,
426  const DVIFhierarchyStatus status = DVIF_objectIsNew,
427  const DVPSInstanceType type = DVPSI_image)
428  : UID(uid),
429  Status(status),
430  Type(type),
431  List()
432  {}
433 
437  DVIFhierarchyStatus Status;
439  DVPSInstanceType Type;
442  };
443 
446  DVSeriesCache()
447  : List(),
448  Iterator(),
449  OldIterator()
450  {
451  Iterator = OldIterator = List.end();
452  }
453 
456  virtual ~DVSeriesCache()
457  {
458  clear();
459  }
460 
464  inline void clear()
465  {
466  Iterator = List.begin();
467  OFListIterator(ItemStruct *) last = List.end();
468  while (Iterator != last)
469  {
470  delete (*Iterator);
471  Iterator = List.erase(Iterator);
472  }
473  List.clear();
474  Iterator = OldIterator = List.end();
475  }
476 
481  inline OFBool empty() const
482  {
483  return List.empty();
484  }
485 
490  inline Uint32 getCount() const
491  {
492  return List.size();
493  }
494 
501  inline OFBool gotoItem(Uint32 idx)
502  {
503  OFBool result = OFFalse;
504  Iterator = List.begin();
505  OFListIterator(ItemStruct *) last = List.end();
506  while (Iterator != last)
507  {
508  if (idx == 0)
509  {
510  result = OFTrue;
511  break;
512  }
513  idx--;
514  ++Iterator;
515  }
516  return result;
517  }
518 
523  inline OFBool gotoFirst()
524  {
525  OldIterator = Iterator;
526  Iterator = List.begin();
527  return (Iterator != List.end());
528  }
529 
534  inline OFBool gotoNext()
535  {
536  OFListIterator(ItemStruct *) last = List.end();
537  if (Iterator != last)
538  Iterator++;
539  return (Iterator != last);
540  }
541 
547  inline OFBool reset()
548  {
549  OFBool result = OFFalse;
550  OFListIterator(ItemStruct *) last = List.end();
551  if (OldIterator != last)
552  {
553  Iterator = OldIterator;
554  OldIterator = last;
555  result = OFTrue;
556  }
557  return result;
558  }
559 
566  inline OFBool isElem(const OFString &uid)
567  {
568  OFBool result = OFFalse;
569  Iterator = List.begin();
570  OFListIterator(ItemStruct *) last = List.end();
571  while (Iterator != last)
572  {
573  const ItemStruct *item = (*Iterator);
574  if (item != NULL)
575  {
576  if (item->UID == uid)
577  {
578  result = OFTrue;
579  break;
580  }
581  }
582  ++Iterator;
583  }
584  return result;
585  }
586 
591  inline DVIFhierarchyStatus getStatus() const
592  {
593  const ItemStruct *item = getItem();
594  return (item != NULL) ? item->Status : DVIF_objectIsNew;
595  }
596 
601  inline DVPSInstanceType getType() const
602  {
603  const ItemStruct *item = getItem();
604  return (item != NULL) ? item->Type : DVPSI_image;
605  }
606 
611  inline ItemStruct *getItem() const
612  {
613  OFListConstIterator(ItemStruct *) it = Iterator;
614  return (it != List.end()) ? (*Iterator) : (ItemStruct *)NULL;
615  }
616 
623  inline void addItem(const OFString &uid,
624  const DVIFhierarchyStatus status = DVIF_objectIsNew)
625  {
626  ItemStruct *item = new ItemStruct(uid, status);
627  List.push_back(item);
628  Iterator = --List.end(); // set to new position
629  }
630 
635  inline DVIFhierarchyStatus updateStatus()
636  {
637  OFListIterator(ItemStruct *) first = List.begin();
638  OFListIterator(ItemStruct *) last = List.end();
639  OFListIterator(ItemStruct *) iter = first;
640  DVIFhierarchyStatus status = DVIF_objectIsNew;
641  while (iter != last)
642  {
643  ItemStruct *item = (*iter);
644  if (item != NULL)
645  {
646  item->Status = item->List.updateStatus();
647  switch (item->Status)
648  {
649  case DVIF_objectIsNew:
650  if (status == DVIF_objectIsNotNew)
651  status = DVIF_objectContainsNewSubobjects;
652  break;
653  case DVIF_objectIsNotNew:
654  if (iter == first)
655  status = DVIF_objectIsNotNew;
656  else if (status == DVIF_objectIsNew)
657  status = DVIF_objectContainsNewSubobjects;
658  break;
659  case DVIF_objectContainsNewSubobjects:
660  status = DVIF_objectContainsNewSubobjects;
661  break;
662  }
663  }
664  ++iter;
665  }
666  return status;
667  }
668 
669 
670  protected:
671 
675  OFListIterator(ItemStruct *) Iterator;
677  OFListIterator(ItemStruct *) OldIterator;
678 };
679 
680 
681 /* ------------------------------ */
682 
683 
690 {
691 
692  public:
693 
696  struct ItemStruct
697  {
704  ItemStruct(const OFString &uid,
705  const DVIFhierarchyStatus status = DVIF_objectIsNew)
706  : UID(uid),
707  Status(status),
708  List()
709  {}
710 
714  DVIFhierarchyStatus Status;
716  DVSeriesCache List;
717  };
718 
721  DVStudyCache()
722  : List(),
723  Iterator()
724  {
725  Iterator = List.end();
726  }
727 
730  virtual ~DVStudyCache()
731  {
732  clear();
733  }
734 
738  inline void clear()
739  {
740  Iterator = List.begin();
741  OFListIterator(ItemStruct *) last = List.end();
742  while (Iterator != last)
743  {
744  delete (*Iterator);
745  Iterator = List.erase(Iterator);
746  }
747  List.clear();
748  Iterator = List.end();
749  }
750 
755  inline OFBool empty() const
756  {
757  return List.empty();
758  }
759 
764  inline Uint32 getCount() const
765  {
766  return List.size();
767  }
768 
775  inline OFBool gotoItem(Uint32 idx)
776  {
777  OFBool result = OFFalse;
778  Iterator = List.begin();
779  OFListIterator(ItemStruct *) last = List.end();
780  while (Iterator != last)
781  {
782  if (idx == 0)
783  {
784  result = OFTrue;
785  break;
786  }
787  idx--;
788  ++Iterator;
789  }
790  return result;
791  }
792 
797  inline OFBool gotoFirst()
798  {
799  //OldIterator = Iterator;
800  Iterator = List.begin();
801  return (Iterator != List.end());
802  }
803 
808  inline OFBool gotoNext()
809  {
810  OFListIterator(ItemStruct *) last = List.end();
811  if (Iterator != last)
812  Iterator++;
813  return (Iterator != last);
814  }
815 
822  inline OFBool isElem(const OFString &uid)
823  {
824  OFBool result = OFFalse;
825  Iterator = List.begin();
826  OFListIterator(ItemStruct *) last = List.end();
827  while (Iterator != last)
828  {
829  const ItemStruct *item = (*Iterator);
830  if (item != NULL)
831  {
832  if (item->UID == uid)
833  {
834  result= OFTrue;
835  break;
836  }
837  }
838  ++Iterator;
839  }
840  return result;
841  }
842 
847  inline DVIFhierarchyStatus getStatus() const
848  {
849  const ItemStruct *item = getItem();
850  return (item != NULL) ? item->Status : DVIF_objectIsNew;
851  }
852 
857  inline ItemStruct *getItem() const
858  {
859  OFListConstIterator(ItemStruct *) it = Iterator;
860  return (it != List.end()) ? (*Iterator) : (ItemStruct *)NULL;
861  }
862 
869  inline void addItem(const OFString &uid,
870  const DVIFhierarchyStatus status = DVIF_objectIsNew)
871  {
872  ItemStruct *item = new ItemStruct(uid, status);
873  List.push_back(item);
874  Iterator = --List.end(); // set to new position
875  }
876 
881  inline void updateStatus()
882  {
883  OFListIterator(ItemStruct *) iter = List.begin();
884  OFListIterator(ItemStruct *) last = List.end();
885  while (iter != last)
886  {
887  ItemStruct *item = (*iter);
888  if (item != NULL)
889  item->Status = item->List.updateStatus();
890  ++iter;
891  }
892  }
893 
894 
895  protected:
896 
900  OFListIterator(ItemStruct *) Iterator;
901 };
902 
903 
904 #endif
905 
906 
907 /*
908  *
909  * CVS/RCS Log:
910  * $Log: dvcache.h,v $
911  * Revision 1.20 2010-10-14 13:16:35 joergr
912  * Updated copyright header. Added reference to COPYRIGHT file.
913  *
914  * Revision 1.19 2010-10-07 14:31:35 joergr
915  * Removed leading underscore characters from preprocessor symbols (reserved).
916  *
917  * Revision 1.18 2009-09-07 12:51:40 joergr
918  * Converted Windows line breaks to Unix format.
919  *
920  * Revision 1.17 2009-09-04 13:53:09 meichel
921  * Minor const iterator related changes needed to compile with VC6 with HAVE_STL
922  *
923  * Revision 1.16 2005-12-08 16:03:30 meichel
924  * Changed include path schema for all DCMTK header files
925  *
926  * Revision 1.15 2005/04/04 10:11:57 meichel
927  * Module dcmpstat now uses the dcmqrdb API instead of imagectn for maintaining
928  * the index database
929  *
930  * Revision 1.14 2001/06/01 15:50:11 meichel
931  * Updated copyright header
932  *
933  * Revision 1.13 2000/10/16 11:39:10 joergr
934  * Added method allowing to select an instance by instance UID and SOP class
935  * UID (without series and study UID). Required for composite references in
936  * DICOM SR.
937  *
938  * Revision 1.12 2000/06/30 09:08:39 joergr
939  * Fixed bug in database cache routines (re. study status).
940  *
941  * Revision 1.11 2000/05/30 13:37:15 joergr
942  * Renamed GrayscaleHardcopy to HardcopyGrayscale (which is the correct term
943  * according to the DICOM standard).
944  *
945  * Revision 1.10 2000/03/08 16:28:47 meichel
946  * Updated copyright header.
947  *
948  * Revision 1.9 1999/09/08 17:03:00 joergr
949  * Added support for new instance types in database (grayscale hardcopy and
950  * stored print).
951  *
952  * Revision 1.8 1999/08/17 10:32:54 joergr
953  * Added Doc++ styled comments.
954  * Corrected wrong return type for method 'getImageSize()'.
955  *
956  * Revision 1.7 1999/05/03 11:01:08 joergr
957  * Minor code purifications to keep Sun CC 2.0.1 quiet.
958  *
959  * Revision 1.6 1999/04/29 15:25:36 joergr
960  * Added PresentationLabel to index file.
961  *
962  * Revision 1.5 1999/04/27 11:20:49 joergr
963  * Add remaining member variables to member initialization list to avoid
964  * compiler warnings.
965  *
966  * Revision 1.4 1999/02/24 20:14:39 joergr
967  * Added support for presentation state caching (e.g. pstate description).
968  * Removed unused methods.
969  *
970  * Revision 1.3 1999/02/19 18:56:08 joergr
971  * Added new methods to interate through Caches (getFirst/getNext) - needed
972  * for delete routines in Interface class.
973  *
974  * Revision 1.2 1999/02/19 09:45:19 joergr
975  * Changed some comments, corrected typos and formatting.
976  *
977  * Revision 1.1 1999/02/18 18:50:18 joergr
978  * Re-implemented methods to access index file (delete methods are still
979  * missing).
980  *
981  *
982  */


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2