annotate Core/MultiThreading/BagOfTasks.h @ 2165:42764dcd3a41

migrate the doc of ModalityWorklists to Orthanc Book
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Nov 2016 13:03:15 +0100
parents 0ae26237569a
children a3a65de1840f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1920
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #pragma once
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "../ICommand.h"
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <list>
1975
730eedd9a5dc fix powerpc build
sjodogne
parents: 1920
diff changeset
38 #include <cstddef>
1920
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace Orthanc
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 class BagOfTasks : public boost::noncopyable
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 private:
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 typedef std::list<ICommand*> Tasks;
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 Tasks tasks_;
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 public:
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 ~BagOfTasks()
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
2016
0ae26237569a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1975
diff changeset
52 for (Tasks::iterator it = tasks_.begin(); it != tasks_.end(); ++it)
1920
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 delete *it;
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 ICommand* Pop()
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 ICommand* task = tasks_.front();
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 tasks_.pop_front();
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 return task;
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 void Push(ICommand* task) // Takes ownership
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 if (task != NULL)
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 tasks_.push_back(task);
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 size_t GetSize() const
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 return tasks_.size();
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 bool IsEmpty() const
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 return tasks_.empty();
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 };
b97aa579e85b bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }