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

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

corrections bugs checkpoint map

File size: 6.3 KB
RevLine 
[2]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[2]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
[15]23namespace flair {
24namespace gui {
[2]25
26using namespace core;
27
[15]28Widget::Widget(const Widget *parent, string name, string type)
29 : Object(parent, name, type) {
30 pimpl_ = new Widget_impl(this, parent, name, type);
[2]31}
32
[15]33Widget::~Widget() { delete pimpl_; }
[2]34
[15]35template <> bool Widget::GetPersistentXmlProp(std::string prop, double &value) {
36 xmlChar *result = NULL;
37 result = xmlGetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
[2]38
[15]39 if (result != NULL) {
40 value = xmlXPathCastStringToNumber(result);
41 xmlFree(result);
42 return true;
43 } else {
44 return false;
45 }
[2]46}
47
[15]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 }
[2]56}
57
[15]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 }
[2]66}
67
68template <>
[15]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 }
[2]77}
78
79template <>
[15]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 }
[2]88}
89
90template <>
[67]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 <>
[15]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());
[2]108}
109
110template <>
[15]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);
[2]115}
116
117template <>
[15]118void Widget::SetVolatileXmlProp(string prop, double value, xmlNodePtr node) {
119 xmlChar *xmlChar_value = xmlXPathCastNumberToString(value);
[2]120
[15]121 if (node == NULL)
122 node = pimpl_->send_node;
123 xmlSetProp(node, (xmlChar *)prop.c_str(), xmlChar_value);
124 xmlFree(xmlChar_value);
[2]125}
126
127template <>
[15]128void Widget::SetVolatileXmlProp(string prop, float value, xmlNodePtr node) {
129 SetVolatileXmlProp<double>(prop, value, node);
[2]130}
131
132template <>
[15]133void Widget::SetVolatileXmlProp(string prop, int32_t value, xmlNodePtr node) {
134 SetVolatileXmlProp<double>(prop, value, node);
[2]135}
136
137template <>
[15]138void Widget::SetVolatileXmlProp(string prop, uint32_t value, xmlNodePtr node) {
139 SetVolatileXmlProp<double>(prop, value, node);
[2]140}
141
142template <>
[15]143void Widget::SetVolatileXmlProp(string prop, int16_t value, xmlNodePtr node) {
144 SetVolatileXmlProp<double>(prop, value, node);
[2]145}
146
147template <>
[15]148void Widget::SetVolatileXmlProp(string prop, uint16_t value, xmlNodePtr node) {
149 SetVolatileXmlProp<double>(prop, value, node);
[2]150}
151
152template <>
[15]153void Widget::SetVolatileXmlProp(string prop, int8_t value, xmlNodePtr node) {
154 SetVolatileXmlProp<double>(prop, value, node);
[2]155}
156
157template <>
[15]158void Widget::SetVolatileXmlProp(string prop, uint8_t value, xmlNodePtr node) {
159 SetVolatileXmlProp<double>(prop, value, node);
[2]160}
161
162template <>
[15]163void Widget::SetVolatileXmlProp(string prop, bool value, xmlNodePtr node) {
164 SetVolatileXmlProp<double>(prop, value, node);
[2]165}
166
167template <>
[15]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);
[2]172}
173
174template <>
[15]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 */
[2]195}
196
[15]197template <> void Widget::SetPersistentXmlProp(std::string prop, double value) {
198 SetVolatileXmlProp(prop, value);
199 SetVolatileXmlProp(prop, value, pimpl_->file_node);
[2]200}
201
[15]202template <> void Widget::SetPersistentXmlProp(std::string prop, float value) {
203 SetVolatileXmlProp(prop, value);
204 SetVolatileXmlProp(prop, value, pimpl_->file_node);
[2]205}
206
[15]207template <> void Widget::SetPersistentXmlProp(std::string prop, int32_t value) {
208 SetVolatileXmlProp(prop, value);
209 SetVolatileXmlProp(prop, value, pimpl_->file_node);
[2]210}
211
212template <>
[15]213void Widget::SetPersistentXmlProp(std::string prop, uint16_t value) {
214 SetVolatileXmlProp(prop, value);
215 SetVolatileXmlProp(prop, value, pimpl_->file_node);
[2]216}
217
[15]218template <> void Widget::SetPersistentXmlProp(std::string prop, bool value) {
219 SetVolatileXmlProp(prop, value);
220 SetVolatileXmlProp(prop, value, pimpl_->file_node);
[2]221}
222
[67]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
[15]232void Widget::SendXml(void) { pimpl_->SendXml(); }
[2]233
[15]234void Widget::setEnabled(bool status) { pimpl_->setEnabled(status); }
[2]235
[15]236bool Widget::isEnabled(void) const { return pimpl_->isenabled; }
[2]237
238} // end namespace gui
239} // end namespace flair
Note: See TracBrowser for help on using the repository browser.