diff options
Diffstat (limited to 'src/Resources.hh')
-rw-r--r-- | src/Resources.hh | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/Resources.hh b/src/Resources.hh new file mode 100644 index 0000000..e199897 --- /dev/null +++ b/src/Resources.hh | |||
@@ -0,0 +1,76 @@ | |||
1 | #ifndef RESOURCES_HH | ||
2 | #define RESOURCES_HH | ||
3 | |||
4 | #include "FbPager.hh" | ||
5 | |||
6 | #include "FbTk/Resource.hh" | ||
7 | #include <string> | ||
8 | #include <cstdio> | ||
9 | #include <cstring> | ||
10 | |||
11 | namespace FbTk { | ||
12 | |||
13 | template<> | ||
14 | void FbTk::Resource<bool>:: | ||
15 | setFromString(char const *strval) { | ||
16 | if (strcasecmp(strval, "true") == 0 || | ||
17 | strcasecmp(strval, "yes") == 0) | ||
18 | *this = true; | ||
19 | else | ||
20 | *this = false; | ||
21 | } | ||
22 | |||
23 | template<> | ||
24 | std::string FbTk::Resource<bool>:: | ||
25 | getString() { | ||
26 | return std::string(**this == true ? "true" : "false"); | ||
27 | } | ||
28 | |||
29 | template <> | ||
30 | void FbTk::Resource<std::string>::setFromString(const char *str) { | ||
31 | *(*this) = (str ? str : ""); | ||
32 | } | ||
33 | |||
34 | template <> | ||
35 | std::string FbTk::Resource<std::string>::getString() { | ||
36 | return *(*this); | ||
37 | } | ||
38 | |||
39 | template <> | ||
40 | void FbTk::Resource<int>::setFromString(const char *str) { | ||
41 | if (str == 0) | ||
42 | return; | ||
43 | sscanf(str, "%d", &(*(*this))); | ||
44 | } | ||
45 | |||
46 | template <> | ||
47 | std::string FbTk::Resource<int>::getString() { | ||
48 | char buff[16]; | ||
49 | sprintf(buff, "%d", (*(*this))); | ||
50 | return std::string(buff); | ||
51 | } | ||
52 | |||
53 | |||
54 | |||
55 | template <> | ||
56 | void FbTk::Resource<FbPager::FbPager::Alignment>:: | ||
57 | setFromString(const char *str) { | ||
58 | if (strcmp("TopToBottom", str) == 0) | ||
59 | *(*this) = FbPager::FbPager::TOP_TO_BOTTOM; | ||
60 | else | ||
61 | *(*this) = FbPager::FbPager::LEFT_TO_RIGHT; | ||
62 | } | ||
63 | |||
64 | template <> | ||
65 | std::string FbTk::Resource<FbPager::FbPager::Alignment>::getString() { | ||
66 | switch (*(*this)) { | ||
67 | case FbPager::FbPager::LEFT_TO_RIGHT: | ||
68 | return "LeftToRight"; | ||
69 | case FbPager::FbPager::TOP_TO_BOTTOM: | ||
70 | return "TopToBottom"; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | |||
75 | } | ||
76 | #endif // RESOURCES | ||