-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_iterator.hpp
More file actions
48 lines (41 loc) · 1.16 KB
/
insert_iterator.hpp
File metadata and controls
48 lines (41 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Andrew Naplavkov
#ifndef BRIG_INSERT_ITERATOR_HPP
#define BRIG_INSERT_ITERATOR_HPP
#include <brig/inserter.hpp>
#include <brig/variant.hpp>
#include <iterator>
#include <memory>
#include <vector>
namespace brig {
class insert_iterator : public std::iterator<std::output_iterator_tag, void, void, void, void> {
std::shared_ptr<inserter> m_ins;
size_t m_flush_size, m_unflushed;
bool m_ok;
public:
explicit insert_iterator(std::shared_ptr<inserter> ins, size_t flush_size = 0)
: m_ins(ins), m_flush_size(flush_size), m_unflushed(0), m_ok(true)
{}
~insert_iterator()
{ if (m_ok) m_ins->flush(); }
insert_iterator& operator *()
{ return *this; }
insert_iterator& operator ++()
{ return *this; }
insert_iterator operator ++(int)
{ return *this; }
insert_iterator& operator =(std::vector<variant>& row)
{
m_ok = false;
m_ins->insert(row);
++m_unflushed;
if (m_unflushed == m_flush_size)
{
m_ins->flush();
m_unflushed = 0;
}
m_ok = true;
return *this;
}
}; // insert_iterator
} // brig
#endif // BRIG_INSERT_ITERATOR_HPP