60 lines
1.1 KiB
C++
60 lines
1.1 KiB
C++
#pragma once
|
|
|
|
extern "C" {
|
|
# include <liblocky.h>
|
|
}
|
|
|
|
#include <cctype>
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
#include <tuple>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
|
|
namespace blky {
|
|
|
|
enum DataFlow {
|
|
kBytes,
|
|
kFeatures,
|
|
kFeatureProbs,
|
|
kVideo,
|
|
};
|
|
|
|
static inline const std::string kDataFlowList = "bytes/features/video";
|
|
static inline const std::unordered_map<std::string, DataFlow> kDataFlowMap = {
|
|
{"bytes", kBytes},
|
|
{"features", kFeatures},
|
|
{"feature-probs", kFeatureProbs},
|
|
{"video", kVideo},
|
|
};
|
|
|
|
|
|
template <typename T>
|
|
std::vector<T> ReadAll(auto& ist) noexcept {
|
|
std::vector<T> ret;
|
|
for (;;) {
|
|
T v;
|
|
ist >> v;
|
|
if (ist.eof()) return ret;
|
|
ret.push_back(v);
|
|
}
|
|
}
|
|
|
|
static uint8_t ToHex(char c) {
|
|
if (!std::isxdigit(c)) throw std::runtime_error {"not xdigit"};
|
|
return static_cast<uint8_t>(std::isalpha(c)? std::tolower(c)-'a'+0xA: c-'0');
|
|
}
|
|
|
|
} // namespace blky
|
|
|
|
|
|
namespace args {
|
|
|
|
auto& operator>>(auto& ist, std::tuple<uint32_t, uint32_t>& v) {
|
|
ist >> std::get<0>(v) >> std::get<1>(v);
|
|
return ist;
|
|
}
|
|
|
|
} // namespace args
|