forked from ni/grpc-labview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature_toggles.cc
More file actions
59 lines (52 loc) · 2.29 KB
/
feature_toggles.cc
File metadata and controls
59 lines (52 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <feature_toggles.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>
#include <algorithm>
namespace grpc_labview {
// Function to read feature configurations from an INI file
void FeatureConfig::readConfigFromFile(const std::string& filePath) {
std::ifstream configFile(filePath);
if (!configFile.is_open()) {
return;
}
std::string line;
std::string currentSection; // For handling INI sections
while (std::getline(configFile, line)) {
// Trim leading and trailing whitespaces
line.erase(line.find_last_not_of(" \t") + 1);
line.erase(0, line.find_first_not_of(" \t"));
// Skip comments and empty lines
if (line.empty() || line[0] == ';') {
continue;
}
// Check for section header
if (line[0] == '[' && line[line.length() - 1] == ']') {
currentSection = line.substr(1, line.length() - 2);
}
else {
// Parse key-value pairs
std::istringstream iss(line);
std::string key, value;
if (std::getline(iss, key, '=') && std::getline(iss, value)) {
// Append section name to key for uniqueness
key.erase(std::remove_if(key.begin(), key.end(), ::isspace),key.end());
value.erase(std::remove_if(value.begin(), value.end(), ::isspace),value.end());
std::string fullKey = currentSection.empty() ? key : currentSection + "_" + key;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
featureFlags[fullKey] = (value == "true");
}
}
}
configFile.close();
//TODO: remove this post fixing LVMessageEfficient to let enable feature. See issue: #433
if (featureFlags.find("data_EfficientMessageCopy") != featureFlags.end())
featureFlags["data_EfficientMessageCopy"] = false;
}
// Function to check if a feature is enabled
bool FeatureConfig::isFeatureEnabled(const std::string& featureName) const {
auto it = featureFlags.find(featureName);
return (it != featureFlags.end()) ? it->second : false;
}
}