source: flair-src/trunk/lib/FlairCore/src/Widget.cpp@ 26

Last change on this file since 26 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

File size: 5.7 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5// created: 2012/05/02
6// filename: Widget.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Abstract class for all Framework's widget classes
14//
15//
16/*********************************************************************/
17
18#include "Widget.h"
19#include "Widget_impl.h"
20
21using std::string;
22
23namespace flair {
24namespace gui {
25
26using namespace core;
27
28Widget::Widget(const Widget *parent, string name, string type)
29 : Object(parent, name, type) {
30 pimpl_ = new Widget_impl(this, parent, name, type);
31}
32
33Widget::~Widget() { delete pimpl_; }
34
35template <> bool Widget::GetPersistentXmlProp(std::string prop, double &value) {
36 xmlChar *result = NULL;
37 result = xmlGetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
38
39 if (result != NULL) {
40 value = xmlXPathCastStringToNumber(result);
41 xmlFree(result);
42 return true;
43 } else {
44 return false;
45 }
46}
47
48template <> bool Widget::GetPersistentXmlProp(std::string prop, float &value) {
49 double tmp;
50 if (GetPersistentXmlProp<double>(prop, tmp)) {
51 value = tmp;
52 return true;
53 } else {
54 return false;
55 }
56}
57
58template <> bool Widget::GetPersistentXmlProp(std::string prop, bool &value) {
59 double tmp;
60 if (GetPersistentXmlProp<double>(prop, tmp)) {
61 value = tmp;
62 return true;
63 } else {
64 return false;
65 }
66}
67
68template <>
69bool Widget::GetPersistentXmlProp(std::string prop, int32_t &value) {
70 double tmp;
71 if (GetPersistentXmlProp<double>(prop, tmp)) {
72 value = tmp;
73 return true;
74 } else {
75 return false;
76 }
77}
78
79template <>
80bool Widget::GetPersistentXmlProp(std::string prop, uint16_t &value) {
81 double tmp;
82 if (GetPersistentXmlProp<double>(prop, tmp)) {
83 value = tmp;
84 return true;
85 } else {
86 return false;
87 }
88}
89
90template <>
91void Widget::SetVolatileXmlProp(string prop, string value, xmlNodePtr node) {
92 if (node == NULL)
93 node = pimpl_->send_node;
94 xmlSetProp(node, (xmlChar *)prop.c_str(), (xmlChar *)value.c_str());
95}
96
97template <>
98void Widget::SetVolatileXmlProp(string prop, char *value, xmlNodePtr node) {
99 if (node == NULL)
100 node = pimpl_->send_node;
101 xmlSetProp(node, (xmlChar *)prop.c_str(), (xmlChar *)value);
102}
103
104template <>
105void Widget::SetVolatileXmlProp(string prop, double value, xmlNodePtr node) {
106 xmlChar *xmlChar_value = xmlXPathCastNumberToString(value);
107
108 if (node == NULL)
109 node = pimpl_->send_node;
110 xmlSetProp(node, (xmlChar *)prop.c_str(), xmlChar_value);
111 xmlFree(xmlChar_value);
112}
113
114template <>
115void Widget::SetVolatileXmlProp(string prop, float value, xmlNodePtr node) {
116 SetVolatileXmlProp<double>(prop, value, node);
117}
118
119template <>
120void Widget::SetVolatileXmlProp(string prop, int32_t value, xmlNodePtr node) {
121 SetVolatileXmlProp<double>(prop, value, node);
122}
123
124template <>
125void Widget::SetVolatileXmlProp(string prop, uint32_t value, xmlNodePtr node) {
126 SetVolatileXmlProp<double>(prop, value, node);
127}
128
129template <>
130void Widget::SetVolatileXmlProp(string prop, int16_t value, xmlNodePtr node) {
131 SetVolatileXmlProp<double>(prop, value, node);
132}
133
134template <>
135void Widget::SetVolatileXmlProp(string prop, uint16_t value, xmlNodePtr node) {
136 SetVolatileXmlProp<double>(prop, value, node);
137}
138
139template <>
140void Widget::SetVolatileXmlProp(string prop, int8_t value, xmlNodePtr node) {
141 SetVolatileXmlProp<double>(prop, value, node);
142}
143
144template <>
145void Widget::SetVolatileXmlProp(string prop, uint8_t value, xmlNodePtr node) {
146 SetVolatileXmlProp<double>(prop, value, node);
147}
148
149template <>
150void Widget::SetVolatileXmlProp(string prop, bool value, xmlNodePtr node) {
151 SetVolatileXmlProp<double>(prop, value, node);
152}
153
154template <>
155void Widget::SetVolatileXmlProp(string prop, xmlChar *value, xmlNodePtr node) {
156 if (node == NULL)
157 node = pimpl_->send_node;
158 xmlSetProp(node, (xmlChar *)prop.c_str(), value);
159}
160
161template <>
162void Widget::SetVolatileXmlProp(string prop, DataType const &dataType,
163 xmlNodePtr node) {
164 if (node == NULL)
165 node = pimpl_->send_node;
166 xmlSetProp(node, (xmlChar *)prop.c_str(),
167 (xmlChar *)dataType.GetDescription().c_str());
168 /*
169 switch(dataType)
170 {
171 case io_data::Float:
172 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"float");
173 break;
174 case io_data::Int8_t:
175 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"int8_t");
176 break;
177 case io_data::Int16_t:
178 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"int16_t");
179 break;
180 }
181 */
182}
183
184template <> void Widget::SetPersistentXmlProp(std::string prop, double value) {
185 SetVolatileXmlProp(prop, value);
186 SetVolatileXmlProp(prop, value, pimpl_->file_node);
187}
188
189template <> void Widget::SetPersistentXmlProp(std::string prop, float value) {
190 SetVolatileXmlProp(prop, value);
191 SetVolatileXmlProp(prop, value, pimpl_->file_node);
192}
193
194template <> void Widget::SetPersistentXmlProp(std::string prop, int32_t value) {
195 SetVolatileXmlProp(prop, value);
196 SetVolatileXmlProp(prop, value, pimpl_->file_node);
197}
198
199template <>
200void Widget::SetPersistentXmlProp(std::string prop, uint16_t value) {
201 SetVolatileXmlProp(prop, value);
202 SetVolatileXmlProp(prop, value, pimpl_->file_node);
203}
204
205template <> void Widget::SetPersistentXmlProp(std::string prop, bool value) {
206 SetVolatileXmlProp(prop, value);
207 SetVolatileXmlProp(prop, value, pimpl_->file_node);
208}
209
210void Widget::SendXml(void) { pimpl_->SendXml(); }
211
212void Widget::setEnabled(bool status) { pimpl_->setEnabled(status); }
213
214bool Widget::isEnabled(void) const { return pimpl_->isenabled; }
215
216} // end namespace gui
217} // end namespace flair
Note: See TracBrowser for help on using the repository browser.