summaryrefslogtreecommitdiff
path: root/src/feature.cc
blob: 5beece102a103eb896e286934549cd5dd1513998 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>

#include "feature.h"

/**
 * Feature registration map for later lookup. This must be initialized
 * before the static feature instances as those register with this map. 
 */
std::map<std::string, Feature *> Feature::feature_map;

/*
 * List of features, the names given here are used in both command line
 * argument to enable the option and for saving the option value in GUI
 * context.
 */
const Feature Feature::ExperimentalConcatFunction("concat");

Feature::Feature(std::string name) : enabled_cmdline(false), enabled_options(false), name(name)
{
        feature_map[name] = this;
}

Feature::~Feature()
{
}

const std::string& Feature::get_name() const
{
        return name;
}
    
void Feature::set_enable_cmdline()
{
	enabled_cmdline = true;
}

void Feature::set_enable_options(bool status)
{
	enabled_options = status;
}

bool Feature::is_enabled() const
{
	if (enabled_cmdline) {
	    return true;
	}
	return enabled_options;
}
    
bool operator ==(const Feature& lhs, const Feature& rhs)
{
        return lhs.get_name() == rhs.get_name();
}

bool operator !=(const Feature& lhs, const Feature& rhs)
{
        return !(lhs == rhs);
}
    
void Feature::enable_feature(std::string feature_name)
{
	map_t::iterator it = feature_map.find(feature_name);
	if (it != feature_map.end()) {
		(*it).second->set_enable_cmdline();
	}
}

void Feature::enable_feature(std::string feature_name, bool status)
{
	map_t::iterator it = feature_map.find(feature_name);
	if (it != feature_map.end()) {
		(*it).second->set_enable_options(status);
	}
}

void Feature::dump_features()
{
	for (map_t::iterator it = feature_map.begin(); it != feature_map.end(); it++) {
		std::cout << "Feature('" << (*it).first << "') = " << ((*it).second->is_enabled() ? "enabled" : "disabled") << std::endl;
	}
}
contact: Jan Huwald // Impressum