| 45 | } |
| 46 | |
| 47 | void CsvWriter::Convert(ChannelObserverList& observer_list) { |
| 48 | std::vector<const IChannelObserver*> obs_list; |
| 49 | |
| 50 | // Add master channel(s) first in the list |
| 51 | for (const auto& itr : observer_list) { |
| 52 | const IChannelObserver* obs = itr.get(); |
| 53 | if (obs == nullptr) { |
| 54 | continue; |
| 55 | } |
| 56 | if (obs->IsMaster()) { |
| 57 | obs_list.emplace_back(obs); |
| 58 | // Should be a break here as it should only exist one master |
| 59 | // but some files has marked more channels as master as it |
| 60 | // may exist in a real application. |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Append non-master channels to the list |
| 65 | for (const auto& itr : observer_list) { |
| 66 | const IChannelObserver* obs = itr.get(); |
| 67 | if (obs == nullptr) { |
| 68 | continue; |
| 69 | } |
| 70 | if (!obs->IsMaster()) { |
| 71 | obs_list.emplace_back(obs); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | if (obs_list.empty()) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | size_t nof_samples = observer_list[0]->NofSamples(); |
| 80 | if (nof_samples == 0) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | try { |
| 85 | file_.open(temp_filename_, std::ios::out | std::ios::trunc); |
| 86 | // HEADER LINE |
| 87 | size_t count = 0; |
| 88 | for (const auto* header : obs_list) { |
| 89 | const IChannel& channel = header->Channel(); |
| 90 | const auto unit = channel.Unit(); |
| 91 | if (count > 0) { |
| 92 | file_ << delimiter_; |
| 93 | } |
| 94 | file_ << "\"" << channel.Name(); |
| 95 | if (!unit.empty()) { |
| 96 | file_ << " [" << unit << "]"; |
| 97 | } |
| 98 | file_ << "\""; |
| 99 | ++count; |
| 100 | } |
| 101 | file_ << std::endl; |
| 102 | |
| 103 | // ROW LINE |
| 104 | for (size_t sample = 0; sample < nof_samples; ++sample) { |
no test coverage detected