finished initial istream split iterator
This commit is contained in:
parent
c138752ecc
commit
b6e43f1a98
1 changed files with 23 additions and 5 deletions
|
@ -72,19 +72,37 @@ namespace pit{
|
|||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Allocator could be generic on just * with + and += using a stack buf and the istream getline method but lazy
|
||||
template<class CharT, class Traits = std::char_traits<CharT>, class Allocator = std::allocator<CharT>>
|
||||
class basic_stream_split {
|
||||
bool ended;
|
||||
std::basic_istream<CharT, Traits> stream;
|
||||
|
||||
std::basic_istream<CharT, Traits>& stream;
|
||||
CharT delim;
|
||||
public:
|
||||
// there's no reason to specify the ending argument unless you want to manually construct the .end state of this iterator
|
||||
basic_stream_split(std::basic_istream<CharT, Traits>& stream, CharT delim, bool ending=false): stream(stream), ended(ending), delim(delim){}
|
||||
bool operator==(basic_stream_split const& rhs){
|
||||
return this->ended == rhs;
|
||||
}
|
||||
// todo: +,-, +=, -=, *
|
||||
std::basic_string<CharT, Traits, Allocator> operator*(){
|
||||
std::basic_string<CharT, Traits, Allocator> s;
|
||||
std::getline(this->stream, s, this->delim);
|
||||
return s;
|
||||
}
|
||||
// can't do -, or -= there's no reasonable way to undo istream reads
|
||||
// can't do + without storing a line
|
||||
void operator+=(std::size_t rhs){
|
||||
std::basic_string<CharT, Traits, Allocator> s;
|
||||
for(size_t i =0;i<rhs-1;i++)std::getline(this->stream, s, this->delim);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
using stream_split = basic_stream_split<char>;
|
||||
using wstream_split = basic_stream_split<wchar_t>;
|
||||
|
||||
template<class CharT, class Traits = std::char_traits<CharT>, class Allocator = std::allocator<CharT>>
|
||||
basic_stream_split<CharT,Traits, Allocator> split_stream(std::basic_istream<CharT, Traits>& stream){
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue