1 #ifndef ROSE_BinaryAnalysis_Concolic_io_utility_H
2 #define ROSE_BinaryAnalysis_Concolic_io_utility_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_CONCOLIC_TESTING
5 #include <Rose/BinaryAnalysis/Concolic.h>
15 namespace BinaryAnalysis {
25 template <
class Container>
27 loadFile(
const std::string& filename, std::ios_base::openmode mode = std::ios_base::in)
29 typedef std::istreambuf_iterator<char> stream_iterator;
31 std::ifstream stream(filename.c_str(), mode);
34 throw std::runtime_error(
"Unable to open " + filename +
".");
39 std::copy(stream_iterator(stream), stream_iterator(), std::back_inserter(res));
48 template <
class T,
class CharT =
char,
class Traits = std::
char_traits<CharT> >
49 struct OStreamBinaryIterator : std::iterator<std::output_iterator_tag, void, void, void, void>
51 typedef std::basic_ostream<CharT, Traits> ostream_type;
52 typedef Traits traits_type;
53 typedef CharT char_type;
57 OStreamBinaryIterator(ostream_type& s) : stream(s) { }
60 OStreamBinaryIterator& operator=(
const T& value)
62 stream.write(reinterpret_cast<const char*>(&value),
sizeof(T));
69 OStreamBinaryIterator& operator*() {
return *
this; }
70 OStreamBinaryIterator& operator++() {
return *
this; }
71 OStreamBinaryIterator& operator++(
int) {
return *
this; }
77 OStreamBinaryIterator();
78 OStreamBinaryIterator& operator=(
const OStreamBinaryIterator&);
90 typedef OStreamBinaryIterator<T> insert_iterator;
94 FileSink(std::ostream& stream)
99 void reserve(
size_t) {}
105 return insert_iterator(datastream);
109 std::ostream& datastream;
121 template <
class Container>
123 storeFile(
const Container& data,
const std::string& filename, std::ios_base::openmode mode = std::ios_base::out)
125 std::ofstream stream(filename.c_str(), mode);
128 throw std::runtime_error(
"Unable to open " + filename +
".");
130 FileSink<char> sink(stream);
132 sink.reserve(data.size());
133 std::copy(data.begin(), data.end(), sink.inserter());
145 loadTextFile(
const boost::filesystem::path& path)
147 return loadFile<std::string>(path.string());
157 storeTextFile(
const std::string& data,
const boost::filesystem::path& path)
159 storeFile(data, path.string());
169 loadBinaryFile(
const boost::filesystem::path& path)
171 return loadFile<std::vector<uint8_t> >(path.string(), std::ios::in | std::ios::binary);
180 storeBinaryFile(
const std::vector<uint8_t>& data,
const boost::filesystem::path& path)
182 storeFile(data, path.string(), std::ofstream::binary);
Main namespace for the ROSE library.