#ifndef __creaImageIOTreeNodeComparators_h_INCLUDED__ #define __creaImageIOTreeNodeComparators_h_INCLUDED__ #include #include namespace creaImageIO { namespace tree { class Node; /** * \ingroup Tree */ //===================================================================== /// Abstract definition of a comparator of Node struct Comparator { virtual ~Comparator() {} virtual bool operator() (Node* const & x, Node* const & y) = 0; }; //===================================================================== //===================================================================== /// Abstract Comparator whose order can be reversed struct ComparatorWithOrder : public Comparator { ComparatorWithOrder(bool reverse_order = false) : mReverseOrder(reverse_order) {} virtual ~ComparatorWithOrder() {} virtual bool compare(Node* const &, Node* const &) = 0; virtual bool operator() (Node* const & x, Node* const & y) { if (mReverseOrder) return this->compare(y,x); return this->compare(x,y); }; bool mReverseOrder; }; //===================================================================== //===================================================================== /// A Comparator which stores a vector of Comparators and /// which performs lexicographical comparison class LexicographicalComparator : public Comparator { public: LexicographicalComparator(const std::string& name) : mName(name) {} ~LexicographicalComparator() {} const std::string& GetName() const { return mName; } void SetName(const std::string& s) { mName = s; } void Clear() { mComparator.clear(); } void DeleteComparators() { std::vector::iterator i; for (i =mComparator.begin(); i!=mComparator.end(); ++i) { delete *i; } mComparator.clear(); } void Add(Comparator* c) { mComparator.push_back(c); } bool operator() (Node* const & x, Node * const & y); private: std::string mName; std::vector mComparator; }; //===================================================================== //=================================================================== /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as an int value struct IntComparator : public ComparatorWithOrder { IntComparator(const std::string& key, bool reverse_order) : ComparatorWithOrder(reverse_order), mKey(key) {} virtual bool compare(Node* const & x, Node* const & y); private: std::string mKey; }; //=================================================================== //=================================================================== /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as an float value struct FloatComparator : public ComparatorWithOrder { FloatComparator(const std::string& key, bool reverse_order ) : ComparatorWithOrder(reverse_order), mKey(key) {} virtual bool compare(Node* const & x, Node* const & y); private: std::string mKey; }; //=================================================================== //=================================================================== /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as a string value struct StringComparator : public ComparatorWithOrder { StringComparator(const std::string& key, bool reverse_order ) : ComparatorWithOrder(reverse_order), mKey(key) {} virtual bool compare(Node* const & x, Node* const & y); private: std::string mKey; }; //=================================================================== //=================================================================== #define INT_FIELD_COMP(NAME,FIELD) \ struct Node##NAME##Comparator : \ public IntComparator \ { \ Node##NAME##Comparator(bool o = false) : \ IntComparator(FIELD,o) \ {} \ } //================================================================== //=================================================================== #define FLOAT_FIELD_COMP(NAME,FIELD) \ struct Node##NAME##Comparator : \ public FloatComparator \ { \ Node##NAME##Comparator(bool o = false) : \ FloatComparator(FIELD,o) \ {} \ } //=================================================================== //=================================================================== #define STRING_FIELD_COMP(NAME,FIELD) \ struct Node##NAME##Comparator : \ public StringComparator \ { \ Node##NAME##Comparator(bool o = false) : \ StringComparator(FIELD,o) \ {} \ } //=================================================================== //=================================================================== // Patient comparators ///Compares the names of the patients STRING_FIELD_COMP(PatientName,"A0010_0010"); ///Compares the sex of the patients STRING_FIELD_COMP(PatientSex, "A0010_0040"); ///Compares the birthdays of the patients STRING_FIELD_COMP(PatientBirthday, "A0010_0030"); //=================================================================== //=================================================================== // Study comparators ///Compares the dates of the studies STRING_FIELD_COMP(StudyDate,"A0008_0020"); ///Compares the description of the studies STRING_FIELD_COMP(StudyDescription,"A0008_1030"); //=================================================================== //=================================================================== // Series comparators ///Compares the modality of the series STRING_FIELD_COMP(Modality,"A0008_0060"); ///Compares the description of the series STRING_FIELD_COMP(SeriesDescription,"A0008_103E"); ///Compares the date of the series STRING_FIELD_COMP(SeriesDate,"A0008_0021"); //=================================================================== //=================================================================== // Image comparators ///Compares the number of the images INT_FIELD_COMP(ImageNumber,"A0020_0013"); ///Compares the location of the images FLOAT_FIELD_COMP(SliceLocation,"A0020_1041"); ///Compares the filename of the images STRING_FIELD_COMP(FullFileName,"FullFileName"); //=================================================================== } // namespace tree } // namespace creaImageIO #endif // #ifndef __creaImageIOComparators_h_INCLUDED__