arcslibtoolkit.h
Go to the documentation of this file.
1 /*
2  name: include/arcs/arcslibtoolkit.h
3 
4  This file is part of ARCS - Augmented Reality Component System
5  (version 2-current), written by Jean-Yves Didier
6  for IBISC Laboratory (http://www.ibisc.univ-evry.fr)
7 
8  Copyright (C) 2013 Université d'Evry-Val d'Essonne
9 
10  This program is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Please send bugreports with examples or suggestions to
25  jean-yves.didier__at__ibisc.univ-evry.fr
26 */
27 
28 
29 #ifndef __ARCSLIBTOOLKIT_H__
30 #define __ARCSLIBTOOLKIT_H__
31 
32 
47 #include <QHash>
48 #include <QMetaObject>
49 
50 #include <arcs/arcsabstractfamily.h>
51 #include <arcs/arcsnativecomponent.h>
52 
53 
54 
56 
60 template<class X> class ARCSNativeComponentTemplate : public ARCSNativeComponent
61 {
62 protected:
64  virtual QObject* createObject(QObject* parent);
65  virtual void destroyObject(QObject* obj);
66  virtual QMetaObject getDescription();
67 };
68 
69 
70 
71 
72 
74 
83 {
84 public:
85  virtual ~ARCSTypeFactory() {}
87  virtual QString getTypeName() const =0;
89  virtual QString toString(QVariant v) = 0;
91  virtual QVariant parseString(QString s) = 0;
93  virtual bool isInternal() const { return false;}
94 };
95 
96 
98 
119 template<class X> class ARCSTypeFactoryTemplate : public ARCSTypeFactory
120 {
121 public:
122  virtual QString getTypeName() const = 0;
123  virtual QString toString(QVariant v);
124  virtual QVariant parseString(QString s);
125 
126 protected:
128  virtual X parse(QString s) = 0;
130  virtual QString serialize(X obj) = 0;
131 };
132 
133 
134 
135 #ifndef DLL_EXPORT
136 #ifdef WIN32
137 
141 #define DLL_EXPORT __declspec(dllexport)
142 template class DLL_EXPORT QHash<QString,ARCSNativeComponent*>;
143 template class DLL_EXPORT QHash<QString,ARCSAbstractFamily*>;
144 //template class DLL_EXPORT QHash<QString,ARCSFamilyFactory*>;
145 template class DLL_EXPORT QHash<QString,ARCSTypeFactory*>;
146 #else
147 #define DLL_EXPORT
148 #endif //WIN32
149 #endif //DLL_EXPORT
150 
151 
155 typedef QHash<QString,ARCSNativeComponent*> ARCSComponentMap;
156 
157 typedef QHash<QString,ARCSAbstractFamily*> ARCSFamilyMap;
158 
159 typedef QHash<QString,ARCSTypeFactory*> ARCSTypeMap;
160 
161 
166 template<class X>
168 {
169  return (new X(parent));
170 }
171 
173 template<class X>
175 {
176  X* xobj = dynamic_cast<X*>(obj);
177  if (xobj != NULL)
178  delete xobj;
179  else
180  delete obj;
181 }
182 
183 template<class X>
185 {
186  setType((X::staticMetaObject).className());
187  return X::staticMetaObject;
188 }
189 
190 template<class X>
192 {
194  return res;
195 }
196 
197 
198 template<class X>
200 {
201  return serialize(v.value<X>());
202 }
203 
204 template<class X>
206 {
207  QVariant var ;
208  var.setValue(parse(s));
209  return var;
210 }
211 
212 
213 #endif //__ARCSLIBTOOLKIT_H__
virtual QString toString(QVariant v)=0
Should return a string representation of data.
virtual bool isInternal() const
Tells wether the factory is internal or not (false by default).
virtual QString getTypeName() const =0
Should return the name of the type factory.
virtual QString getTypeName() const =0
Should return the name of the type factory.
Template class to implement type factories.
virtual QString serialize(X obj)=0
This function serializes an X object to a string.
virtual QObject * createObject(QObject *parent)
virtual void destroyObject(QObject *obj)
Dirty (Kids, don't do this at home !)
virtual ARCSNativeComponent * genuineClone()
Kage bunshin no jutsu !
QHash< QString, ARCSNativeComponent * > ARCSComponentMap
virtual QVariant parseString(QString s)=0
Should create data from their string representation.
virtual QVariant parseString(QString s)
Should create data from their string representation.
virtual QString toString(QVariant v)
Should return a string representation of data.
Generic class describing how type factories should be implemented.
Generic factories for each new native component type.
virtual X parse(QString s)=0
This function should return a X object according to its string representation.
Component representation of ARCS Native components.