Skip to content
Merged

up #45

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions include/GenericToolbox.Json.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,22 @@ namespace GenericToolbox {
inline JsonType getForwardedConfig(const JsonType& config_) {
JsonType out = config_;
while( out.is_string() ){
out = readConfigFile(out.template get<std::string>());
out = readConfigFile(out.get<std::string>());
}
return out;
}
inline void forwardConfig(JsonType& config_, const std::string& className_){
while( config_.is_string() ){
std::cout << "Forwarding " << (className_.empty()? "": className_ + " ") << "config: \"" << config_.template get<std::string>() << "\"" << std::endl;
auto name = config_.template get<std::string>();
std::cout << "Forwarding " << (className_.empty()? "": className_ + " ") << "config: \"" << config_.get<std::string>() << "\"" << std::endl;
auto name = config_.get<std::string>();
std::string expand = expandEnvironmentVariables(name);
config_ = readConfigFile(expand);
}
}
inline void unfoldConfig(JsonType& config_){
for( auto& entry : config_ ){
if( entry.is_string() and (
endsWith(entry.template get<std::string>(), ".json", true)
endsWith(entry.get<std::string>(), ".json", true)
) ){
forwardConfig(entry);
unfoldConfig(config_); // remake the loop on the unfolder config
Expand Down Expand Up @@ -245,7 +245,7 @@ namespace GenericToolbox {

for( auto& condEntry : jsonList ){
if( condEntry.is_string() ){
conditionsList.emplace_back( condEntry.template get<std::string>() );
conditionsList.emplace_back( condEntry.get<std::string>() );
}
else{
std::cout << "Could not recognise condition entry: " << condEntry << std::endl;
Expand Down Expand Up @@ -334,7 +334,7 @@ namespace GenericToolbox {
}
template<typename T> JsonType fetchMatchingEntry(const JsonType& jsonConfig_, const std::string& keyPath_, const T& keyValue_){
if( jsonConfig_.empty() or not jsonConfig_.is_array() ){ return {}; }
for(const auto& jsonEntry : jsonConfig_.template get<std::vector<JsonType>>() ){
for(const auto& jsonEntry : jsonConfig_.get<std::vector<JsonType>>() ){
try{ if( fetchValue<T>(jsonEntry, keyPath_) == keyValue_ ){ return jsonEntry; } }
catch (...){} // next
}
Expand Down Expand Up @@ -575,17 +575,17 @@ namespace GenericToolbox {

namespace Internal{
template<typename T> T getImpl(const JsonType& json_, T*){
return json_.template get<T>();
return json_.get<T>();
}
inline double getImpl(const JsonType& json_, double*){
// better handling of nan
if( json_.is_string() ){
if( json_.template get<std::string>() == "nan" ){ return std::nan("nan"); }
if( json_.template get<std::string>() == "null" ){ return std::nan("null"); }
if( json_.get<std::string>() == "nan" ){ return std::nan("nan"); }
if( json_.get<std::string>() == "null" ){ return std::nan("null"); }
// otherwise it is a string that should be castable as a double
}
if( json_.is_null() ){ return std::nan("null"); } // macOS
return json_.template get<double>();
return json_.get<double>();
}
inline Range getImpl(const JsonType& json_, Range*){
if( not json_.is_array() ){ throw std::runtime_error("provided json is not an array."); }
Expand Down
4 changes: 2 additions & 2 deletions include/GenericToolbox.Switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ namespace GenericToolbox::Switch {
const std::string &title_, bool forcePrint_,
const std::string& color_
){
if(forcePrint_ or ProgressBar::gProgressBar.template showProgressBar(iCurrent_, iTotal_) ){
if(forcePrint_ or ProgressBar::gProgressBar.showProgressBar(iCurrent_, iTotal_) ){
ProgressBar::gProgressBar.setDisableVt100Cmd( true );
printRight(ProgressBar::gProgressBar.template generateProgressBarStr(iCurrent_, iTotal_, GenericToolbox::padString(title_, 40)), color_, true);
printRight(ProgressBar::gProgressBar.generateProgressBarStr(iCurrent_, iTotal_, GenericToolbox::padString(title_, 40)), color_, true);
consoleUpdate(nullptr);
}
}
Expand Down
15 changes: 9 additions & 6 deletions include/GenericToolbox.Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,16 @@ namespace GenericToolbox{
}

template<typename T, typename TT> static std::string generateProgressBarStr( const T& iCurrent_, const TT& iTotal_, const std::string &title_ ){
return ProgressBar::gProgressBar.template generateProgressBarStr(iCurrent_, iTotal_, title_);
return ProgressBar::gProgressBar.generateProgressBarStr(iCurrent_, iTotal_, title_);
}
template<typename T, typename TT> static bool showProgressBar(const T& iCurrent_, const TT& iTotal_){
return ProgressBar::gProgressBar.template showProgressBar(iCurrent_, iTotal_);
return ProgressBar::gProgressBar.showProgressBar(iCurrent_, iTotal_);
}
template<typename T, typename TT> static std::string getProgressBarStr(const T& iCurrent_, const TT& iTotal_, const std::string &title_, bool forcePrint_ ){
return ProgressBar::gProgressBar.template getProgressBarStr(iCurrent_, iTotal_, title_, forcePrint_);
return ProgressBar::gProgressBar.getProgressBarStr(iCurrent_, iTotal_, title_, forcePrint_);
}
template<typename T, typename TT> static void displayProgressBar(const T& iCurrent_, const TT& iTotal_, const std::string &title_, bool forcePrint_) {
return ProgressBar::gProgressBar.template displayProgressBar(iCurrent_, iTotal_, title_, forcePrint_);
return ProgressBar::gProgressBar.displayProgressBar(iCurrent_, iTotal_, title_, forcePrint_);
}
static void resetLastDisplayedValue(){
ProgressBar::gProgressBar.resetLastDisplayedValue();
Expand Down Expand Up @@ -439,7 +439,10 @@ namespace GenericToolbox{
}

Range& operator+=(double shift_){ min += shift_; max += shift_; return *this; }
Range& operator-=(double shift_){ min -= shift_; max -= shift_; return *this; }
Range& operator-=(double shift_){ *this += -shift_; return *this; }
bool operator==(const Range& other_) const { return min == other_.min && max == other_.max; }
bool operator!=(const Range& other_) const { return !(*this == other_); }

friend std::ostream& operator <<( std::ostream& o, const Range& this_ ){ o << this_.toString(); return o; }
};
}
Expand Down Expand Up @@ -1202,7 +1205,7 @@ namespace GenericToolbox{ // Structs to decide if a stream function can be impl
if( other_._varPtr_ != nullptr ){ this->_varPtr_ = std::unique_ptr<PlaceHolder>(other_._varPtr_->clone()); }
}
template<typename ValueType> inline AnyType::AnyType(const ValueType& value_){
this->template setValue(value_);
this->setValue(value_);
}

template<typename ValueType> inline AnyType& AnyType::operator=(const ValueType & rhs) {
Expand Down
2 changes: 1 addition & 1 deletion include/GenericToolbox.Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace GenericToolbox {
}
template<typename T> static void addIfNotInVector(const T& element_, std::vector<T> &vector_){
if( not GenericToolbox::doesElementIsInVector(element_, vector_) ){
vector_.template emplace_back(element_);
vector_.emplace_back(element_);
}
}
static void addIfNotInVector(const char* element_, std::vector<std::string> &vector_){
Expand Down
4 changes: 2 additions & 2 deletions include/GenericToolbox.Yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace GenericToolbox {
throw std::runtime_error(keyName_ + " does not exist");
}

return yamlConfig_[keyName_].template as<T>();
return yamlConfig_[keyName_].as<T>();
}
template<class T> inline auto fetchValue(const YAML::Node& yamlConfig_, const std::string& keyName_, const T& defaultValue_) -> T{
try{
Expand All @@ -85,7 +85,7 @@ namespace GenericToolbox {
}

for( const auto& yamlEntry : yamlConfig_ ){
if(yamlEntry[keyName_] and yamlEntry[keyName_].template as<T>() == keyValue_ ){
if(yamlEntry[keyName_] and yamlEntry[keyName_].as<T>() == keyValue_ ){
return YAML::Node(yamlEntry);
}
}
Expand Down