summary refs log tree commit diff stats
path: root/src/util.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-17 15:55:37 -0400
committerGitHub <noreply@github.com>2018-05-17 15:55:37 -0400
commit90aadf3844386824140a20d7fbb847bc16009a94 (patch)
tree6f83fce90e71abb22b1a8f3e09c79963b2a34d5d /src/util.h
parentbc63fa57ced1c7329f7fdcfd168eaf7e290158bc (diff)
parent86f0106d0523825549f1e74b835688c78a10cf6c (diff)
downloadtherapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.gz
therapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.bz2
therapy-90aadf3844386824140a20d7fbb847bc16009a94.zip
Merge pull request #7 from hatkirby/es-rewrite
The ECS rewrite exceeds the original branch in functionality, so it is time to merge it in.
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..72cb0d3 --- /dev/null +++ b/src/util.h
@@ -0,0 +1,41 @@
1#ifndef ALGORITHMS_H_1DDC517E
2#define ALGORITHMS_H_1DDC517E
3
4#include <fstream>
5#include <sstream>
6#include <cstring>
7
8template< typename ContainerT, typename PredicateT >
9void erase_if( ContainerT& items, const PredicateT& predicate ) {
10 for( auto it = items.begin(); it != items.end(); ) {
11 if( predicate(*it) ) it = items.erase(it);
12 else ++it;
13 }
14};
15
16struct chlit
17{
18 chlit(char c) : c_(c) { }
19 char c_;
20};
21
22inline std::istream& operator>>(std::istream& is, chlit x)
23{
24 char c;
25 if (is >> c && c != x.c_)
26 {
27 is.setstate(std::iostream::failbit);
28 }
29
30 return is;
31}
32
33std::string slurp(std::ifstream& in);
34
35void flipImageData(
36 unsigned char* data,
37 int width,
38 int height,
39 int comps);
40
41#endif /* end of include guard: ALGORITHMS_H_1DDC517E */