| 1 |
#include <pbcopper/data/MovieName.h> |
| 2 |
|
| 3 |
#include <cstddef> |
| 4 |
|
| 5 |
namespace PacBio { |
| 6 |
namespace Data { |
| 7 |
|
| 8 |
MovieName::MovieName(const std::string& instrumentName, const std::string& runStartTime) |
| 9 |
: partsCache_(nullptr) |
| 10 |
{ |
| 11 |
// construct name from parts |
| 12 |
std::string result; |
| 13 |
result.reserve(128); |
| 14 |
result += "m"; |
| 15 |
result += instrumentName; |
| 16 |
result += "_"; |
| 17 |
result += runStartTime; |
| 18 |
movieName_ = result; |
| 19 |
// don't update cache until actually requested |
| 20 |
} |
| 21 |
|
| 22 |
void MovieName::UpdatePartsCache() const |
| 23 |
{ |
| 24 |
// sanity checks |
| 25 |
assert(partsCache_ == nullptr); |
| 26 |
if (movieName_.empty()) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
// calculate name parts |
| 31 |
const char underscore = '_'; |
| 32 |
const size_t firstUnderscore = movieName_.find(underscore); |
| 33 |
|
| 34 |
const char* movieCStr = movieName_.c_str(); |
| 35 |
const char* nameStart = movieCStr + 1; |
| 36 |
const char* rstStart = movieCStr + firstUnderscore + 1; // skip '_' |
| 37 |
const size_t nameSize = (firstUnderscore - 1); |
| 38 |
const size_t rstSize = (movieName_.size() - firstUnderscore) - 1; // skip '\0 ' |
| 39 |
|
| 40 |
// cache name parts |
| 41 |
partsCache_.reset(new PartsCache{ |
| 42 |
std::string_view{nameStart, nameSize}, // instrumentName |
| 43 |
std::string_view{rstStart, rstSize} // runStartTime |
| 44 |
}); |
| 45 |
|
| 46 |
// checks - here? or elsewhere? |
| 47 |
if (partsCache_->instrumentName_.empty()) { |
| 48 |
throw std::runtime_error("[pbcopper] movie name ERROR: instrument name must not be empty"); |
| 49 |
} |
| 50 |
if (partsCache_->runStartTime_.empty()) { |
| 51 |
throw std::runtime_error("[pbcopper] movie name ERROR: run start time must not be empty"); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
} // namespace Data |
| 56 |
} // namespace PacBio |