1 /*
2  *
3  *  Copyright (C) 2000-2015, 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: dcmsr
15  *
16  *  Author: Joerg Riesmeier
17  *
18  *  Purpose:
19  *    classes: DSRWaveformChannelItem, DSRWaveformChannelList
20  *
21  */
22 
23 
24 #ifndef DSRWAVCH_H
25 #define DSRWAVCH_H
26 
27 #include "dcmtk/config/osconfig.h"   /* make sure OS specific configuration is included first */
28 
29 #include "dcmtk/dcmsr/dsrtypes.h"
30 #include "dcmtk/dcmsr/dsrtlist.h"
31 
32 
33 /*---------------------*
34  *  class declaration  *
35  *---------------------*/
36 
37 /** Class for waveform channel items
38  */
39 class DCMTK_DCMSR_EXPORT DSRWaveformChannelItem
40 {
41   public:
42 
43     /** (default) constructor
44      ** @param  multiplexGroupNumber  optional multiplex group number
45      *  @param  channelNumber         optional channel number
46      */
47     DSRWaveformChannelItem(const Uint16 multiplexGroupNumber = 0,
48                            const Uint16 channelNumber = 0)
MultiplexGroupNumber(multiplexGroupNumber)49       : MultiplexGroupNumber(multiplexGroupNumber),
50         ChannelNumber(channelNumber)
51     {
52     }
53 
54     /** comparison operator
55      ** @param  item  item with which the (m,c) pair should be compared
56      ** @return OFTrue if both pairs are equal, OFFalse otherwise
57      */
58     inline OFBool operator==(const DSRWaveformChannelItem &item) const
59     {
60         return (item.MultiplexGroupNumber == MultiplexGroupNumber) && (item.ChannelNumber == ChannelNumber);
61     }
62 
63     /** comparison operator
64      ** @param  item  item with which the (m,c) pair should be compared
65      ** @return true if not equal, false if equal
66      */
67     inline OFBool operator!=(const DSRWaveformChannelItem &item) const
68     {
69         return (item.MultiplexGroupNumber != MultiplexGroupNumber) || (item.ChannelNumber != ChannelNumber);
70     }
71 
72     /** comparison operator
73      ** @param  item  item with which the (m,c) pair should be compared
74      ** @return true if smaller. ChannelNumber takes precedence over MultiplexGroupNumber.
75      */
76     inline OFBool operator<(const DSRWaveformChannelItem &item) const
77     {
78         return (ChannelNumber < item.ChannelNumber) || ((ChannelNumber == item.ChannelNumber) && (MultiplexGroupNumber < item.MultiplexGroupNumber));
79     }
80 
81     /** comparison operator
82      ** @param  item  item with which the (m,c) pair should be compared
83      ** @return true if greater. ChannelNumber takes precedence over MultiplexGroupNumber.
84      */
85     inline OFBool operator>(const DSRWaveformChannelItem &item) const
86     {
87         return (ChannelNumber > item.ChannelNumber) || ((ChannelNumber == item.ChannelNumber) && (MultiplexGroupNumber > item.MultiplexGroupNumber));
88     }
89 
90     /* copy constructor and assignment operator are defined implicitly */
91 
92     /// multiplex group number value (VR=US)
93     Uint16 MultiplexGroupNumber;
94     /// channel number value (VR=US)
95     Uint16 ChannelNumber;
96 };
97 
98 
99 /** Class for waveform channel lists
100  */
101 class DCMTK_DCMSR_EXPORT DSRWaveformChannelList
102   : public DSRListOfItems<DSRWaveformChannelItem>
103 {
104 
105   public:
106 
107     /** default constructor
108      */
109     DSRWaveformChannelList();
110 
111     /** copy constructor
112      ** @param  lst  list to be copied
113      */
114     DSRWaveformChannelList(const DSRWaveformChannelList &lst);
115 
116     /** destructor
117      */
118     virtual ~DSRWaveformChannelList();
119 
120     /** assignment operator
121      ** @param  lst  list to be copied
122      ** @return reference to this list after 'lst' has been copied
123      */
124     DSRWaveformChannelList &operator=(const DSRWaveformChannelList &lst);
125 
126     /** print list of waveform channels.
127      *  The output of a typical list looks like this: 1/2,3/4,5/6
128      ** @param  stream         output stream to which the list should be printed
129      *  @param  flags          flag used to customize the output (see DSRTypes::PF_xxx)
130      *  @param  pairSeparator  character specifying the separator between the value pairs
131      *  @param  itemSeparator  character specifying the separator between the list items
132      ** @return status, EC_Normal if successful, an error code otherwise
133      */
134     OFCondition print(STD_NAMESPACE ostream &stream,
135                       const size_t flags = 0,
136                       const char pairSeparator = '/',
137                       const char itemSeparator = ',') const;
138 
139     /** read list of waveform channels
140      ** @param  dataset  DICOM dataset from which the list should be read
141      *  @param  flags    flag used to customize the reading process (see DSRTypes::RF_xxx)
142      ** @return status, EC_Normal if successful, an error code otherwise
143      */
144     OFCondition read(DcmItem &dataset,
145                      const size_t flags);
146 
147     /** write list of waveform channels
148      ** @param  dataset  DICOM dataset to which the list should be written
149      ** @return status, EC_Normal if successful, an error code otherwise
150      */
151     OFCondition write(DcmItem &dataset) const;
152 
153     /** check whether specified value pair is contained in the list
154      ** @param  multiplexGroupNumber  multiplex group number to be checked
155      *  @param  channelNumber         channel number to be checked
156      ** @return OFTrue if the value pair is in the list, OFFalse otherwise
157      */
158     OFBool isElement(const Uint16 multiplexGroupNumber,
159                      const Uint16 channelNumber) const;
160 
161     /** get copy of the specified value pair
162      ** @param  idx                   index of the value pair to be returned (starting from 1)
163      *  @param  multiplexGroupNumber  multiplex group number of the specified index (set to 0)
164      *  @param  channelNumber         channel number of the specified index (set to 0 first)
165      ** @return status, EC_Normal if successful, an error code otherwise
166      */
167     OFCondition getItem(const size_t idx,
168                         Uint16 &multiplexGroupNumber,
169                         Uint16 &channelNumber) const;
170 
171     /** add value pair to the list
172      ** @param  multiplexGroupNumber  multiplex group number to be added
173      *  @param  channelNumber         channel number to be added
174      */
175     void addItem(const Uint16 multiplexGroupNumber,
176                  const Uint16 channelNumber);
177 
178     /** put list of waveform channels as a string.
179      *  This function expects the same input format as created by print(), i.e. a comma
180      *  separated list of numerical value pairs.
181      ** @param  stringValue  string value to be set
182      ** @return status, EC_Normal if successful, an error code otherwise
183      */
184     OFCondition putString(const char *stringValue);
185 };
186 
187 
188 #endif
189