2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "benchmark/CsvWriter.h"
23 const std::vector<std::string> csv_header{
24 #include "benchmark/CsvHeader.lst"
32 CsvWriter::CsvWriter(const std::string &csv_filename) : CsvWriter(csv_filename, csv_header)
37 CsvWriter::CsvWriter(const std::string &csv_filename, const std::vector<std::string> &header)
38 : _ofs(csv_filename), _header_size(header.size()), _col_idx(0), _row_idx(0)
40 assert(csv_filename.empty() == false);
41 assert(header.size() != 0);
42 assert(_ofs.is_open());
47 CsvWriter::~CsvWriter()
53 void CsvWriter::writeHeader(const std::vector<std::string> &header)
55 for (const auto &col : header)
59 void CsvWriter::postWrite()
61 if (++_col_idx == _header_size)
73 void CsvWriter::write(const std::string &val)
79 void CsvWriter::write(double val)
85 void CsvWriter::write(uint32_t val)
91 void CsvWriter::write(char val)
97 bool CsvWriter::done() { return (_col_idx == 0) && (_row_idx == 2); }
99 CsvWriter &operator<<(CsvWriter &csvw, const std::string &val)
105 CsvWriter &operator<<(CsvWriter &csvw, double val)
111 CsvWriter &operator<<(CsvWriter &csvw, uint32_t val)
117 CsvWriter &operator<<(CsvWriter &csvw, char val)
123 } // namespace benchmark