1 #ifndef __creaImageIOTreeNodeComparators_h_INCLUDED__
2 #define __creaImageIOTreeNodeComparators_h_INCLUDED__
18 //=====================================================================
19 /// Abstract definition of a comparator of Node
22 virtual ~Comparator() {}
23 virtual bool operator() (Node* const & x, Node* const & y) = 0;
25 //=====================================================================
29 //=====================================================================
30 /// Abstract Comparator whose order can be reversed
31 struct ComparatorWithOrder : public Comparator
33 ComparatorWithOrder(bool reverse_order = false)
34 : mReverseOrder(reverse_order) {}
35 virtual ~ComparatorWithOrder() {}
38 virtual bool compare(Node* const &, Node* const &) = 0;
40 virtual bool operator() (Node* const & x, Node* const & y)
42 if (mReverseOrder) return this->compare(y,x);
43 return this->compare(x,y);
48 //=====================================================================
52 //=====================================================================
53 /// A Comparator which stores a vector of Comparators and
54 /// which performs lexicographical comparison
55 class LexicographicalComparator : public Comparator
58 LexicographicalComparator(const std::string& name)
60 ~LexicographicalComparator() {}
62 const std::string& GetName() const { return mName; }
63 void SetName(const std::string& s) { mName = s; }
64 void Clear() { mComparator.clear(); }
65 void DeleteComparators()
67 std::vector<Comparator*>::iterator i;
68 for (i =mComparator.begin();
76 void Add(Comparator* c) { mComparator.push_back(c); }
78 bool operator() (Node* const & x, Node * const & y);
82 std::vector<Comparator*> mComparator;
84 //=====================================================================
89 //===================================================================
90 /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as an int value
91 struct IntComparator :
92 public ComparatorWithOrder
94 IntComparator(const std::string& key,
97 ComparatorWithOrder(reverse_order),
100 virtual bool compare(Node* const & x, Node* const & y);
105 //===================================================================
107 //===================================================================
108 /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as an float value
109 struct FloatComparator :
110 public ComparatorWithOrder
112 FloatComparator(const std::string& key,
115 ComparatorWithOrder(reverse_order),
119 virtual bool compare(Node* const & x, Node* const & y);
124 //===================================================================
126 //===================================================================
127 /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as a string value
128 struct StringComparator :
129 public ComparatorWithOrder
131 StringComparator(const std::string& key,
134 ComparatorWithOrder(reverse_order),
138 virtual bool compare(Node* const & x, Node* const & y);
143 //===================================================================
145 //===================================================================
146 #define INT_FIELD_COMP(NAME,FIELD) \
147 struct Node##NAME##Comparator : \
148 public IntComparator \
150 Node##NAME##Comparator(bool o = false) : \
151 IntComparator(FIELD,o) \
154 //==================================================================
156 //===================================================================
157 #define FLOAT_FIELD_COMP(NAME,FIELD) \
158 struct Node##NAME##Comparator : \
159 public FloatComparator \
161 Node##NAME##Comparator(bool o = false) : \
162 FloatComparator(FIELD,o) \
165 //===================================================================
167 //===================================================================
168 #define STRING_FIELD_COMP(NAME,FIELD) \
169 struct Node##NAME##Comparator : \
170 public StringComparator \
172 Node##NAME##Comparator(bool o = false) : \
173 StringComparator(FIELD,o) \
176 //===================================================================
180 //===================================================================
181 // Patient comparators
182 STRING_FIELD_COMP(PatientName,"A0010_0010");
183 STRING_FIELD_COMP(PatientSex, "A0010_0040");
184 STRING_FIELD_COMP(PatientBirthday, "A0010_0030");
185 //===================================================================
187 //===================================================================
189 STRING_FIELD_COMP(StudyDate,"A0008_0020");
190 STRING_FIELD_COMP(StudyDescription,"A0008_1030");
191 //===================================================================
193 //===================================================================
194 // Series comparators
195 STRING_FIELD_COMP(Modality,"A0008_0060");
196 STRING_FIELD_COMP(SeriesDescription,"A0008_103E");
197 STRING_FIELD_COMP(SeriesDate,"A0008_0021");
198 //===================================================================
200 //===================================================================
202 INT_FIELD_COMP(ImageNumber,"A0020_0013");
203 FLOAT_FIELD_COMP(SliceLocation,"A0020_1041");
204 STRING_FIELD_COMP(FullFileName,"FullFileName");
205 //===================================================================
208 } // namespace creaImageIO
212 #endif // #ifndef __creaImageIOComparators_h_INCLUDED__