Palette.cpp 1.14 KB
Newer Older
1 2
#include <string>
#include <map>
3
#include <iostream>
4 5 6 7 8 9 10 11 12 13 14 15
/* -- */
#include "trace/values/Value.hpp"
#include "trace/values/Color.hpp"
/* -- */
#include "common/Session.hpp"
/* -- */
#include "Palette.hpp"

Palette::Palette(const std::string &name) : _name(name) {
}

Palette::~Palette() {
16 17
    for(auto & _pair : _pairs) {
        Color *c = _pair.second;
18 19 20 21 22 23
        delete c;
    }
}


Color *Palette::get_color(const std::string &state_name) {
Mathieu Faverge's avatar
Mathieu Faverge committed
24
    if(_pairs.find(state_name) != _pairs.end())
25
        return _pairs[state_name];
26
    else{
27
        return nullptr;
28
    }
29 30
}

31
bool Palette::is_visible(const std::string &state_name){
32 33 34 35
    if (_visible.count(state_name) > 0)
        return _visible[state_name];
    else
        return true;
36
}
37 38

void Palette::add_state(const std::string &state, Color &c, bool visible) {
39 40 41 42 43
    if(_pairs.find(state) != _pairs.end()) {
        Color *tmp = _pairs[state];
        delete tmp;
    }
    _pairs[state] = new Color(c);
44
    _visible[state] = visible;
45 46
}

47
void Palette::clear(){
48
    _pairs.clear();
49 50
}

51 52 53 54 55 56 57
std::string Palette::get_name() const {
    return _name;
}

std::map<std::string, Color *> Palette::get_map() const {
    return _pairs;
}