GCC Code Coverage Report


Directory: src/gate/
File: src/gate/encode/cxx_csv.cpp
Date: 2026-12-03 19:36:00
Exec Total Coverage
Lines: 51 53 96.2%
Functions: 11 11 100.0%
Branches: 19 38 50.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/encode/csv.hpp"
30 #include "gate/exceptions.hpp"
31
32 namespace gate
33 {
34 namespace enc
35 {
36
37 2 CsvReader::CsvReader(Stream stream, char csvSeparator, char csvQuote)
38 {
39 2 const result_t result = gate_csv_reader_create(&this->impl, stream.c_impl(), csvSeparator, csvQuote);
40
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_ERROR(result);
41 2 }
42 4 CsvReader::~CsvReader() noexcept
43 {
44 2 gate_csv_reader_destroy(&this->impl);
45 2 }
46
47 11 VoidResult CsvReader::tryReadNext(String& field, bool_t& recordCompleted)
48 {
49 11 gate_string_t str_field = GATE_STRING_INIT_EMPTY;
50
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
11 const result_t result = gate_csv_reader_get_next(&this->impl, &str_field, &this->lineRecordCompleted);
51 11 recordCompleted = this->lineRecordCompleted;
52 11 field = String::createFrom(str_field);
53
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
22 return makeResult(result);
54 }
55
56 11 bool_t CsvReader::readNext(String& field, bool_t& recordCompleted)
57 {
58
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
22 VoidResult result = this->tryReadNext(field, recordCompleted);
59
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10 times.
11 if (result.hasError())
60 {
61
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (result.error() != results::EndOfStream)
62 {
63 ✗ result.checkException("CsvReader::readNext");
64 }
65 1 return false;
66 }
67 10 return true;
68 }
69
70 2 bool_t CsvReader::readRecord(ArrayList<String>& fields)
71 {
72 2 unsigned counter = 0;
73
74 2 bool_t lineRecordCompleted = false;
75
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
7 while (!lineRecordCompleted)
76 {
77 5 String field;
78
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 bool_t fieldReceived = this->readNext(field, lineRecordCompleted);
79
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!fieldReceived)
80 {
81 ✗ break;
82 }
83
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 fields.add(field);
84 5 ++counter;
85 }
86 2 return counter > 0;
87 }
88
89
90 1 CsvWriter::CsvWriter(Stream destStream, char csvSeparator, char csvQuote)
91 {
92 1 result_t result = gate_csv_writer_create(&this->impl, destStream.c_impl(), csvSeparator, csvQuote);
93
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
94 1 }
95
96 2 CsvWriter::~CsvWriter() noexcept
97 {
98 1 gate_csv_writer_destroy(&this->impl);
99 1 }
100
101 5 VoidResult CsvWriter::tryWriteNext(String const& field, bool_t recordCompleted)
102 {
103
1/2
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 const result_t result = gate_csv_writer_write_next(&this->impl, field.c_impl(), recordCompleted);
104
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
10 return makeResult(result);
105 }
106
107 5 void CsvWriter::writeNext(String const& field, bool_t recordCompleted)
108 {
109
1/2
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 this->tryWriteNext(field, recordCompleted).checkException("CsvWriter::writeNext");
110 5 }
111
112
113 1 PropTable CsvPropTable::load(Stream& inputStream, char csvSeparator, char csvQuote)
114 {
115 1 PropTable proptable;
116
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 const result_t result = gate_csv_proptable_load(inputStream.c_impl(), proptable.c_impl(), csvSeparator, csvQuote);
117
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
118 1 return proptable;
119
120 }
121 1 void CsvPropTable::store(PropTable const& src, Stream& outputStream, char csvSeparator, char csvQuote)
122 {
123 1 const result_t result = gate_csv_proptable_store(src.c_impl(), outputStream.c_impl(), csvSeparator, csvQuote);
124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
125 1 }
126
127 } // end of namespace encode
128 } // end of namespace gate
129