MCPcopy Create free account
hub / github.com/Exiv2/exiv2 / BlockMap

Class BlockMap

src/basicio.cpp:592–650  ·  view source on GitHub ↗

! @brief Utility class provides the block mapping to the part of data. This avoids allocating a single contiguous block of memory to the big data. */

Source from the content-addressed store, hash-verified

590 a single contiguous block of memory to the big data.
591 */
592class BlockMap {
593 public:
594 //! the status of the block.
595 enum blockType_e { bNone, bKnown, bMemory };
596 //! @name Creators
597 //@{
598 //! Default constructor. the init status of the block is bNone.
599 BlockMap() = default;
600
601 //! Destructor. Releases all managed memory.
602 ~BlockMap() {
603 delete[] data_;
604 }
605
606 BlockMap(const BlockMap&) = delete;
607 BlockMap& operator=(const BlockMap&) = delete;
608
609 //! @brief Populate the block.
610 //! @param source The data populate to the block
611 //! @param num The size of data
612 void populate(const byte* source, size_t num) {
613 size_ = num;
614 data_ = new byte[size_];
615 type_ = bMemory;
616 std::memcpy(data_, source, size_);
617 }
618
619 /*!
620 @brief Change the status to bKnow. bKnow blocks do not contain the data,
621 but they keep the size of data. This avoids allocating memory for parts
622 of the file that contain image-date (non-metadata/pixel data) which never change in exiv2.
623 @param num The size of the data
624 */
625 void markKnown(size_t num) {
626 type_ = bKnown;
627 size_ = num;
628 }
629
630 [[nodiscard]] bool isNone() const {
631 return type_ == bNone;
632 }
633
634 [[nodiscard]] bool isKnown() const {
635 return type_ == bKnown;
636 }
637
638 [[nodiscard]] byte* getData() const {
639 return data_;
640 }
641
642 [[nodiscard]] size_t getSize() const {
643 return size_;
644 }
645
646 private:
647 blockType_e type_{bNone};
648 byte* data_{nullptr};
649 size_t size_{0};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected