11#include " fst_wave_data.h"
2+ #include " absl/status/status.h"
23#include " external/fst/fstapi.h"
34#include < stack>
4- #include < stdexcept>
55
66namespace sv {
77namespace {
@@ -24,15 +24,19 @@ std::string ParseSignalLsb(const std::string &s, int *lsb) {
2424
2525} // namespace
2626
27- FstWaveData::FstWaveData (const std::string &file_name, bool keep_glitches)
28- : WaveData(file_name, keep_glitches) {
29- reader_ = fstReaderOpen (file_name.c_str ());
30- if (reader_ == nullptr ) {
31- throw std::runtime_error (" Unable to read wave file." );
32- }
33- ReadScopes ();
27+ absl::StatusOr<std::unique_ptr<FstWaveData>> FstWaveData::Create (const std::string &file_name,
28+ bool keep_glitches) {
29+ void *reader = fstReaderOpen (file_name.c_str ());
30+ if (reader == nullptr ) return absl::InternalError (" Error opening wave file." );
31+ std::unique_ptr<FstWaveData> waves (new FstWaveData (file_name, keep_glitches));
32+ waves->reader_ = reader;
33+ waves->ReadScopes ();
34+ return waves;
3435}
3536
37+ FstWaveData::FstWaveData (const std::string &file_name, bool keep_glitches)
38+ : WaveData(file_name, keep_glitches) {}
39+
3640FstWaveData::~FstWaveData () { fstReaderClose (reader_); }
3741
3842int FstWaveData::Log10TimeUnits () const { return fstReaderGetTimescale (reader_); }
@@ -180,16 +184,14 @@ void FstWaveData::LoadSignalSamples(const std::vector<const Signal *> &signals,
180184 }
181185}
182186
183- void FstWaveData::Reload () {
184- // First, re-create the reader.
187+ absl::Status FstWaveData::Reload () {
185188 fstReaderClose (reader_);
186- reader_ = fstReaderOpen (file_name_.c_str ());
187- if (reader_ == nullptr ) {
188- throw std::runtime_error (" Unable to read wave file." );
189- }
190189 waves_.clear ();
191190 roots_.clear ();
191+ reader_ = fstReaderOpen (file_name_.c_str ());
192+ if (reader_ == nullptr ) return absl::InternalError (" Unable to re-read wave file." );
192193 ReadScopes ();
194+ return absl::OkStatus ();
193195}
194196
195197} // namespace sv
0 commit comments