|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
#include <chrono> |
|
#include <map> |
|
#include <memory> |
|
#include <string> |
|
#include <vector> |
|
|
|
namespace libkineto { |
|
|
|
class AbstractConfig { |
|
public: |
|
AbstractConfig& operator=(const AbstractConfig&) = delete; |
|
AbstractConfig(AbstractConfig&&) = delete; |
|
AbstractConfig& operator=(AbstractConfig&&) = delete; |
|
|
|
virtual ~AbstractConfig() { |
|
for (const auto& p : featureConfigs_) { |
|
delete p.second; |
|
} |
|
} |
|
|
|
|
|
virtual AbstractConfig* cloneDerived(AbstractConfig& parent) const = 0; |
|
|
|
|
|
bool parse(const std::string& conf); |
|
|
|
|
|
virtual void setSignalDefaults() { |
|
for (auto& p : featureConfigs_) { |
|
p.second->setSignalDefaults(); |
|
} |
|
} |
|
|
|
|
|
virtual void setClientDefaults() { |
|
for (auto& p : featureConfigs_) { |
|
p.second->setClientDefaults(); |
|
} |
|
} |
|
|
|
|
|
std::chrono::time_point<std::chrono::system_clock> timestamp() const { |
|
return timestamp_; |
|
} |
|
|
|
|
|
const std::string& source() const { |
|
return source_; |
|
} |
|
|
|
AbstractConfig& feature(std::string name) const { |
|
const auto& pos = featureConfigs_.find(name); |
|
return *pos->second; |
|
} |
|
|
|
|
|
void addFeature(const std::string& name, AbstractConfig* cfg) { |
|
featureConfigs_[name] = cfg; |
|
} |
|
|
|
protected: |
|
AbstractConfig() {} |
|
AbstractConfig(const AbstractConfig& other) = default; |
|
|
|
|
|
|
|
virtual bool handleOption(const std::string& name, std::string& val); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void validate( |
|
const std::chrono::time_point<std::chrono::system_clock>& |
|
fallbackProfileStartTime) = 0; |
|
|
|
|
|
virtual void printActivityProfilerConfig(std::ostream& s) const; |
|
virtual void setActivityDependentConfig(); |
|
|
|
|
|
|
|
std::vector<std::string> splitAndTrim(const std::string& s, char delim) const; |
|
|
|
std::string toLower(std::string& s) const; |
|
|
|
bool endsWith(const std::string& s, const std::string& suffix) const; |
|
|
|
int64_t toIntRange(const std::string& val, int64_t min, int64_t max) const; |
|
int32_t toInt32(const std::string& val) const; |
|
int64_t toInt64(const std::string& val) const; |
|
bool toBool(std::string& val) const; |
|
|
|
void cloneFeaturesInto(AbstractConfig& cfg) const { |
|
for (const auto& feature : featureConfigs_) { |
|
cfg.featureConfigs_[feature.first] = feature.second->cloneDerived(cfg); |
|
} |
|
} |
|
|
|
private: |
|
|
|
std::chrono::time_point<std::chrono::system_clock> timestamp_{}; |
|
|
|
|
|
std::string source_{""}; |
|
|
|
|
|
std::map<std::string, AbstractConfig*> featureConfigs_{}; |
|
}; |
|
|
|
} |
|
|