Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 062bf3d
  • /
  • VofDataUtils
  • /
  • Grid
  • /
  • GridIterator.h
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:78101b7f13ab9d0992ed6ad5c96ac7ba0bed0e81
directory badge
swh:1:dir:ea777418dfe39c945fc3cd3aae27eb67872744e4

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
GridIterator.h
#pragma once

#include <algorithm>

#include "GridTypes.h"

namespace VofFlow {
    class GridRange {
    public:
        GridRange(const gridCoords_t& startPos, const gridCoords_t& endPos) : startPos_(startPos), endPos_(endPos) {}

        explicit GridRange(const extent_t& extent) {
            startPos_ = {extent[0], extent[2], extent[4]};
            endPos_ = {extent[1], extent[3], extent[5]};
        }

        GridRange(const dim_t& dimensions, const gridCoords_t& start, int searchRange) {
            startPos_ = {
                std::max(start[0] - searchRange, 0),
                std::max(start[1] - searchRange, 0),
                std::max(start[2] - searchRange, 0),
            };
            endPos_ = {
                std::min(start[0] + searchRange + 1, dimensions[0]),
                std::min(start[1] + searchRange + 1, dimensions[1]),
                std::min(start[2] + searchRange + 1, dimensions[2]),
            };
        }

        class Iterator {
        public:
            Iterator(const gridCoords_t& startPos, const gridCoords_t& endPos)
                : position_(startPos),
                  startPos_(startPos),
                  endPos_(endPos) {
                if (position_[0] >= endPos_[0] || position_[1] >= endPos_[1] || position_[2] >= endPos_[2]) {
                    position_ = endPos_;
                }
            }

            inline Iterator& operator++() {
                position_[0]++;
                if (position_[0] >= endPos_[0]) {
                    position_[0] = startPos_[0];
                    position_[1]++;
                    if (position_[1] >= endPos_[1]) {
                        position_[1] = startPos_[1];
                        position_[2]++;
                        if (position_[2] >= endPos_[2]) {
                            position_ = endPos_;
                        }
                    }
                }
                return *this;
            }

            inline const gridCoords_t& operator*() const {
                return position_;
            }

            inline bool operator==(const Iterator& other) {
                return position_ == other.position_;
            }

            inline bool operator!=(const Iterator& other) {
                return position_ != other.position_;
            }

        private:
            gridCoords_t position_;
            const gridCoords_t& startPos_;
            const gridCoords_t& endPos_;
        };

        [[nodiscard]] inline auto begin() const {
            return Iterator(startPos_, endPos_);
        }

        [[nodiscard]] inline auto end() const {
            return Iterator(endPos_, endPos_);
        }

    private:
        gridCoords_t startPos_;
        gridCoords_t endPos_;
    };

} // namespace VofFlow

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API