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

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
content badge
swh:1:cnt:e914a8a2df2b49cd55625bb7a5f9595428a1877b

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
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
#include "pds.hpp"
#include "graphio.hpp"
#include "draw_grid.hpp"

#include <boost/program_options.hpp>
#include <fmt/format.h>

#include <ogdf/energybased/FMMMLayout.h>
#include <ogdf/energybased/fmmm/FMMMOptions.h>

void writeLayout(const pds::Layout& layout, const std::string& filename) {
    FILE* outfile = fopen(filename.c_str(), "wb");
    if (outfile == nullptr) throw std::system_error(std::error_code(errno, std::system_category()));
    fmt::print(outfile, "Layout V1.0\n");
    for (auto [k, v]: layout) {
        fmt::print(outfile, "{} {} {}\n", k, v.x, v.y);
    }
    fclose(outfile);
}

struct ParseError : std::exception {
    std::string reason;
    ParseError(const std::string& reason, size_t line) : reason(fmt::format("{}: {}", line, reason)) { }
    const char * what() const noexcept override { return reason.c_str(); }
};

std::vector<std::string_view> split(const std::string_view& in, char delim) {
    std::vector<std::string_view> pieces;
    size_t start = 0;
    size_t end;
    while (start != std::string::npos) {
        end = in.find(delim, start);
        pieces.emplace_back(in.substr(start, end - start));
        if (end == std::string::npos) {
            start = std::string::npos;
        } else {
            start = end + 1;
        }

    }
    return pieces;
}

pds::Layout readLayout(const std::string& filename) {
    std::ifstream infile(filename);
    std::string line;
    size_t lineno = 0;
    pds::Layout layout;
    std::getline(infile, line);
    ++lineno;
    if (line != "Layout V1.0") throw ParseError { fmt::format("unknown format: {}", line), lineno };
    while (infile) {
        std::getline(infile, line);
        ++lineno;
        auto pieces = split(line, ' ');
        if (pieces.size() == 1 && pieces[0] == "") continue; // empty line
        if (pieces.size() != 3) throw ParseError { "not a triple", lineno };
        try {
            long v = std::stoi(std::string{pieces[0]});
            double x = std::stoi(std::string{pieces[1]});
            double y = std::stoi(std::string{pieces[2]});
            layout[v] = {x, y};
        } catch(const std::exception& ex) {
            throw ParseError { fmt::format("could not read number: {}", ex.what()), lineno };
        }
    }
    return layout;
}

void restrictLayout(pds::Layout& layout, const pds::PowerGrid& graph) {
    pds::set<long> ids = ranges::transform_view(graph.vertices(), [&graph](auto v) { return graph[v].id; }) | ranges::to<pds::set<long>>;
    erase_if(layout,[&ids](const auto& kv) { return !ids.contains(kv.first);});
}

int main(int argc, const char** argv) {
    namespace po = boost::program_options;
    using std::string;
    using namespace pds;

    po::options_description desc;
    desc.add_options()
            ("layout,l", po::value<string>(), "load layout from file")
            ("save-layout,s", po::value<string>(), "save layout to file")
            ("graph,g", po::value<string>()->required(), "graph file")
            ("draw,d", po::value<string>(), "create graph svg file")
            ("layout-bounds,b", "use bounds from layout for drawing")
            ("help,h", "show this help")
    ;
    po::positional_options_description pos;
    pos.add("graph", 1);

    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).options(desc).positional(pos).run(), vm);
    if (vm.count("help")) {
        desc.print(std::cout);
        return EXIT_FAILURE;
    }

    auto graph = readAutoGraph(vm["graph"].as<string>());

    Layout layout;
    if (vm.count("layout")) {
        layout = readLayout(vm["layout"].as<string>());
        if (!vm.count("layout-bounds")) {
            restrictLayout(layout, graph);
        }
    } else {
        layout = layoutGraph(graph);
    }
    if (vm.count("draw")) {
        PdsState state(graph);
        drawGrid(state, vm["draw"].as<string>(), layout);
    }
    if (vm.count("save-layout")) {
        writeLayout(layout, vm["save-layout"].as<string>());
    }
}

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