Home | History | Annotate | Download | only in testing
      1 // Copyright 2017 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef TESTING_RANGE_SET_H_
      6 #define TESTING_RANGE_SET_H_
      7 
      8 #include <stddef.h>
      9 
     10 #include <set>
     11 #include <utility>
     12 
     13 class RangeSet {
     14  public:
     15   using Range = std::pair<size_t, size_t>;
     16 
     17   RangeSet();
     18   ~RangeSet();
     19 
     20   bool Contains(const Range& range) const;
     21 
     22   void Union(const Range& range);
     23 
     24   void Union(const RangeSet& range_set);
     25 
     26   bool IsEmpty() const { return ranges().empty(); }
     27 
     28   void Clear() { ranges_.clear(); }
     29 
     30   struct range_compare {
     31     bool operator()(const Range& lval, const Range& rval) const {
     32       return lval.first < rval.first;
     33     }
     34   };
     35 
     36   using RangesContainer = std::set<Range, range_compare>;
     37   const RangesContainer& ranges() const { return ranges_; }
     38 
     39  private:
     40   Range FixDirection(const Range& range) const;
     41 
     42   bool IsEmptyRange(const Range& range) const;
     43 
     44   RangesContainer ranges_;
     45 };
     46 
     47 #endif  // TESTING_RANGE_SET_H_
     48