Csv.cpp
Go to the documentation of this file.
1 #include "Csv.hpp"
2 
3 using namespace quori_controller;
4 
6  : csv_(csv)
7 {
8 }
9 
11 {
12  csv_.appendRow(elements_);
13 }
14 
15 Csv::Row &Csv::Row::operator<< (const std::string &value)
16 {
17  elements_.push_back(value);
18  return *this;
19 }
20 
21 Csv::Row &Csv::Row::operator<< (const char *const value)
22 {
23  elements_.push_back(value);
24  return *this;
25 }
26 
27 Csv::Csv(std::ostream &out)
28  : out_(out)
29 {
30 }
31 
33 {
34  out_.flush();
35  std::cerr << "Cleanup" << std::endl;
36 }
37 
38 Csv::Ptr Csv::open(std::ostream &out)
39 {
40  return Csv::Ptr(new Csv(out));
41 }
42 
44 {
45  return Row(*this);
46 }
47 
48 void Csv::appendRow(const std::vector<std::string> &elements)
49 {
50  std::lock_guard<std::mutex> lock(mut_);
51 
52  for (auto it = elements.begin(); it != elements.end(); ++it)
53  {
54  if (it != elements.begin()) out_ << ",";
55  out_ << *it;
56  }
57  out_ << std::endl;
58 }
quori_controller::Csv::Row::operator<<
Row & operator<<(const std::string &value)
Definition: Csv.cpp:15
Csv.hpp
quori_controller::Csv::Row::~Row
~Row()
Definition: Csv.cpp:10
quori_controller::Csv::appendRow
void appendRow(const std::vector< std::string > &elements)
Definition: Csv.cpp:48
quori_controller::Csv::out_
std::ostream & out_
Definition: Csv.hpp:50
quori_controller::Csv::append
Row append()
Definition: Csv.cpp:43
quori_controller::Csv::Row
friend struct Row
Definition: Csv.hpp:38
quori_controller::Csv::mut_
std::mutex mut_
Definition: Csv.hpp:51
quori_controller
Definition: Csv.hpp:10
quori_controller::Csv::Ptr
std::shared_ptr< Csv > Ptr
Definition: Csv.hpp:15
quori_controller::Csv::Row
Definition: Csv.hpp:18
quori_controller::Csv::open
static Ptr open(std::ostream &out)
Definition: Csv.cpp:38
quori_controller::Csv::Csv
Csv(std::ostream &out)
Definition: Csv.cpp:27
quori_controller::Csv::~Csv
~Csv()
Definition: Csv.cpp:32
quori_controller::Csv
Definition: Csv.hpp:12
quori_controller::Csv::Row::Row
Row(Csv &csv)
Definition: Csv.cpp:5


quori_controller
Author(s):
autogenerated on Wed Mar 2 2022 00:53:16