qtmobility/src/sensors/make_sensor.pl
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 8 71781823f776
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
   138 public:
   138 public:
   139     qreal myprop() const;
   139     qreal myprop() const;
   140     void setMyprop(qreal myprop);
   140     void setMyprop(qreal myprop);
   141 };
   141 };
   142 
   142 
   143 // begin generated code
       
   144 // end generated code
       
   145 
       
   146 QTM_END_NAMESPACE
       
   147 
       
   148 #endif
       
   149 ';
       
   150     close OUT;
       
   151 }
       
   152 
       
   153 if (-e $header) {
       
   154     open IN, "$header" or die $!;
       
   155     my @data = <IN>;
       
   156     close IN;
       
   157     my @tags = grep /^\/\/ (begin|end) generated code/, @data;
       
   158     if (scalar(@tags) == 2 &&
       
   159     $tags[0] eq "// begin generated code\n" &&
       
   160     $tags[1] eq "// end generated code\n") {
       
   161         print "Updating generated code in $header\n";
       
   162         open OUT, ">$header" or die $!;
       
   163         my $skip = 0;
       
   164         for (@data) {
       
   165             if ($_ eq $tags[0]) {
       
   166                 print OUT $_;
       
   167                 print OUT '
       
   168 class Q_SENSORS_EXPORT '.$filter.' : public QSensorFilter
   143 class Q_SENSORS_EXPORT '.$filter.' : public QSensorFilter
   169 {
   144 {
   170 public:
   145 public:
   171     virtual bool filter('.$reading.' *reading) = 0;
   146     virtual bool filter('.$reading.' *reading) = 0;
   172 private:
   147 private:
   181     { setType('.$sensor.'::type); }
   156     { setType('.$sensor.'::type); }
   182     virtual ~'.$sensor.'() {}
   157     virtual ~'.$sensor.'() {}
   183     '.$reading.' *reading() const { return static_cast<'.$reading.'*>(QSensor::reading()); }
   158     '.$reading.' *reading() const { return static_cast<'.$reading.'*>(QSensor::reading()); }
   184     static const char *type;
   159     static const char *type;
   185 };
   160 };
       
   161 
       
   162 QTM_END_NAMESPACE
       
   163 
       
   164 #endif
   186 ';
   165 ';
   187                 $skip = 1;
   166     close OUT;
   188             }
       
   189             if ($_ eq $tags[1]) {
       
   190                 $skip = 0;
       
   191             }
       
   192             if (!$skip) {
       
   193                 print OUT $_;
       
   194             }
       
   195         }
       
   196     }
       
   197 }
   167 }
   198 
   168 
   199 if (! -e $source) {
   169 if (! -e $source) {
   200     print "Creating $source\n";
   170     print "Creating $source\n";
   201     open OUT, ">$source" or die $!;
   171     open OUT, ">$source" or die $!;
   242     d->myprop = myprop;
   212     d->myprop = myprop;
   243 }
   213 }
   244 
   214 
   245 // =====================================================================
   215 // =====================================================================
   246 
   216 
   247 // begin generated code
   217 /*!
   248 // end generated code
   218     \class '.$filter.'
       
   219     \ingroup sensors_filter
       
   220 
       
   221     \preliminary
       
   222     \brief The '.$filter.' class is a convenience wrapper around QSensorFilter.
       
   223 
       
   224     The only difference is that the filter() method features a pointer to '.$reading.'
       
   225     instead of QSensorReading.
       
   226 */
       
   227 
       
   228 /*!
       
   229     \fn '.$filter.'::filter('.$reading.' *reading)
       
   230 
       
   231     Called when \a reading changes. Returns false to prevent the reading from propagating.
       
   232 
       
   233     \sa QSensorFilter::filter()
       
   234 */
       
   235 
       
   236 const char *'.$sensor.'::type("'.$sensor.'");
       
   237 
       
   238 /*!
       
   239     \class '.$sensor.'
       
   240     \ingroup sensors_type
       
   241 
       
   242     \preliminary
       
   243     \brief The '.$sensor.' class is a convenience wrapper around QSensor.
       
   244 
       
   245     The only behavioural difference is that this class sets the type properly.
       
   246 
       
   247     This class also features a reading() function that returns a '.$reading.' instead of a QSensorReading.
       
   248 
       
   249     For details about how the sensor works, see \l '.$reading.'.
       
   250 
       
   251     \sa '.$reading.'
       
   252 */
       
   253 
       
   254 /*!
       
   255     \fn '.$sensor.'::'.$sensor.'(QObject *parent)
       
   256 
       
   257     Construct the sensor as a child of \a parent.
       
   258 */
       
   259 
       
   260 /*!
       
   261     \fn '.$sensor.'::~'.$sensor.'()
       
   262 
       
   263     Destroy the sensor. Stops the sensor if it has not already been stopped.
       
   264 */
       
   265 
       
   266 /*!
       
   267     \fn '.$sensor.'::reading() const
       
   268 
       
   269     Returns the reading class for this sensor.
       
   270 
       
   271     \sa QSensor::reading()
       
   272 */
   249 
   273 
   250 #include "moc_'.$source.'"
   274 #include "moc_'.$source.'"
   251 QTM_END_NAMESPACE
   275 QTM_END_NAMESPACE
   252 ';
   276 ';
   253     close OUT;
   277     close OUT;
   254 }
   278 }
   255 
   279 
   256 if (-e $source) {
       
   257     open IN, "$source" or die $!;
       
   258     my @data = <IN>;
       
   259     close IN;
       
   260     my @tags = grep /^\/\/ (begin|end) generated code/, @data;
       
   261     if (scalar(@tags) == 2 &&
       
   262     $tags[0] eq "// begin generated code\n" &&
       
   263     $tags[1] eq "// end generated code\n") {
       
   264         print "Updating generated code in $source\n";
       
   265         open OUT, ">$source" or die $!;
       
   266         my $skip = 0;
       
   267         for (@data) {
       
   268             if ($_ eq $tags[0]) {
       
   269                 print OUT $_;
       
   270                 print OUT '
       
   271 /*!
       
   272     \class '.$filter.'
       
   273     \ingroup sensors_filter
       
   274 
       
   275     \preliminary
       
   276     \brief The '.$filter.' class is a convenience wrapper around QSensorFilter.
       
   277 
       
   278     The only difference is that the filter() method features a pointer to '.$reading.'
       
   279     instead of QSensorReading.
       
   280 */
       
   281 
       
   282 /*!
       
   283     \fn '.$filter.'::filter('.$reading.' *reading)
       
   284 
       
   285     Called when \a reading changes. Returns false to prevent the reading from propagating.
       
   286 
       
   287     \sa QSensorFilter::filter()
       
   288 */
       
   289 
       
   290 const char *'.$sensor.'::type("'.$sensor.'");
       
   291 
       
   292 /*!
       
   293     \class '.$sensor.'
       
   294     \ingroup sensors_type
       
   295 
       
   296     \preliminary
       
   297     \brief The '.$sensor.' class is a convenience wrapper around QSensor.
       
   298 
       
   299     The only behavioural difference is that this class sets the type properly.
       
   300 
       
   301     This class also features a reading() function that returns a '.$reading.' instead of a QSensorReading.
       
   302 
       
   303     For details about how the sensor works, see \l '.$reading.'.
       
   304 
       
   305     \sa '.$reading.'
       
   306 */
       
   307 
       
   308 /*!
       
   309     \fn '.$sensor.'::'.$sensor.'(QObject *parent)
       
   310 
       
   311     Construct the sensor as a child of \a parent.
       
   312 */
       
   313 
       
   314 /*!
       
   315     \fn '.$sensor.'::~'.$sensor.'()
       
   316 
       
   317     Destroy the sensor. Stops the sensor if it has not already been stopped.
       
   318 */
       
   319 
       
   320 /*!
       
   321     \fn '.$sensor.'::reading() const
       
   322 
       
   323     Returns the reading class for this sensor.
       
   324 
       
   325     \sa QSensor::reading()
       
   326 */
       
   327 ';
       
   328                 $skip = 1;
       
   329             }
       
   330             if ($_ eq $tags[1]) {
       
   331                 $skip = 0;
       
   332             }
       
   333             if (!$skip) {
       
   334                 print OUT $_;
       
   335             }
       
   336         }
       
   337     }
       
   338 }
       
   339 
       
   340 
       
   341 exit 0;
   280 exit 0;
   342 
   281 
   343 
   282 
   344 sub get_arg
   283 sub get_arg
   345 {
   284 {