File: Settings.hpp

package info (click to toggle)
reflect-cpp 0.21.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,128 kB
  • sloc: cpp: 50,336; python: 139; makefile: 30; sh: 3
file content (97 lines) | stat: -rw-r--r-- 2,930 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef RFL_CSV_SETTINGS_HPP_
#define RFL_CSV_SETTINGS_HPP_

#include <arrow/csv/api.h>
#include <arrow/io/api.h>

#include "../Field.hpp"
#include "../replace.hpp"

namespace rfl::csv {

struct Settings {
  /// Maximum number of rows processed at a time.
  /// Data is processed in batches of N rows. This number
  /// can impact performance.
  int32_t batch_size = 1024;

  /// Field delimiter.
  char delimiter = ',';

  /// Whether quoting is used.
  bool quoting = true;

  /// Quoting character (if quoting is true). Only relevant for reading.
  char quote_char = '"';

  /// The string to be used for null values. Quotes are not allowed in this
  /// string.
  std::string null_string = "n/a";

  /// Whether a quote inside a value is double-quoted. Only relevant for
  /// reading.
  bool double_quote = true;

  /// Whether escaping is used. Only relevant for reading.
  bool escaping = false;

  /// Escaping character (if escaping is true). Only relevant for reading.
  char escape_char = arrow::csv::kDefaultEscapeChar;

  /// Whether values are allowed to contain CR (0x0d) and LF (0x0a)
  /// characters. Only relevant for reading.
  bool newlines_in_values = false;

  /// Whether empty lines are ignored.
  /// If false, an empty line represents a single empty value (assuming a
  /// one-column CSV file). Only relevant for reading.
  bool ignore_empty_lines = true;

  Settings with_batch_size(const int32_t _batch_size) const noexcept {
    return replace(*this, make_field<"batch_size">(_batch_size));
  }

  Settings with_delimiter(const char _delimiter) const noexcept {
    return replace(*this, make_field<"delimiter">(_delimiter));
  }

  Settings with_quoting(const bool _quoting) const noexcept {
    return replace(*this, make_field<"quoting">(_quoting));
  }

  Settings with_quote_char(const char _quote_char) const noexcept {
    return replace(*this, make_field<"quote_char">(_quote_char));
  }

  Settings with_null_string(const std::string& _null_string) const noexcept {
    return replace(*this, make_field<"null_string">(_null_string));
  }

  Settings with_double_quote(const bool _double_quote) const noexcept {
    return replace(*this, make_field<"double_quote">(_double_quote));
  }

  Settings with_escaping(const bool _escaping) const noexcept {
    return replace(*this, make_field<"escaping">(_escaping));
  }

  Settings with_escape_char(const char _escape_char) const noexcept {
    return replace(*this, make_field<"escape_char">(_escape_char));
  }

  Settings with_newlines_in_values(
      const bool _newlines_in_values) const noexcept {
    return replace(*this,
                   make_field<"newlines_in_values">(_newlines_in_values));
  }

  Settings with_ignore_empty_lines(
      const bool _ignore_empty_lines) const noexcept {
    return replace(*this,
                   make_field<"ignore_empty_lines">(_ignore_empty_lines));
  }
};

}  // namespace rfl::csv

#endif