resource.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "resource.h"
  2. #include "resource.h"
  3. #include "registry.h"
  4. #include <util/generic/yexception.h>
  5. #include <util/generic/xrange.h>
  6. using namespace NResource;
  7. bool NResource::FindExact(const TStringBuf key, TString* out) {
  8. return CommonStore()->FindExact(key, out);
  9. }
  10. void NResource::FindMatch(const TStringBuf subkey, TResources* out) {
  11. struct TMatch: public IMatch {
  12. inline TMatch(TResources* r)
  13. : R(r)
  14. {
  15. }
  16. void OnMatch(const TResource& res) override {
  17. R->push_back(res);
  18. }
  19. TResources* R;
  20. };
  21. TMatch m(out);
  22. CommonStore()->FindMatch(subkey, m);
  23. }
  24. bool NResource::Has(const TStringBuf key) {
  25. return CommonStore()->Has(key);
  26. }
  27. TString NResource::Find(const TStringBuf key) {
  28. TString ret;
  29. if (FindExact(key, &ret)) {
  30. return ret;
  31. }
  32. ythrow yexception() << "can not find resource with path " << key;
  33. }
  34. size_t NResource::Count() noexcept {
  35. return CommonStore()->Count();
  36. }
  37. TStringBuf NResource::KeyByIndex(size_t idx) {
  38. return CommonStore()->KeyByIndex(idx);
  39. }
  40. TVector<TStringBuf> NResource::ListAllKeys() {
  41. TVector<TStringBuf> res(Reserve(NResource::Count()));
  42. for (auto i : xrange(NResource::Count())) {
  43. res.push_back(NResource::KeyByIndex(i));
  44. }
  45. return res;
  46. }