~ubuntu-branches/ubuntu/quantal/cups-filters/quantal-proposed

« back to all changes in this revision

Viewing changes to filter/pdftopdf/intervalset.cc

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2012-08-20 14:53:42 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20120820145342-bddzpwqv0klmt84d
Tags: 1.0.22-1
* New upstream release
   - pdftopdf filter replaced by new QPDF-based filter from Tobias
     Hoffmann's Google Summer of Code project. The former Poppler-based
     pdftopdf duplicated a lot of Poppler's code. The old filter is
     still in the package as pdftopdf.old with source code in
     filter/pdftopdf.old. It will be removed in a later release.
   - bannertopdf: Page duplication routine fixed.
   - bannertopdf: Fixed invalid output of a direct stream object.
   - Added most recent contributors to AUTHORS and COPYING files.
* debian/control: Added build dependency on libqpdf-dev.
* debian/copyright: Updated for the addition of the new pdftopdf filter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "intervalset.h"
 
2
#include <stdio.h>
 
3
#include <assert.h>
 
4
#include <limits>
 
5
#include <algorithm>
 
6
 
 
7
const key_t IntervalSet::npos=std::numeric_limits<key_t>::max();
 
8
 
 
9
void IntervalSet::clear() // {{{
 
10
{
 
11
  data.clear();
 
12
}
 
13
// }}}
 
14
 
 
15
void IntervalSet::add(key_t start,key_t end) // {{{
 
16
{
 
17
  if (start<end) {
 
18
    data.push_back(std::make_pair(start,end));
 
19
  }
 
20
}
 
21
// }}}
 
22
 
 
23
void IntervalSet::finish() // {{{
 
24
{
 
25
  std::sort(data.begin(),data.end());
 
26
 
 
27
  data_t::iterator it=data.begin(),end=data.end(),pos=it;
 
28
  while (1) {
 
29
    ++it;
 
30
    if (it==end) {
 
31
      ++pos;
 
32
      break;
 
33
    }
 
34
    if (pos->second>=it->first) {
 
35
      pos->second=it->second;
 
36
    } else {
 
37
      ++pos;
 
38
      if (pos!=it) {
 
39
        *pos=*it;
 
40
      }
 
41
    }
 
42
  }
 
43
 
 
44
  data.erase(pos,data.end());
 
45
}
 
46
// }}}
 
47
 
 
48
bool IntervalSet::contains(key_t val) const // {{{
 
49
{
 
50
  data_t::const_iterator it=std::upper_bound(data.begin(),data.end(),std::make_pair(val,npos));
 
51
  if (it==data.begin()) {
 
52
    return false;
 
53
  }
 
54
  --it;
 
55
  return (val<it->second);
 
56
}
 
57
// }}}
 
58
 
 
59
key_t IntervalSet::next(key_t val) const // {{{
 
60
{
 
61
  val++;
 
62
  data_t::const_iterator it=std::upper_bound(data.begin(),data.end(),std::make_pair(val,npos));
 
63
  if (it==data.begin()) {
 
64
    return it->first;
 
65
  }
 
66
  --it;
 
67
  if (val<it->second) {
 
68
    return val;
 
69
  }
 
70
  ++it;
 
71
  if (it==data.end()) {
 
72
    return npos;
 
73
  }
 
74
  return it->first;
 
75
}
 
76
// }}}
 
77
 
 
78
bool IntervalSet::intersect(const value_t &a,const value_t &b) const // {{{
 
79
{
 
80
  return ( (a.first>=b.first)&&(a.first<b.second) )||
 
81
         ( (b.first>=a.first)&&(b.first<a.second) );
 
82
}
 
83
// }}}
 
84
 
 
85
void IntervalSet::unite(value_t &aret,const value_t &b) const // {{{
 
86
{
 
87
  assert(intersect(aret,b));
 
88
  if (b.first<aret.first) {
 
89
    aret.first=b.first;
 
90
  }
 
91
  if (b.second>aret.second) {
 
92
    aret.second=b.second;
 
93
  }
 
94
}
 
95
// }}}
 
96
 
 
97
void IntervalSet::dump() const // {{{
 
98
{
 
99
  int len=data.size();
 
100
  if (len==0) {
 
101
    fprintf(stderr,"(empty)\n");
 
102
    return;
 
103
  }
 
104
  len--;
 
105
  for (int iA=0;iA<len;iA++) {
 
106
    fprintf(stderr,"[%d,%d),",data[iA].first,data[iA].second);
 
107
  }
 
108
  if (data[len].second==npos) {
 
109
    fprintf(stderr,"[%d,inf)\n",data[len].first);
 
110
  } else {
 
111
    fprintf(stderr,"[%d,%d)\n",data[len].first,data[len].second);
 
112
  }
 
113
}
 
114
// }}}
 
115