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

Last change on this file since 202 was 67, checked in by Sanahuja Guillaume, 8 years ago

corrections bugs checkpoint map

File size: 6.3 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 <>
91bool Widget::GetPersistentXmlProp(std::string prop, std::string &value) {
92 xmlChar *result = NULL;
93 result = xmlGetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
94 if (result != NULL) {
95 value = std::string((char *)result);
96 xmlFree(result);
97 return true;
98 } else {
99 return false;
100 }
101}
102
103template <>
104void Widget::SetVolatileXmlProp(string prop, string value, xmlNodePtr node) {
105 if (node == NULL)
106 node = pimpl_->send_node;
107 xmlSetProp(node, (xmlChar *)prop.c_str(), (xmlChar *)value.c_str());
108}
109
110template <>
111void Widget::SetVolatileXmlProp(string prop, char *value, xmlNodePtr node) {
112 if (node == NULL)
113 node = pimpl_->send_node;
114 xmlSetProp(node, (xmlChar *)prop.c_str(), (xmlChar *)value);
115}
116
117template <>
118void Widget::SetVolatileXmlProp(string prop, double value, xmlNodePtr node) {
119 xmlChar *xmlChar_value = xmlXPathCastNumberToString(value);
120
121 if (node == NULL)
122 node = pimpl_->send_node;
123 xmlSetProp(node, (xmlChar *)prop.c_str(), xmlChar_value);
124 xmlFree(xmlChar_value);
125}
126
127template <>
128void Widget::SetVolatileXmlProp(string prop, float value, xmlNodePtr node) {
129 SetVolatileXmlProp<double>(prop, value, node);
130}
131
132template <>
133void Widget::SetVolatileXmlProp(string prop, int32_t value, xmlNodePtr node) {
134 SetVolatileXmlProp<double>(prop, value, node);
135}
136
137template <>
138void Widget::SetVolatileXmlProp(string prop, uint32_t value, xmlNodePtr node) {
139 SetVolatileXmlProp<double>(prop, value, node);
140}
141
142template <>
143void Widget::SetVolatileXmlProp(string prop, int16_t value, xmlNodePtr node) {
144 SetVolatileXmlProp<double>(prop, value, node);
145}
146
147template <>
148void Widget::SetVolatileXmlProp(string prop, uint16_t value, xmlNodePtr node) {
149 SetVolatileXmlProp<double>(prop, value, node);
150}
151
152template <>
153void Widget::SetVolatileXmlProp(string prop, int8_t value, xmlNodePtr node) {
154 SetVolatileXmlProp<double>(prop, value, node);
155}
156
157template <>
158void Widget::SetVolatileXmlProp(string prop, uint8_t value, xmlNodePtr node) {
159 SetVolatileXmlProp<double>(prop, value, node);
160}
161
162template <>
163void Widget::SetVolatileXmlProp(string prop, bool value, xmlNodePtr node) {
164 SetVolatileXmlProp<double>(prop, value, node);
165}
166
167template <>
168void Widget::SetVolatileXmlProp(string prop, xmlChar *value, xmlNodePtr node) {
169 if (node == NULL)
170 node = pimpl_->send_node;
171 xmlSetProp(node, (xmlChar *)prop.c_str(), value);
172}
173
174template <>
175void Widget::SetVolatileXmlProp(string prop, DataType const &dataType,
176 xmlNodePtr node) {
177 if (node == NULL)
178 node = pimpl_->send_node;
179 xmlSetProp(node, (xmlChar *)prop.c_str(),
180 (xmlChar *)dataType.GetDescription().c_str());
181 /*
182 switch(dataType)
183 {
184 case io_data::Float:
185 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"float");
186 break;
187 case io_data::Int8_t:
188 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"int8_t");
189 break;
190 case io_data::Int16_t:
191 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"int16_t");
192 break;
193 }
194 */
195}
196
197template <> void Widget::SetPersistentXmlProp(std::string prop, double value) {
198 SetVolatileXmlProp(prop, value);
199 SetVolatileXmlProp(prop, value, pimpl_->file_node);
200}
201
202template <> void Widget::SetPersistentXmlProp(std::string prop, float value) {
203 SetVolatileXmlProp(prop, value);
204 SetVolatileXmlProp(prop, value, pimpl_->file_node);
205}
206
207template <> void Widget::SetPersistentXmlProp(std::string prop, int32_t value) {
208 SetVolatileXmlProp(prop, value);
209 SetVolatileXmlProp(prop, value, pimpl_->file_node);
210}
211
212template <>
213void Widget::SetPersistentXmlProp(std::string prop, uint16_t value) {
214 SetVolatileXmlProp(prop, value);
215 SetVolatileXmlProp(prop, value, pimpl_->file_node);
216}
217
218template <> void Widget::SetPersistentXmlProp(std::string prop, bool value) {
219 SetVolatileXmlProp(prop, value);
220 SetVolatileXmlProp(prop, value, pimpl_->file_node);
221}
222
223template <> void Widget::SetPersistentXmlProp(std::string prop, std::string value) {
224 SetVolatileXmlProp(prop, value);
225 SetVolatileXmlProp(prop, value, pimpl_->file_node);
226}
227
228void Widget::UnsetPersistentXmlProp(std::string prop) {
229 xmlUnsetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
230}
231
232void Widget::SendXml(void) { pimpl_->SendXml(); }
233
234void Widget::setEnabled(bool status) { pimpl_->setEnabled(status); }
235
236bool Widget::isEnabled(void) const { return pimpl_->isenabled; }
237
238} // end namespace gui
239} // end namespace flair
Note: See TracBrowser for help on using the repository browser.