|
1 #!/usr/bin/perl |
|
2 ############################################################################# |
|
3 ## |
|
4 ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
5 ## All rights reserved. |
|
6 ## Contact: Nokia Corporation (qt-info@nokia.com) |
|
7 ## |
|
8 ## This file is part of the Qt Mobility Components. |
|
9 ## |
|
10 ## $QT_BEGIN_LICENSE:LGPL$ |
|
11 ## No Commercial Usage |
|
12 ## This file contains pre-release code and may not be distributed. |
|
13 ## You may use this file in accordance with the terms and conditions |
|
14 ## contained in the Technology Preview License Agreement accompanying |
|
15 ## this package. |
|
16 ## |
|
17 ## GNU Lesser General Public License Usage |
|
18 ## Alternatively, this file may be used under the terms of the GNU Lesser |
|
19 ## General Public License version 2.1 as published by the Free Software |
|
20 ## Foundation and appearing in the file LICENSE.LGPL included in the |
|
21 ## packaging of this file. Please review the following information to |
|
22 ## ensure the GNU Lesser General Public License version 2.1 requirements |
|
23 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
24 ## |
|
25 ## In addition, as a special exception, Nokia gives you certain additional |
|
26 ## rights. These rights are described in the Nokia Qt LGPL Exception |
|
27 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
28 ## |
|
29 ## If you have questions regarding the use of this file, please contact |
|
30 ## Nokia at qt-info@nokia.com. |
|
31 ## |
|
32 ## |
|
33 ## |
|
34 ## |
|
35 ## |
|
36 ## |
|
37 ## |
|
38 ## |
|
39 ## $QT_END_LICENSE$ |
|
40 ## |
|
41 ############################################################################# |
|
42 |
|
43 use strict; |
|
44 use warnings; |
|
45 |
|
46 use Carp; |
|
47 local $Carp::CarpLevel;# = 1; |
|
48 |
|
49 my $sensor = get_arg(); |
|
50 my $sensorbase = $sensor; |
|
51 $sensorbase =~ s/Sensor$//; |
|
52 my $reading = $sensorbase.'Reading'; |
|
53 my $reading_private = $reading.'Private'; |
|
54 my $filter = $sensorbase.'Filter'; |
|
55 |
|
56 my $filebase; |
|
57 eval { |
|
58 $filebase = get_arg(); |
|
59 }; |
|
60 if ($@) { |
|
61 $filebase = lc($sensor); |
|
62 } |
|
63 |
|
64 my $pheader = $filebase."_p.h"; |
|
65 my $header = $filebase.".h"; |
|
66 my $source = $filebase.".cpp"; |
|
67 |
|
68 my $pguard = uc($pheader); |
|
69 $pguard =~ s/\./_/g; |
|
70 |
|
71 my $guard = uc($header); |
|
72 $guard =~ s/\./_/g; |
|
73 |
|
74 if (! -e $pheader) { |
|
75 print "Creating $pheader\n"; |
|
76 open OUT, ">$pheader" or die $!; |
|
77 print OUT ' |
|
78 #ifndef '.$pguard.' |
|
79 #define '.$pguard.' |
|
80 |
|
81 // |
|
82 // W A R N I N G |
|
83 // ------------- |
|
84 // |
|
85 // This file is not part of the Qt API. It exists purely as an |
|
86 // implementation detail. This header file may change from version to |
|
87 // version without notice, or even be removed. |
|
88 // |
|
89 // We mean it. |
|
90 // |
|
91 |
|
92 QTM_BEGIN_NAMESPACE |
|
93 |
|
94 class '.$reading_private.' |
|
95 { |
|
96 public: |
|
97 '.$reading_private.'() |
|
98 : myprop(0) |
|
99 { |
|
100 } |
|
101 |
|
102 /* |
|
103 * Note that this class is copied so you may need to implement |
|
104 * a copy constructor if you have complex types or pointers |
|
105 * as values. |
|
106 */ |
|
107 |
|
108 qreal myprop; |
|
109 }; |
|
110 |
|
111 QTM_END_NAMESPACE |
|
112 |
|
113 #endif |
|
114 '; |
|
115 close OUT; |
|
116 } |
|
117 |
|
118 if (! -e $header) { |
|
119 print "Creating $header\n"; |
|
120 open OUT, ">$header" or die $!; |
|
121 print OUT ' |
|
122 #ifndef '.$guard.' |
|
123 #define '.$guard.' |
|
124 |
|
125 #include <qsensor.h> |
|
126 |
|
127 QTM_BEGIN_NAMESPACE |
|
128 |
|
129 class '.$reading_private.'; |
|
130 |
|
131 class Q_SENSORS_EXPORT '.$reading.' : public QSensorReading |
|
132 { |
|
133 Q_OBJECT |
|
134 Q_PROPERTY(qreal myprop READ myprop) |
|
135 DECLARE_READING('.$reading.') |
|
136 public: |
|
137 qreal myprop() const; |
|
138 void setMyprop(qreal myprop); |
|
139 }; |
|
140 |
|
141 class Q_SENSORS_EXPORT '.$filter.' : public QSensorFilter |
|
142 { |
|
143 public: |
|
144 virtual bool filter('.$reading.' *reading) = 0; |
|
145 private: |
|
146 bool filter(QSensorReading *reading) { return filter(static_cast<'.$reading.'*>(reading)); } |
|
147 }; |
|
148 |
|
149 class Q_SENSORS_EXPORT '.$sensor.' : public QSensor |
|
150 { |
|
151 Q_OBJECT |
|
152 public: |
|
153 explicit '.$sensor.'(QObject *parent = 0) : QSensor(parent) |
|
154 { setType('.$sensor.'::type); } |
|
155 virtual ~'.$sensor.'() {} |
|
156 '.$reading.' *reading() const { return static_cast<'.$reading.'*>(QSensor::reading()); } |
|
157 static char const * const type; |
|
158 }; |
|
159 |
|
160 QTM_END_NAMESPACE |
|
161 |
|
162 #endif |
|
163 '; |
|
164 close OUT; |
|
165 } |
|
166 |
|
167 if (! -e $source) { |
|
168 print "Creating $source\n"; |
|
169 open OUT, ">$source" or die $!; |
|
170 print OUT ' |
|
171 #include <'.$header.'> |
|
172 #include "'.$pheader.'" |
|
173 |
|
174 QTM_BEGIN_NAMESPACE |
|
175 |
|
176 IMPLEMENT_READING('.$reading.') |
|
177 |
|
178 /*! |
|
179 \class '.$reading.' |
|
180 \ingroup sensors_reading |
|
181 |
|
182 \brief The '.$reading.' class holds readings from the [X] sensor. |
|
183 |
|
184 [Fill this out] |
|
185 |
|
186 \section2 '.$reading.' Units |
|
187 |
|
188 [Fill this out] |
|
189 */ |
|
190 |
|
191 /*! |
|
192 \property '.$reading.'::myprop |
|
193 \brief [what does it hold?] |
|
194 |
|
195 [What are the units?] |
|
196 \sa {'.$reading.' Units} |
|
197 */ |
|
198 |
|
199 qreal '.$reading.'::myprop() const |
|
200 { |
|
201 return d->myprop; |
|
202 } |
|
203 |
|
204 /*! |
|
205 Sets [what?] to \a myprop. |
|
206 */ |
|
207 void '.$reading.'::setMyprop(qreal myprop) |
|
208 { |
|
209 d->myprop = myprop; |
|
210 } |
|
211 |
|
212 // ===================================================================== |
|
213 |
|
214 /*! |
|
215 \class '.$filter.' |
|
216 \ingroup sensors_filter |
|
217 |
|
218 \brief The '.$filter.' class is a convenience wrapper around QSensorFilter. |
|
219 |
|
220 The only difference is that the filter() method features a pointer to '.$reading.' |
|
221 instead of QSensorReading. |
|
222 */ |
|
223 |
|
224 /*! |
|
225 \fn '.$filter.'::filter('.$reading.' *reading) |
|
226 |
|
227 Called when \a reading changes. Returns false to prevent the reading from propagating. |
|
228 |
|
229 \sa QSensorFilter::filter() |
|
230 */ |
|
231 |
|
232 char const * const '.$sensor.'::type("'.$sensor.'"); |
|
233 |
|
234 /*! |
|
235 \class '.$sensor.' |
|
236 \ingroup sensors_type |
|
237 |
|
238 \brief The '.$sensor.' class is a convenience wrapper around QSensor. |
|
239 |
|
240 The only behavioural difference is that this class sets the type properly. |
|
241 |
|
242 This class also features a reading() function that returns a '.$reading.' instead of a QSensorReading. |
|
243 |
|
244 For details about how the sensor works, see \l '.$reading.'. |
|
245 |
|
246 \sa '.$reading.' |
|
247 */ |
|
248 |
|
249 /*! |
|
250 \fn '.$sensor.'::'.$sensor.'(QObject *parent) |
|
251 |
|
252 Construct the sensor as a child of \a parent. |
|
253 */ |
|
254 |
|
255 /*! |
|
256 \fn '.$sensor.'::~'.$sensor.'() |
|
257 |
|
258 Destroy the sensor. Stops the sensor if it has not already been stopped. |
|
259 */ |
|
260 |
|
261 /*! |
|
262 \fn '.$sensor.'::reading() const |
|
263 |
|
264 Returns the reading class for this sensor. |
|
265 |
|
266 \sa QSensor::reading() |
|
267 */ |
|
268 |
|
269 #include "moc_'.$source.'" |
|
270 QTM_END_NAMESPACE |
|
271 '; |
|
272 close OUT; |
|
273 } |
|
274 |
|
275 exit 0; |
|
276 |
|
277 |
|
278 sub get_arg |
|
279 { |
|
280 if (scalar(@ARGV) == 0) { |
|
281 croak "Missing arg(s)"; |
|
282 } |
|
283 return shift(@ARGV); |
|
284 } |
|
285 |