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

Last change on this file since 2 was 2, checked in by Sanahuja Guillaume, 6 years ago

flaircore

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