~ubuntu-branches/ubuntu/saucy/abyss/saucy

« back to all changes in this revision

Viewing changes to Common/IOUtil.h

  • Committer: Package Import Robot
  • Author(s): Shaun Jackman
  • Date: 2011-09-11 10:00:13 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110911100013-oa4m5fi036mjuwc8
Tags: 1.3.0-1
* New upstream release.
* Add libboost-graph-dev to Build-Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#ifndef IOUTIL_H
2
2
#define IOUTIL_H 1
3
3
 
 
4
#include <cassert>
4
5
#include <cerrno>
5
6
#include <cstdlib>
6
7
#include <cstring> // for strerror
 
8
#include <fstream>
7
9
#include <iostream>
8
10
#include <limits> // for numeric_limits
9
11
#include <string>
13
15
                const std::string& path)
14
16
{
15
17
        if (!stream.good()) {
16
 
                std::cerr << path << ": " << strerror(errno) << std::endl;
 
18
                std::cerr << "error: `" << path << "': "
 
19
                        << strerror(errno) << std::endl;
17
20
                exit(EXIT_FAILURE);
18
21
        }
19
22
}
62
65
        return in.ignore(o.n, o.delim);
63
66
}
64
67
 
 
68
/** Read a file and store it in the specified vector. */
 
69
template <typename Vector>
 
70
static inline void readFile(const char* path, Vector& s)
 
71
{
 
72
        std::ifstream in(path);
 
73
        assert_good(in, path);
 
74
        in.seekg(0, std::ios::end);
 
75
        s.resize(in.tellg());
 
76
        in.seekg(0, std::ios::beg);
 
77
        assert_good(in, path);
 
78
        in.read((char*)s.data(), s.size());
 
79
        assert_good(in, path);
 
80
        assert((size_t)in.gcount() == s.size());
 
81
}
 
82
 
65
83
#endif