X-Plane Remote Access Plugin and Client Library
MultiTaskRequest.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_MULTITASKREQUEST_H
30 #define XPLRA_MULTITASKREQUEST_H
31 //------------------------------------------------------------------------------
32 
33 #include "Request.h"
34 
35 #include <vector>
36 
37 #include <cstdlib>
38 
39 //------------------------------------------------------------------------------
40 
41 namespace xplra {
42 
43 //------------------------------------------------------------------------------
44 
45 class Task;
46 
47 //------------------------------------------------------------------------------
48 
54 class MultiTaskRequest : public Request
55 {
56 private:
60  typedef std::vector<Task*> tasks_t;
61 
66 
67 public:
71  virtual ~MultiTaskRequest();
72 
76  void addTask(Task* task);
77 
81  size_t getNumTasks() const;
82 
86  Task* getTask(size_t index) const;
87 
88 protected:
92  virtual void execute();
93 };
94 
95 //------------------------------------------------------------------------------
96 //------------------------------------------------------------------------------
97 
102 template <class TaskClass>
104 {
105 public:
109  void addTask(TaskClass* task);
110 
114  TaskClass* getTask(size_t index) const;
115 };
116 
117 //------------------------------------------------------------------------------
118 // Inline definitions
119 //------------------------------------------------------------------------------
120 
121 inline void MultiTaskRequest::addTask(Task* task)
122 {
123  tasks.push_back(task);
124 }
125 
126 //------------------------------------------------------------------------------
127 
128 inline size_t MultiTaskRequest::getNumTasks() const
129 {
130  return tasks.size();
131 }
132 
133 //------------------------------------------------------------------------------
134 
135 inline Task* MultiTaskRequest::getTask(size_t index) const
136 {
137  return tasks[index];
138 }
139 
140 //------------------------------------------------------------------------------
141 // Template definitions
142 //------------------------------------------------------------------------------
143 
144 template <class TaskClass>
146 {
148 }
149 
150 //------------------------------------------------------------------------------
151 
152 template <class TaskClass>
153 inline TaskClass*
155 {
156  return static_cast<TaskClass*>(MultiTaskRequest::getTask(index));
157 }
158 
159 //------------------------------------------------------------------------------
160 
161 } /* namespace xplra */
162 
163 //------------------------------------------------------------------------------
164 #endif // XPLRA_MULTITASKREQUEST_H
165 
166 // Local Variables:
167 // mode: C++
168 // c-basic-offset: 4
169 // indent-tabs-mode: nil
170 // End:
TaskClass * getTask(size_t index) const
std::vector< Task * > tasks_t
void addTask(Task *task)
Task * getTask(size_t index) const
Python client module for the X-Plane Remote Access plugin.
Definition: DataRefTask.h:41