librime 1.2
Rime Input Method Engine, the core library
tsv.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2013-04-16 GONG Chen <chen.sst@gmail.com>
6//
7#ifndef RIME_TSV_H_
8#define RIME_TSV_H_
9
10#include <rime/common.h>
11
12namespace rime {
13
14using Tsv = vector<string>;
15
16using TsvParser = function<bool(const Tsv& row, string* key, string* value)>;
17
19 function<bool(const string& key, const string& value, Tsv* row)>;
20
21class Sink;
22class Source;
23
24class TsvReader {
25 public:
26 TsvReader(const path& file_path, TsvParser parser)
27 : file_path_(file_path), parser_(parser) {}
28 // return number of records read
29 int operator()(Sink* sink);
30
31 protected:
34};
35
36class TsvWriter {
37 public:
38 TsvWriter(const path& file_path, TsvFormatter formatter)
39 : file_path_(file_path), formatter_(formatter) {}
40 // return number of records written
41 int operator()(Source* source);
42
43 protected:
46
47 public:
49};
50
51template <class SinkType>
52int operator<<(SinkType& sink, TsvReader& reader) {
53 return reader(&sink);
54}
55
56template <class SinkType>
57int operator>>(TsvReader& reader, SinkType& sink) {
58 return reader(&sink);
59}
60
61template <class SourceType>
62int operator<<(TsvWriter& writer, SourceType& source) {
63 return writer(&source);
64}
65
66template <class SourceType>
67int operator>>(SourceType& source, TsvWriter& writer) {
68 return writer(&source);
69}
70
71} // namespace rime
72
73#endif // RIME_TSV_H_
Definition algebra.cc:12
vector< string > Tsv
Definition tsv.h:14
std::ostream & operator<<(std::ostream &stream, const Reference &reference)
Definition config_compiler.cc:12
function< bool(const string &key, const string &value, Tsv *row)> TsvFormatter
Definition tsv.h:18
int operator>>(TsvReader &reader, SinkType &sink)
Definition tsv.h:57
function< bool(const Tsv &row, string *key, string *value)> TsvParser
Definition tsv.h:16
Definition common.h:84
Definition db_utils.h:14
Definition db_utils.h:24
Definition tsv.h:24
TsvParser parser_
Definition tsv.h:33
TsvReader(const path &file_path, TsvParser parser)
Definition tsv.h:26
path file_path_
Definition tsv.h:32
int operator()(Sink *sink)
Definition tsv.cc:15
Definition tsv.h:36
TsvWriter(const path &file_path, TsvFormatter formatter)
Definition tsv.h:38
path file_path_
Definition tsv.h:44
TsvFormatter formatter_
Definition tsv.h:45
string file_description
Definition tsv.h:48
int operator()(Source *source)
Definition tsv.cc:59