Home | History | Annotate | Download | only in GLcommon
      1 /*
      2 * Copyright (C) 2011 The Android Open Source Project
      3 *
      4 * Licensed under the Apache License, Version 2.0 (the "License");
      5 * you may not use this file except in compliance with the License.
      6 * You may obtain a copy of the License at
      7 *
      8 * http://www.apache.org/licenses/LICENSE-2.0
      9 *
     10 * Unless required by applicable law or agreed to in writing, software
     11 * distributed under the License is distributed on an "AS IS" BASIS,
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 * See the License for the specific language governing permissions and
     14 * limitations under the License.
     15 */
     16 #ifndef RANGE_H
     17 #define RANGE_H
     18 
     19 #include <vector>
     20 
     21 class Range {
     22 
     23 public:
     24     Range():m_start(0),m_end(0),m_size(0){};
     25     Range(int start,int size):m_start(start),m_end(start+size),m_size(size){};
     26     Range(const Range& r):m_start(r.m_start),m_end(r.m_end),m_size(r.m_size){};
     27     void setRange(int start,int size){m_start = start; m_end = start+size; m_size = size;};
     28     inline int getStart() const{return m_start;};
     29     inline int getEnd() const{return m_end;};
     30     inline int getSize() const{return m_size;};
     31     Range& operator=(const Range& r) {
     32         m_start = r.m_start;
     33         m_end = r.m_end;
     34         m_size = r.m_size;
     35         return *this;
     36     }
     37     bool operator ==(const Range& r) const {
     38         return m_start == r.m_start && m_size == r.m_size && m_end == r.m_end;
     39     }
     40     bool operator !=(const Range& r) const {return !((*this) == r);};
     41     bool rangeIntersection(const Range& r,Range& rOut) const ;
     42     bool rangeUnion(const Range& r,Range& rOut) const ;
     43 
     44 private:
     45     int m_start;
     46     int m_end;
     47     int m_size;
     48 };
     49 
     50 class RangeList {
     51 public:
     52       void addRange(const Range& r);
     53       void addRanges(const RangeList& rl);
     54       void delRange(const Range& r,RangeList& deleted);
     55       void delRanges(const RangeList& rl,RangeList& deleted);
     56       bool empty() const;
     57       void merge();
     58       int  size() const;
     59       void clear();
     60       Range& operator[](unsigned int i){return list[i];};
     61 private:
     62   void erase(unsigned int i);
     63   std::vector<Range> list;
     64 };
     65 
     66 
     67 
     68 
     69 #endif
     70