looper/license.hpp

36 lines
1.3 KiB
C++
Raw Permalink Normal View History

#pragma once
#include <string>
#include <vector>
#include <cstring>
2024-03-26 18:39:02 -07:00
#include <unordered_set>
#include "log.hpp"
#include "util.hpp"
using std::string;
struct LicenseData {
string Project;
string Spdx;
string LicenseContents = "";
inline void load_contents(const unsigned int *license_data, const unsigned int license_size) {
std::vector<char> vec(license_size);
vec.resize(license_size);
memcpy(vec.data(), license_data, license_size);
vec.push_back('\0');
LicenseContents = string(vec.data());
2024-03-26 18:39:02 -07:00
DEBUG.writefln("Loading license for project '%s': %s...", Project.c_str(), Spdx.c_str());
}
inline LicenseData(string project, string spdx) {
this->Project = project;
this->Spdx = spdx;
}
2024-03-26 18:39:02 -07:00
inline bool operator==(const LicenseData &other) const {
return Project == other.Project && Spdx == other.Spdx;
}
};
template<>
struct std::hash<LicenseData> {
inline std::size_t operator()(const LicenseData d) const noexcept {
return combine_hashes({std::hash<string>()(d.Project), std::hash<string>()(d.Spdx)});
}
};
2024-03-26 18:39:02 -07:00
std::unordered_set<LicenseData> &get_license_data();
#define LOAD_LICENSE(data, prefix) if (data.LicenseContents == "") data.load_contents(prefix##_license_data, prefix##_license_size);