librime: tsv.h Source File

| 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
14 using Tsv = vector<string>;
15
16 using TsvParser = function<bool(const Tsv& row, string* key, string* value)>;
17
18 using TsvFormatter =
19 function<bool(const string& key, const string& value, Tsv* row)>;
20
21class Sink;
22class Source;
23
24 class 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:
32 path file_path_;
33 TsvParser parser_;
34};
35
36 class 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:
44 path file_path_;
45 TsvFormatter formatter_;
46
47 public:
48 string file_description;
49};
50
51template <class SinkType>
52 int operator<<(SinkType& sink, TsvReader& reader) {
53 return reader(&sink);
54}
55
56template <class SinkType>
57 int operator>>(TsvReader& reader, SinkType& sink) {
58 return reader(&sink);
59}
60
61template <class SourceType>
62 int operator<<(TsvWriter& writer, SourceType& source) {
63 return writer(&source);
64}
65
66template <class SourceType>
67 int operator>>(SourceType& source, TsvWriter& writer) {
68 return writer(&source);
69}
70
71} // namespace rime
72
73#endif // RIME_TSV_H_
common.h
rime
Definition algebra.cc:12
rime::Tsv
vector< string > Tsv
Definition tsv.h:14
rime::operator<<
std::ostream & operator<<(std::ostream &stream, const Reference &reference)
Definition config_compiler.cc:12
rime::TsvFormatter
function< bool(const string &key, const string &value, Tsv *row)> TsvFormatter
Definition tsv.h:18
rime::operator>>
int operator>>(TsvReader &reader, SinkType &sink)
Definition tsv.h:57
rime::TsvParser
function< bool(const Tsv &row, string *key, string *value)> TsvParser
Definition tsv.h:16
rime::path
Definition common.h:84
rime::Sink
Definition db_utils.h:14
rime::Source
Definition db_utils.h:24
rime::TsvReader
Definition tsv.h:24
rime::TsvReader::parser_
TsvParser parser_
Definition tsv.h:33
rime::TsvReader::TsvReader
TsvReader(const path &file_path, TsvParser parser)
Definition tsv.h:26
rime::TsvReader::file_path_
path file_path_
Definition tsv.h:32
rime::TsvReader::operator()
int operator()(Sink *sink)
Definition tsv.cc:15
rime::TsvWriter
Definition tsv.h:36
rime::TsvWriter::TsvWriter
TsvWriter(const path &file_path, TsvFormatter formatter)
Definition tsv.h:38
rime::TsvWriter::file_path_
path file_path_
Definition tsv.h:44
rime::TsvWriter::formatter_
TsvFormatter formatter_
Definition tsv.h:45
rime::TsvWriter::file_description
string file_description
Definition tsv.h:48
rime::TsvWriter::operator()
int operator()(Source *source)
Definition tsv.cc:59