source: flair-src/branches/mavlink/lib/FlairCore/src/Widget.cpp@ 63

Last change on this file since 63 was 63, checked in by Thomas Fuhrmann, 6 years ago

Save config on target and save all locally are now working

File size: 6.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
23//remove, for tests
24#include <iostream>
25
26namespace flair {
27namespace gui {
28
29using namespace core;
30
31Widget::Widget(const Widget *parent, string name, string type)
32 : Object(parent, name, type) {
33 pimpl_ = new Widget_impl(this, parent, name, type);
34}
35
36Widget::~Widget() { delete pimpl_; }
37
38template <> bool Widget::GetPersistentXmlProp(std::string prop, double &value) {
39 xmlChar *result = NULL;
40 result = xmlGetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
41
42 if (result != NULL) {
43 value = xmlXPathCastStringToNumber(result);
44 xmlFree(result);
45 return true;
46 } else {
47 return false;
48 }
49}
50
51template <> bool Widget::GetPersistentXmlProp(std::string prop, float &value) {
52 double tmp;
53 if (GetPersistentXmlProp<double>(prop, tmp)) {
54 value = tmp;
55 return true;
56 } else {
57 return false;
58 }
59}
60
61template <> bool Widget::GetPersistentXmlProp(std::string prop, bool &value) {
62 double tmp;
63 if (GetPersistentXmlProp<double>(prop, tmp)) {
64 value = tmp;
65 return true;
66 } else {
67 return false;
68 }
69}
70
71template <>
72bool Widget::GetPersistentXmlProp(std::string prop, int32_t &value) {
73 double tmp;
74 if (GetPersistentXmlProp<double>(prop, tmp)) {
75 value = tmp;
76 return true;
77 } else {
78 return false;
79 }
80}
81
82template <>
83bool Widget::GetPersistentXmlProp(std::string prop, uint16_t &value) {
84 double tmp;
85 if (GetPersistentXmlProp<double>(prop, tmp)) {
86 value = tmp;
87 return true;
88 } else {
89 return false;
90 }
91}
92
93template <>
94bool Widget::GetPersistentXmlProp(std::string prop, std::string &value) {
95 xmlChar *result = NULL;
96 result = xmlGetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
97 if (result != NULL) {
98 value = std::string((char *)result);
99 xmlFree(result);
100 return true;
101 } else {
102 return false;
103 }
104}
105
106template <>
107void Widget::SetVolatileXmlProp(string prop, string value, xmlNodePtr node) {
108 if (node == NULL)
109 node = pimpl_->send_node;
110 xmlSetProp(node, (xmlChar *)prop.c_str(), (xmlChar *)value.c_str());
111}
112
113template <>
114void Widget::SetVolatileXmlProp(string prop, char *value, xmlNodePtr node) {
115 if (node == NULL)
116 node = pimpl_->send_node;
117 xmlSetProp(node, (xmlChar *)prop.c_str(), (xmlChar *)value);
118}
119
120template <>
121void Widget::SetVolatileXmlProp(string prop, double value, xmlNodePtr node) {
122 xmlChar *xmlChar_value = xmlXPathCastNumberToString(value);
123
124 if (node == NULL)
125 node = pimpl_->send_node;
126 xmlSetProp(node, (xmlChar *)prop.c_str(), xmlChar_value);
127 xmlFree(xmlChar_value);
128}
129
130template <>
131void Widget::SetVolatileXmlProp(string prop, float value, xmlNodePtr node) {
132 SetVolatileXmlProp<double>(prop, value, node);
133}
134
135template <>
136void Widget::SetVolatileXmlProp(string prop, int32_t value, xmlNodePtr node) {
137 SetVolatileXmlProp<double>(prop, value, node);
138}
139
140template <>
141void Widget::SetVolatileXmlProp(string prop, uint32_t value, xmlNodePtr node) {
142 SetVolatileXmlProp<double>(prop, value, node);
143}
144
145template <>
146void Widget::SetVolatileXmlProp(string prop, int16_t value, xmlNodePtr node) {
147 SetVolatileXmlProp<double>(prop, value, node);
148}
149
150template <>
151void Widget::SetVolatileXmlProp(string prop, uint16_t value, xmlNodePtr node) {
152 SetVolatileXmlProp<double>(prop, value, node);
153}
154
155template <>
156void Widget::SetVolatileXmlProp(string prop, int8_t value, xmlNodePtr node) {
157 SetVolatileXmlProp<double>(prop, value, node);
158}
159
160template <>
161void Widget::SetVolatileXmlProp(string prop, uint8_t value, xmlNodePtr node) {
162 SetVolatileXmlProp<double>(prop, value, node);
163}
164
165template <>
166void Widget::SetVolatileXmlProp(string prop, bool value, xmlNodePtr node) {
167 SetVolatileXmlProp<double>(prop, value, node);
168}
169
170template <>
171void Widget::SetVolatileXmlProp(string prop, xmlChar *value, xmlNodePtr node) {
172 if (node == NULL)
173 node = pimpl_->send_node;
174 xmlSetProp(node, (xmlChar *)prop.c_str(), value);
175}
176
177template <>
178void Widget::SetVolatileXmlProp(string prop, DataType const &dataType,
179 xmlNodePtr node) {
180 if (node == NULL)
181 node = pimpl_->send_node;
182 xmlSetProp(node, (xmlChar *)prop.c_str(),
183 (xmlChar *)dataType.GetDescription().c_str());
184 /*
185 switch(dataType)
186 {
187 case io_data::Float:
188 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"float");
189 break;
190 case io_data::Int8_t:
191 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"int8_t");
192 break;
193 case io_data::Int16_t:
194 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"int16_t");
195 break;
196 }
197 */
198}
199
200template <> void Widget::SetPersistentXmlProp(std::string prop, double value) {
201 SetVolatileXmlProp(prop, value);
202 SetVolatileXmlProp(prop, value, pimpl_->file_node);
203}
204
205template <> void Widget::SetPersistentXmlProp(std::string prop, float value) {
206 SetVolatileXmlProp(prop, value);
207 SetVolatileXmlProp(prop, value, pimpl_->file_node);
208}
209
210template <> void Widget::SetPersistentXmlProp(std::string prop, int32_t value) {
211 SetVolatileXmlProp(prop, value);
212 SetVolatileXmlProp(prop, value, pimpl_->file_node);
213}
214
215template <>
216void Widget::SetPersistentXmlProp(std::string prop, uint16_t value) {
217 SetVolatileXmlProp(prop, value);
218 SetVolatileXmlProp(prop, value, pimpl_->file_node);
219}
220
221template <> void Widget::SetPersistentXmlProp(std::string prop, bool value) {
222 SetVolatileXmlProp(prop, value);
223 SetVolatileXmlProp(prop, value, pimpl_->file_node);
224}
225
226template <> void Widget::SetPersistentXmlProp(std::string prop, std::string value) {
227 SetVolatileXmlProp(prop, value);
228 SetVolatileXmlProp(prop, value, pimpl_->file_node);
229}
230
231void Widget::UnsetPersistentXmlProp(std::string prop) {
232 xmlNodePtr Node = pimpl_->file_node;
233
234 for(xmlAttrPtr attr = Node->properties; NULL != attr; attr = attr->next)
235 {
236 std::cout << attr->name << std::endl;
237 }
238
239 int ret = xmlUnsetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
240 std::cout << "UnsetPersistentXmlProp, item= " << prop << "result = " << ret << std::endl;
241
242 for(xmlAttrPtr attr = Node->properties; NULL != attr; attr = attr->next)
243 {
244 std::cout << attr->name << std::endl;
245 }
246}
247
248void Widget::SendXml(void) { pimpl_->SendXml(); }
249
250void Widget::setEnabled(bool status) { pimpl_->setEnabled(status); }
251
252bool Widget::isEnabled(void) const { return pimpl_->isenabled; }
253
254} // end namespace gui
255} // end namespace flair
Note: See TracBrowser for help on using the repository browser.