I am trying to wrap istreamusing boost progress_displayusing boost::iterator_adaptor. What I wrote
class ifstreamWithProgress: public boost::iterator_adaptor <
ifstreamWithProgress,
char*,
boost::use_default,
boost::forward_traversal_tag > {
public:
ifstreamWithProgress(): iter(std::istream_iterator<char>()), pd(0)
{}
ifstreamWithProgress(const std::string& fname_): fname(fname_), fsize(0), pd(fsize) {
std::ifstream file(fname.c_str(), std::ios::binary);
fsize = file.tellg();
file.seekg(0, std::ios::end);
fsize = file.tellg() - fsize;
file.seekg(0, std::ios::beg);
iter = std::istream_iterator<char>(file);
pd.restart(fsize);
}
~ifstreamWithProgress() {
while( ++pd < fsize);
}
const std::istream_iterator<char> getRawIstream() const {
return iter;
}
private:
std::string fname;
friend class boost::iterator_core_access;
std::istream_iterator<char> iter;
std::streampos fsize;
progress_display pd;
void increments() {
iter++;
++pd;
}
bool equal(const ifstreamWithProgress& rhs) const {
return this->iter == rhs.getRawIstream();
}
};
It compiles. However, when I started doing something like
ifstreamWithProgress is("data.txt");
ifstreamWithProgress eos;
is != eos;
I get a compile-time error saying that it is not being copied. This makes sense because the mapping class is derived from boost::noncopyable. However, I do not understand where the copying takes place. Any pointers?
PS: error message
1>c:\users\leon.sit\documents\myprojects\c++\general_models\phoenixdsm\phx\fileProgressBarWrapper.hpp(58) : error C2248: 'boost::noncopyable_::noncopyable::noncopyable' : cannot access private member declared in class 'boost::noncopyable_::noncopyable'
1> C:\Program Files\boost\boost_1_44\boost/noncopyable.hpp(27) : see declaration of 'boost::noncopyable_::noncopyable::noncopyable'
1> C:\Program Files\boost\boost_1_44\boost/noncopyable.hpp(22) : see declaration of 'boost::noncopyable_::noncopyable'
1> This diagnostic occurred in the compiler generated function 'ifstreamWithProgress::ifstreamWithProgress(const ifstreamWithProgress &)'
which does not indicate anywhere in the source. However, it compiles after commenting out the comparison string.
source
share