2022-12-19 14:37:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <filesystem>
|
|
|
|
#include <optional>
|
2022-12-20 12:54:40 +00:00
|
|
|
#include <regex>
|
2023-03-21 17:52:28 +00:00
|
|
|
#include <set>
|
2022-12-19 14:37:51 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-06-06 16:13:51 +01:00
|
|
|
#include "oi/ContainerTypeEnum.h"
|
2023-10-09 21:39:33 +01:00
|
|
|
#include "oi/Features.h"
|
2022-12-19 14:37:51 +00:00
|
|
|
|
2023-03-22 16:16:17 +00:00
|
|
|
ContainerTypeEnum containerTypeEnumFromStr(std::string& str);
|
|
|
|
const char* containerTypeEnumToStr(ContainerTypeEnum ty);
|
2022-12-19 14:37:51 +00:00
|
|
|
|
|
|
|
struct ContainerInfo {
|
2023-08-16 20:40:36 +01:00
|
|
|
struct Processor {
|
|
|
|
std::string type;
|
|
|
|
std::string func;
|
|
|
|
};
|
|
|
|
|
2023-03-21 17:52:28 +00:00
|
|
|
struct Codegen {
|
|
|
|
std::string decl;
|
|
|
|
std::string func;
|
2023-08-16 20:40:36 +01:00
|
|
|
std::string traversalFunc = "";
|
2023-09-26 20:19:28 +01:00
|
|
|
std::string extra = "";
|
2023-08-16 20:40:36 +01:00
|
|
|
std::vector<Processor> processors{};
|
2023-03-21 17:52:28 +00:00
|
|
|
};
|
|
|
|
|
2023-05-23 22:36:42 +01:00
|
|
|
explicit ContainerInfo(const std::filesystem::path& path); // Throws
|
2023-05-26 17:57:26 +01:00
|
|
|
ContainerInfo(std::string typeName,
|
|
|
|
ContainerTypeEnum ctype,
|
|
|
|
std::string header);
|
|
|
|
|
|
|
|
// Old ctors, remove with OICodeGen:
|
2023-03-21 17:52:28 +00:00
|
|
|
ContainerInfo() = default;
|
2023-04-18 18:02:37 +01:00
|
|
|
ContainerInfo(std::string typeName_,
|
|
|
|
std::regex matcher_,
|
2023-03-21 17:52:28 +00:00
|
|
|
std::optional<size_t> numTemplateParams_,
|
2023-04-18 18:02:37 +01:00
|
|
|
ContainerTypeEnum ctype_,
|
|
|
|
std::string header_,
|
2023-03-21 17:52:28 +00:00
|
|
|
std::vector<std::string> ns_,
|
|
|
|
std::vector<size_t> replaceTemplateParamIndex_,
|
|
|
|
std::optional<size_t> allocatorIndex_,
|
|
|
|
std::optional<size_t> underlyingContainerIndex_,
|
2023-05-23 22:36:42 +01:00
|
|
|
std::vector<size_t> stubTemplateParams_,
|
2023-11-16 15:21:05 +00:00
|
|
|
oi::detail::FeatureSet requiredFeatures,
|
2023-03-21 17:52:28 +00:00
|
|
|
ContainerInfo::Codegen codegen_)
|
|
|
|
: typeName(std::move(typeName_)),
|
|
|
|
matcher(std::move(matcher_)),
|
|
|
|
numTemplateParams(numTemplateParams_),
|
|
|
|
ctype(ctype_),
|
|
|
|
header(std::move(header_)),
|
|
|
|
ns(std::move(ns_)),
|
|
|
|
replaceTemplateParamIndex(std::move(replaceTemplateParamIndex_)),
|
|
|
|
allocatorIndex(allocatorIndex_),
|
|
|
|
underlyingContainerIndex(underlyingContainerIndex_),
|
2023-05-23 22:36:42 +01:00
|
|
|
stubTemplateParams(std::move(stubTemplateParams_)),
|
2023-11-16 15:21:05 +00:00
|
|
|
requiredFeatures(requiredFeatures),
|
2023-03-21 17:52:28 +00:00
|
|
|
codegen(std::move(codegen_)) {
|
|
|
|
}
|
|
|
|
|
2023-05-23 22:36:42 +01:00
|
|
|
ContainerInfo(ContainerInfo&&) = default;
|
|
|
|
ContainerInfo& operator=(ContainerInfo&&) = default;
|
|
|
|
|
2023-09-22 14:20:00 +01:00
|
|
|
// Explicit interface for copying
|
|
|
|
ContainerInfo clone() const {
|
|
|
|
ContainerInfo copy{*this};
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2022-12-19 14:37:51 +00:00
|
|
|
std::string typeName;
|
2022-12-20 12:54:40 +00:00
|
|
|
std::regex matcher;
|
2022-12-19 14:37:51 +00:00
|
|
|
std::optional<size_t> numTemplateParams;
|
|
|
|
ContainerTypeEnum ctype = UNKNOWN_TYPE;
|
|
|
|
std::string header;
|
|
|
|
std::vector<std::string> ns;
|
|
|
|
std::vector<size_t> replaceTemplateParamIndex{};
|
|
|
|
std::optional<size_t> allocatorIndex{};
|
|
|
|
// Index of underlying container in template parameters for a container
|
|
|
|
// adapter
|
|
|
|
std::optional<size_t> underlyingContainerIndex{};
|
2023-05-23 22:36:42 +01:00
|
|
|
std::vector<size_t> stubTemplateParams{};
|
2023-09-22 14:20:00 +01:00
|
|
|
bool captureKeys = false;
|
2023-10-09 21:39:33 +01:00
|
|
|
oi::detail::FeatureSet requiredFeatures;
|
2022-12-19 14:37:51 +00:00
|
|
|
|
2023-03-21 17:52:28 +00:00
|
|
|
Codegen codegen;
|
|
|
|
|
|
|
|
static std::unique_ptr<ContainerInfo> loadFromFile(
|
|
|
|
const std::filesystem::path& path);
|
2022-12-19 14:37:51 +00:00
|
|
|
|
2023-03-22 16:16:17 +00:00
|
|
|
bool operator<(const ContainerInfo& rhs) const {
|
2022-12-19 14:37:51 +00:00
|
|
|
return (typeName < rhs.typeName);
|
|
|
|
}
|
2023-09-22 14:20:00 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
ContainerInfo(const ContainerInfo&) = default;
|
|
|
|
ContainerInfo& operator=(const ContainerInfo& other) = default;
|
2022-12-19 14:37:51 +00:00
|
|
|
};
|
2023-03-21 17:52:28 +00:00
|
|
|
|
2023-06-20 17:57:13 +01:00
|
|
|
class ContainerInfoError : public std::runtime_error {
|
|
|
|
public:
|
|
|
|
ContainerInfoError(const std::filesystem::path& path, const std::string& msg)
|
|
|
|
: std::runtime_error{std::string{path} + ": " + msg} {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-21 17:52:28 +00:00
|
|
|
using ContainerInfoRefSet =
|
|
|
|
std::set<std::reference_wrapper<const ContainerInfo>,
|
|
|
|
std::less<ContainerInfo>>;
|