Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reader to be instantiated without files #307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions stempy/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,21 @@ SectorStreamReader::SectorStreamReader(const vector<string>& files,
m_streamsIterator = m_streams.begin();
}

SectorStreamReader::SectorStreamReader(uint8_t version) : m_version(version)
{
// Validate version
switch (m_version) {
case 4:
case 5:
break;
default:
std::ostringstream ss;
ss << "Unsupported version: ";
ss << m_version;
throw invalid_argument(ss.str());
}
}

SectorStreamReader::~SectorStreamReader()
{
m_streams.clear();
Expand Down Expand Up @@ -781,6 +796,13 @@ SectorStreamThreadedReader::SectorStreamThreadedReader(
initNumberOfThreads();
}

SectorStreamThreadedReader::SectorStreamThreadedReader(uint8_t version,
int threads)
: SectorStreamReader(version), m_threads(threads)
{
initNumberOfThreads();
}

void SectorStreamThreadedReader::initNumberOfThreads()
{
if (m_threads < 1) {
Expand Down
4 changes: 3 additions & 1 deletion stempy/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class SectorStreamReader
SectorStreamReader(const std::string& path, uint8_t version = 5);
SectorStreamReader(const std::vector<std::string>& files,
uint8_t version = 5);
SectorStreamReader(uint8_t version = 5);
~SectorStreamReader();

Block read();
Expand Down Expand Up @@ -334,6 +335,7 @@ class SectorStreamThreadedReader : public SectorStreamReader
int threads = 0);
SectorStreamThreadedReader(const std::vector<std::string>& files,
uint8_t version = 5, int threads = 0);
SectorStreamThreadedReader(uint8_t version = 5, int threads = 0);

template <typename Functor>
std::future<void> readAll(Functor& f);
Expand All @@ -348,7 +350,7 @@ class SectorStreamThreadedReader : public SectorStreamReader
// The futures associated with the worker threads
std::vector<std::future<void>> m_futures;

private:
protected:
// Protect access to frame cache
std::mutex m_cacheMutex;

Expand Down
Loading