aboutsummaryrefslogtreecommitdiff
path: root/src/Resources.hh
blob: e19989709ffc7dc99d1e7c42a799730518fcb915 (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
#ifndef RESOURCES_HH
#define RESOURCES_HH

#include "FbPager.hh"

#include "FbTk/Resource.hh"
#include <string>
#include <cstdio>
#include <cstring>

namespace FbTk {

template<>
void FbTk::Resource<bool>::
setFromString(char const *strval) {
    if (strcasecmp(strval, "true") == 0 ||
        strcasecmp(strval, "yes") == 0)
        *this = true;
    else
        *this = false;
}

template<>
std::string FbTk::Resource<bool>::
getString() {				
    return std::string(**this == true ? "true" : "false");
}

template <>
void FbTk::Resource<std::string>::setFromString(const char *str) {
    *(*this) = (str ?  str : "");
}

template <>
std::string FbTk::Resource<std::string>::getString() {
    return *(*this);
}

template <>
void FbTk::Resource<int>::setFromString(const char *str) {
    if (str == 0)
        return;
    sscanf(str, "%d", &(*(*this)));
}

template <>
std::string FbTk::Resource<int>::getString() {
    char buff[16];
    sprintf(buff, "%d", (*(*this)));
    return std::string(buff);
}



template <>
void FbTk::Resource<FbPager::FbPager::Alignment>::
setFromString(const char *str) {
    if (strcmp("TopToBottom", str) == 0)
        *(*this) = FbPager::FbPager::TOP_TO_BOTTOM;
    else
        *(*this) = FbPager::FbPager::LEFT_TO_RIGHT;
}

template <>
std::string FbTk::Resource<FbPager::FbPager::Alignment>::getString() {
    switch (*(*this)) {
    case FbPager::FbPager::LEFT_TO_RIGHT:
        return "LeftToRight";
    case FbPager::FbPager::TOP_TO_BOTTOM:
        return "TopToBottom";
    }
}


}
#endif // RESOURCES