reference_set.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_ZUCCHINI_REFERENCE_SET_H_
  5. #define COMPONENTS_ZUCCHINI_REFERENCE_SET_H_
  6. #include <stddef.h>
  7. #include <vector>
  8. #include "components/zucchini/image_utils.h"
  9. namespace zucchini {
  10. class TargetPool;
  11. // Container of distinct references of one type, along with traits, only used
  12. // during patch generation.
  13. class ReferenceSet {
  14. public:
  15. using const_iterator = std::vector<Reference>::const_iterator;
  16. // |traits| specifies the reference represented. |target_pool| specifies
  17. // common targets shared by all reference represented, and mediates target
  18. // translation between offsets and indexes.
  19. ReferenceSet(const ReferenceTypeTraits& traits,
  20. const TargetPool& target_pool);
  21. ReferenceSet(const ReferenceSet&) = delete;
  22. ReferenceSet(ReferenceSet&&);
  23. ~ReferenceSet();
  24. // Either one of the initializers below should be called exactly once. These
  25. // insert all references from |ref_reader/refs| into this class. The targets
  26. // of these references must be in |target_pool_|.
  27. void InitReferences(ReferenceReader&& ref_reader);
  28. void InitReferences(const std::vector<Reference>& refs);
  29. const std::vector<Reference>& references() const { return references_; }
  30. const ReferenceTypeTraits& traits() const { return traits_; }
  31. const TargetPool& target_pool() const { return target_pool_; }
  32. TypeTag type_tag() const { return traits_.type_tag; }
  33. PoolTag pool_tag() const { return traits_.pool_tag; }
  34. offset_t width() const { return traits_.width; }
  35. // Looks up the Reference by an |offset| that it spans. |offset| is assumed to
  36. // be valid, i.e., |offset| must be spanned by some Reference in
  37. // |references_|.
  38. Reference at(offset_t offset) const;
  39. size_t size() const { return references_.size(); }
  40. const_iterator begin() const { return references_.begin(); }
  41. const_iterator end() const { return references_.end(); }
  42. private:
  43. ReferenceTypeTraits traits_;
  44. const TargetPool& target_pool_;
  45. // List of distinct Reference instances sorted by location.
  46. std::vector<Reference> references_;
  47. };
  48. } // namespace zucchini
  49. #endif // COMPONENTS_ZUCCHINI_REFERENCE_SET_H_