X-Plane Remote Access Plugin and Client Library
SetDataRefTask.h
1 // Copyright (c) 2013 by István Váradi
2 
3 // This file is part of XPLRA, a remote-access plugin for X-Plane
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 
8 // 1. Redistributions of source code must retain the above copyright notice, this
9 // list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 // The views and conclusions contained in the software and documentation are those
26 // of the authors and should not be interpreted as representing official policies,
27 // either expressed or implied, of the FreeBSD Project.
28 
29 #ifndef XPLRA_SETDATAREFTASK_H
30 #define XPLRA_SETDATAREFTASK_H
31 //------------------------------------------------------------------------------
32 
33 #include "DataRefTask.h"
34 
35 #include <hu/varadiistvan/scpl/io/DataStream.h>
36 
37 //------------------------------------------------------------------------------
38 
39 namespace xplra {
40 
41 //------------------------------------------------------------------------------
42 
55 {
56 public:
68  static SetDataRefTask* create(uint8_t& result, hu::varadiistvan::scpl::io::DataStream& stream);
69 
73  SetDataRefTask(const std::string& name);
74 
78  SetDataRefTask(XPLMDataRef dataRef);
79 
83  virtual void readValue(hu::varadiistvan::scpl::io::DataStream& stream) = 0;
84 };
85 
86 //------------------------------------------------------------------------------
87 //------------------------------------------------------------------------------
88 
96 template <typename T, class ConcreteClass>
98 {
99 protected:
103  T value;
104 
105 public:
110  SetScalarDataRefTask(const std::string& name);
111 
117 
118 protected:
122  virtual void process();
123 };
124 
125 //------------------------------------------------------------------------------
126 //------------------------------------------------------------------------------
127 
132  public SetScalarDataRefTask<int, SetIntDataRefTask>
133 {
134 public:
138  static void setData(XPLMDataRef dataRef, int value);
139 
143  SetIntDataRefTask(const std::string& name);
144 
148  SetIntDataRefTask(XPLMDataRef dataRef);
149 
153  virtual void readValue(hu::varadiistvan::scpl::io::DataStream& stream);
154 };
155 
156 //------------------------------------------------------------------------------
157 //------------------------------------------------------------------------------
158 
163  public SetScalarDataRefTask<float, SetFloatDataRefTask>
164 {
165 public:
169  static void setData(XPLMDataRef dataRef, float value);
170 
174  SetFloatDataRefTask(const std::string& name);
175 
179  SetFloatDataRefTask(XPLMDataRef dataRef);
180 
184  virtual void readValue(hu::varadiistvan::scpl::io::DataStream& stream);
185 };
186 
187 //------------------------------------------------------------------------------
188 //------------------------------------------------------------------------------
189 
194  public SetScalarDataRefTask<double, SetDoubleDataRefTask>
195 {
196 public:
200  static void setData(XPLMDataRef dataRef, double value);
201 
205  SetDoubleDataRefTask(const std::string& name);
206 
210  SetDoubleDataRefTask(XPLMDataRef dataRef);
211 
215  virtual void readValue(hu::varadiistvan::scpl::io::DataStream& stream);
216 };
217 
218 //------------------------------------------------------------------------------
219 //------------------------------------------------------------------------------
220 
228 template <typename T, class ConcreteClass>
230 {
231 private:
235  int count;
236 
240  int offset;
241 
245  T* value;
246 
247 public:
255  SetArrayDataRefTask(const std::string& name, int count, int offset = 0);
256 
263  SetArrayDataRefTask(XPLMDataRef dataRef, int count, int offset = 0);
264 
269 
273  virtual void readValue(hu::varadiistvan::scpl::io::DataStream& stream);
274 
275 protected:
279  virtual void process();
280 };
281 
282 //------------------------------------------------------------------------------
283 //------------------------------------------------------------------------------
284 
289  public SetArrayDataRefTask<int, SetIntArrayDataRefTask>
290 {
291 public:
295  static void setData(XPLMDataRef dataRef, int* value, int count, int offset);
296 
300  SetIntArrayDataRefTask(const std::string& name, int count, int offset = 0);
301 
305  SetIntArrayDataRefTask(XPLMDataRef dataRef, int count, int offset = 0);
306 };
307 
308 //------------------------------------------------------------------------------
309 //------------------------------------------------------------------------------
310 
316  public SetArrayDataRefTask<float, SetFloatArrayDataRefTask>
317 {
318 public:
322  static void setData(XPLMDataRef dataRef, float* value, int count, int offset);
323 
327  SetFloatArrayDataRefTask(const std::string& name, int count, int offset = 0);
328 
332  SetFloatArrayDataRefTask(XPLMDataRef dataRef, int count, int offset = 0);
333 };
334 
335 //------------------------------------------------------------------------------
336 //------------------------------------------------------------------------------
337 
342  public SetArrayDataRefTask<unsigned char, SetByteArrayDataRefTask>
343 {
344 public:
348  static void setData(XPLMDataRef dataRef, unsigned char* value,
349  int count, int offset);
350 
354  SetByteArrayDataRefTask(const std::string& name, int count, int offset = 0);
355 
359  SetByteArrayDataRefTask(XPLMDataRef dataRef, int count, int offset = 0);
360 };
361 
362 //------------------------------------------------------------------------------
363 // Template definitions
364 //------------------------------------------------------------------------------
365 
366 template <typename T, class ConcreteClass>
368 SetScalarDataRefTask(const std::string& name) :
369  SetDataRefTask(name)
370 {
371 }
372 
373 //------------------------------------------------------------------------------
374 
375 template <typename T, class ConcreteClass>
377 SetScalarDataRefTask(XPLMDataRef dataRef) :
378  SetDataRefTask(dataRef)
379 {
380 }
381 
382 //------------------------------------------------------------------------------
383 
384 template <typename T, class ConcreteClass>
386 {
387  ConcreteClass::setData(getDataRef(), value);
388 }
389 
390 //------------------------------------------------------------------------------
391 //------------------------------------------------------------------------------
392 
393 template <typename T, class ConcreteClass>
395 SetArrayDataRefTask(const std::string& name, int count, int offset) :
396  SetDataRefTask(name),
397  count(count),
398  offset(offset),
399  value(new T[count])
400 {
401 }
402 
403 //------------------------------------------------------------------------------
404 
405 template <typename T, class ConcreteClass>
407 SetArrayDataRefTask(XPLMDataRef dataRef, int count, int offset) :
408  SetDataRefTask(dataRef),
409  count(count),
410  offset(offset),
411  value(new T[count])
412 {
413 }
414 
415 //------------------------------------------------------------------------------
416 
417 template <typename T, class ConcreteClass>
419 {
420  delete [] value;
421 }
422 
423 //------------------------------------------------------------------------------
424 
425 template <typename T, class ConcreteClass>
427 readValue(hu::varadiistvan::scpl::io::DataStream& stream)
428 {
429  stream.read(value, count * sizeof(T));
430 }
431 
432 //------------------------------------------------------------------------------
433 
434 template <typename T, class ConcreteClass>
436 {
437  ConcreteClass::setData(getDataRef(), value, count, offset);
438 }
439 
440 //------------------------------------------------------------------------------
441 // Inline definitions
442 //------------------------------------------------------------------------------
443 
444 inline SetDataRefTask::SetDataRefTask(const std::string& name) :
445  DataRefTask(name)
446 {
447 }
448 
449 //------------------------------------------------------------------------------
450 
451 inline SetDataRefTask::SetDataRefTask(XPLMDataRef dataRef) :
452  DataRefTask(dataRef)
453 {
454 }
455 
456 //------------------------------------------------------------------------------
457 //------------------------------------------------------------------------------
458 
459 inline void SetIntDataRefTask::setData(XPLMDataRef dataRef, int value)
460 {
461  XPLMSetDatai(dataRef, value);
462 }
463 
464 //------------------------------------------------------------------------------
465 
466 inline SetIntDataRefTask::SetIntDataRefTask(const std::string& name) :
468 {
469 }
470 
471 //------------------------------------------------------------------------------
472 
473 inline SetIntDataRefTask::SetIntDataRefTask(XPLMDataRef dataRef) :
475 {
476 }
477 
478 //------------------------------------------------------------------------------
479 //------------------------------------------------------------------------------
480 
481 inline void SetFloatDataRefTask::setData(XPLMDataRef dataRef, float value)
482 {
483  XPLMSetDatai(dataRef, value);
484 }
485 
486 //------------------------------------------------------------------------------
487 
488 inline SetFloatDataRefTask::SetFloatDataRefTask(const std::string& name) :
490 {
491 }
492 
493 //------------------------------------------------------------------------------
494 
495 inline SetFloatDataRefTask::SetFloatDataRefTask(XPLMDataRef dataRef) :
497 {
498 }
499 
500 //------------------------------------------------------------------------------
501 //------------------------------------------------------------------------------
502 
503 inline void SetDoubleDataRefTask::setData(XPLMDataRef dataRef, double value)
504 {
505  XPLMSetDatai(dataRef, value);
506 }
507 
508 //------------------------------------------------------------------------------
509 
510 inline SetDoubleDataRefTask::SetDoubleDataRefTask(const std::string& name) :
512 {
513 }
514 
515 //------------------------------------------------------------------------------
516 
517 inline SetDoubleDataRefTask::SetDoubleDataRefTask(XPLMDataRef dataRef) :
519 {
520 }
521 
522 //------------------------------------------------------------------------------
523 //------------------------------------------------------------------------------
524 
525 inline void SetIntArrayDataRefTask::setData(XPLMDataRef dataRef, int* value,
526  int count, int offset)
527 {
528  XPLMSetDatavi(dataRef, value, offset, count);
529 }
530 
531 //------------------------------------------------------------------------------
532 
533 inline SetIntArrayDataRefTask::SetIntArrayDataRefTask(const std::string& name,
534  int count, int offset) :
535  SetArrayDataRefTask<int, SetIntArrayDataRefTask>(name, count, offset)
536 {
537 }
538 
539 //------------------------------------------------------------------------------
540 
542  int count, int offset) :
543  SetArrayDataRefTask<int, SetIntArrayDataRefTask>(dataRef, count, offset)
544 {
545 }
546 
547 //------------------------------------------------------------------------------
548 //------------------------------------------------------------------------------
549 
550 inline void SetFloatArrayDataRefTask::setData(XPLMDataRef dataRef,
551  float* value,
552  int count, int offset)
553 {
554  XPLMSetDatavf(dataRef, value, offset, count);
555 }
556 
557 //------------------------------------------------------------------------------
558 
559 inline
561  int count, int offset) :
562  SetArrayDataRefTask<float, SetFloatArrayDataRefTask>(name, count, offset)
563 {
564 }
565 
566 //------------------------------------------------------------------------------
567 
568 inline
570  int count, int offset) :
571  SetArrayDataRefTask<float, SetFloatArrayDataRefTask>(dataRef, count, offset)
572 {
573 }
574 
575 //------------------------------------------------------------------------------
576 //------------------------------------------------------------------------------
577 
578 inline void SetByteArrayDataRefTask::setData(XPLMDataRef dataRef,
579  unsigned char* value,
580  int count, int offset)
581 {
582  XPLMSetDatab(dataRef, value, offset, count);
583 }
584 
585 //------------------------------------------------------------------------------
586 
587 inline
589  int count, int offset) :
590  SetArrayDataRefTask<unsigned char, SetByteArrayDataRefTask>(name,
591  count, offset)
592 {
593 }
594 
595 //------------------------------------------------------------------------------
596 
597 inline
599  int count, int offset) :
600  SetArrayDataRefTask<unsigned char, SetByteArrayDataRefTask>(dataRef,
601  count, offset)
602 {
603 }
604 
605 //------------------------------------------------------------------------------
606 
607 } /* namespace xplra */
608 
609 //------------------------------------------------------------------------------
610 #endif // XPLRA_SETDATAREFTASK_H
611 
612 // Local Variables:
613 // mode: C++
614 // c-basic-offset: 4
615 // indent-tabs-mode: nil
616 // End:
XPLMDataRef dataRef
Definition: DataRefTask.h:61
std::string name
Definition: DataRefTask.h:56
SetArrayDataRefTask(XPLMDataRef dataRef, int count, int offset=0)
virtual void readValue(hu::varadiistvan::scpl::io::DataStream &stream)
SetArrayDataRefTask(const std::string &name, int count, int offset=0)
SetByteArrayDataRefTask(const std::string &name, int count, int offset=0)
static void setData(XPLMDataRef dataRef, unsigned char *value, int count, int offset)
static SetDataRefTask * create(uint8_t &result, hu::varadiistvan::scpl::io::DataStream &stream)
virtual void readValue(hu::varadiistvan::scpl::io::DataStream &stream)=0
SetDataRefTask(const std::string &name)
static void setData(XPLMDataRef dataRef, double value)
SetDoubleDataRefTask(const std::string &name)
virtual void readValue(hu::varadiistvan::scpl::io::DataStream &stream)
static void setData(XPLMDataRef dataRef, float *value, int count, int offset)
SetFloatArrayDataRefTask(const std::string &name, int count, int offset=0)
virtual void readValue(hu::varadiistvan::scpl::io::DataStream &stream)
SetFloatDataRefTask(const std::string &name)
static void setData(XPLMDataRef dataRef, float value)
static void setData(XPLMDataRef dataRef, int *value, int count, int offset)
SetIntArrayDataRefTask(const std::string &name, int count, int offset=0)
static void setData(XPLMDataRef dataRef, int value)
virtual void readValue(hu::varadiistvan::scpl::io::DataStream &stream)
SetIntDataRefTask(const std::string &name)
SetScalarDataRefTask(const std::string &name)
SetScalarDataRefTask(XPLMDataRef dataRef)
Python client module for the X-Plane Remote Access plugin.
Definition: DataRefTask.h:41