]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/bcp/fileview.cpp
3 * Copyright (c) 2003 Dr John Maddock
4 * Use, modification and distribution is subject to the
5 * Boost Software License, Version 1.0. (See accompanying file
6 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 * This file implements the fileview class
11 #include "fileview.hpp"
12 #include <boost/filesystem/fstream.hpp>
20 struct fileview::implementation
22 std::vector
<char> m_data
;
29 pimpl
.reset(new implementation());
32 fileview::fileview(const boost::filesystem::path
& p
)
34 pimpl
.reset(new implementation());
42 fileview::fileview(const fileview
& )
46 fileview
& fileview::operator=(const fileview
& that
)
52 void fileview::close()
55 pimpl
->m_data
.clear();
58 void fileview::open(const boost::filesystem::path
& p
)
61 boost::filesystem::ifstream
is(p
);
64 std::string
msg("Bad file name: ");
66 std::runtime_error
e(msg
);
67 boost::throw_exception(e
);
69 std::istreambuf_iterator
<char> in(is
);
70 std::istreambuf_iterator
<char> end
;
71 std::copy(in
, end
, std::back_inserter(pimpl
->m_data
));
75 fileview::const_iterator
fileview::begin() const
77 return pimpl
->m_data
.size() ? &(pimpl
->m_data
[0]) : 0;
80 fileview::const_iterator
fileview::end() const
82 return begin() + pimpl
->m_data
.size();
85 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
86 fileview::const_reverse_iterator
fileview::rbegin() const
88 return const_reverse_iterator(end());
91 fileview::const_reverse_iterator
fileview::rend() const
93 return const_reverse_iterator(begin());
98 fileview::size_type
fileview::size() const
100 return pimpl
->m_data
.size();
103 fileview::size_type
fileview::max_size() const
105 return pimpl
->m_data
.max_size();
108 bool fileview::empty() const
110 return pimpl
->m_data
.empty();
114 fileview::const_reference
fileview::operator[](fileview::size_type n
) const
116 return pimpl
->m_data
[n
];
119 fileview::const_reference
fileview::at(size_type n
) const
121 return pimpl
->m_data
.at(n
);
124 fileview::const_reference
fileview::front() const
126 return pimpl
->m_data
.front();
129 fileview::const_reference
fileview::back() const
131 return pimpl
->m_data
.back();
134 void fileview::swap(fileview
& that
)
136 pimpl
.swap(that
.pimpl
);
142 pimpl
.reset(new implementation(*pimpl
));