summary refs log tree commit diff stats
path: root/src/util.h
blob: 72cb0d308b9062308f095f170f9b4d7c36bc5a9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef ALGORITHMS_H_1DDC517E
#define ALGORITHMS_H_1DDC517E

#include <fstream>
#include <sstream>
#include <cstring>

template< typename ContainerT, typename PredicateT >
void erase_if( ContainerT& items, const PredicateT& predicate ) {
  for( auto it = items.begin(); it != items.end(); ) {
    if( predicate(*it) ) it = items.erase(it);
    else ++it;
  }
};

struct chlit
{
  chlit(char c) : c_(c) { }
  char c_;
};

inline std::istream& operator>>(std::istream& is, chlit x)
{
  char c;
  if (is >> c && c != x.c_)
  {
    is.setstate(std::iostream::failbit);
  }

  return is;
}

std::string slurp(std::ifstream& in);

void flipImageData(
  unsigned char* data,
  int width,
  int height,
  int comps);

#endif /* end of include guard: ALGORITHMS_H_1DDC517E */