47 lines
1.3 KiB
C
47 lines
1.3 KiB
C
|
|
#pragma once
|
||
|
|
// Step 1980: ProjectStackDeclarator
|
||
|
|
// Declares the available library stack for a project.
|
||
|
|
// librariesForDomain() returns declared libraries with score > 0 in the ledger.
|
||
|
|
|
||
|
|
#include "LibraryCapabilityLedger.h"
|
||
|
|
#include <algorithm>
|
||
|
|
#include <string>
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
namespace whetstone {
|
||
|
|
|
||
|
|
class ProjectStackDeclarator {
|
||
|
|
public:
|
||
|
|
std::string projectId;
|
||
|
|
std::vector<std::string> declaredLibraries;
|
||
|
|
std::vector<std::string> operationDomains;
|
||
|
|
|
||
|
|
void declare(const std::string& lib) {
|
||
|
|
declaredLibraries.push_back(lib);
|
||
|
|
}
|
||
|
|
|
||
|
|
void addDomain(const std::string& domain) {
|
||
|
|
operationDomains.push_back(domain);
|
||
|
|
}
|
||
|
|
|
||
|
|
bool hasDomain(const std::string& domain) const {
|
||
|
|
return std::find(operationDomains.begin(), operationDomains.end(), domain)
|
||
|
|
!= operationDomains.end();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Returns declared libraries that have score > 0 for the given domain.
|
||
|
|
std::vector<std::string> librariesForDomain(
|
||
|
|
const std::string& domain,
|
||
|
|
const LibraryCapabilityLedger& ledger) const {
|
||
|
|
std::vector<std::string> result;
|
||
|
|
for (const auto& lib : declaredLibraries) {
|
||
|
|
if (ledger.score(lib, domain) > 0.0f) {
|
||
|
|
result.push_back(lib);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace whetstone
|