File: directory.h

package info (click to toggle)
intel-compute-runtime 25.48.36300.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,652 kB
  • sloc: cpp: 939,022; lisp: 2,090; sh: 722; makefile: 162; python: 21
file content (77 lines) | stat: -rw-r--r-- 2,174 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (C) 2018-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once
#include "shared/source/helpers/non_copyable_or_moveable.h"

#include <cinttypes>
#include <optional>
#include <string.h>
#include <string>
#include <vector>

namespace NEO {

class Directory : NEO::NonCopyableAndNonMovableClass {
  public:
    static inline constexpr char returnDirs{1 << 0};
    static inline constexpr char createDirs{1 << 1};

    static std::vector<std::string> getFiles(const std::string &path);
    static void createDirectory(const std::string &path);

    Directory() = default;
    Directory(const std::string &path) : path(path) {}

    inline std::optional<std::vector<std::string>> parseDirectories(char flags) {
        std::optional<std::vector<std::string>> directories;
        if (flags & returnDirs) {
            directories.emplace();
        }
        std::string tmp;
        size_t pos = 0;

        while (pos != std::string::npos) {
            pos = this->path.find_first_of("/\\", pos + 1);
            tmp = this->path.substr(0, pos);
            if (flags & createDirs) {
                this->create(tmp);
            }
            if (flags & returnDirs) {
                directories->push_back(tmp);
            }
        }
        return directories;
    }

    void operator()(const std::string &path) {
        this->path = path;
    }

  protected:
    virtual void create(const std::string &path) {
        createDirectory(path);
    }

    std::string path;
};

static_assert(NEO::NonCopyableAndNonMovable<Directory>);

inline int parseBdfString(const std::string &pciBDF, uint16_t &domain, uint8_t &bus, uint8_t &device, uint8_t &function) {
    if (strlen(pciBDF.c_str()) == 12) {
        domain = static_cast<uint16_t>(strtol((pciBDF.substr(0, 4)).c_str(), NULL, 16));
        bus = static_cast<uint8_t>(strtol((pciBDF.substr(5, 2)).c_str(), NULL, 16));
        device = static_cast<uint8_t>(strtol((pciBDF.substr(8, 2)).c_str(), NULL, 16));
        function = static_cast<uint8_t>(strtol((pciBDF.substr(11, 1)).c_str(), NULL, 16));
        return 4;
    } else {
        return 0;
    }
}

} // namespace NEO