Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
List.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OMNI_PATCH_LIST_H_
20 #define OMNI_PATCH_LIST_H_
21 
22 #include <map>
23 #include <memory>
24 #include <QString>
25 #include <omni/patch/Interface.h>
26 
27 namespace omni {
28  namespace patch {
29  class List : private std::map<QString,std::unique_ptr<Patch>> {
30  public:
31  typedef std::map<QString,std::unique_ptr<Patch>> container_type;
32 
33  using container_type::empty;
34  using container_type::size;
35  using container_type::begin;
36  using container_type::end;
37 
38  /**@brief Add new patch with given type id. Returns nullptr if input
39  with typeid does not exist
40  @param _id Id for the patch
41  *@param _typeId Type id of patch to determine which kind of input is
42  * created
43  **/
44  Patch* addPatch(QString const& _id,
45  Id const& _typeId);
46 
47  /// Input with id and return pointer to input when successfully added
48  Patch* addPatch(QString const& _id,
49  Patch*);
50 
51  /**@brief Add new input with given type id. Returns nullptr if input
52  with typeid does not exist
53  @detail Id is automatically generated
54  *@param _typeId Type id of input to determine which kind of input is
55  *created
56  *@return Pair with input id and pointer to added input
57  **/
58  std::pair<QString, Patch *> addPatch(Id const& _typeId);
59 
60  /// Return pointer of input with id, nullptr if input does not exist
61  Patch * getPatch(QString const& _id);
62 
63  /// Return pointer of input with id, nullptr if input does not exist
64  Patch const * getPatch(QString const& _id) const;
65 
66 
67  void removePatch(QString const& _id);
68 
69  /// Delete all patches
70  void clear();
71 
72  /// Return ID of current patch
73  QString currentId() const;
74 
75  /// Set current patch by id and deselected all other patches
76  void setCurrentId(QString const&);
77 
78  /// Return patch at index
79  Patch * operator[](QString const& _id) const;
80 
81  /**@brief Returns pointer to current patch
82  * @detail Returns nullptr if currentIdx_ == -1 or input list is empty
83  **/
84  Patch * current();
85 
86  /// Select / deselect patch
87  void selectPatch(QString const& _id,
88  bool _select = true);
89 
90  /// Return flag whether patch with id is selected
91  bool patchIsSelected(QString const&) const;
92 
93  /// Deserialize from stream
94  void fromStream(QDataStream&);
95 
96  /// Serialize to stream
97  void toStream(QDataStream&) const;
98 
99  private:
100  /// Generate a new id for input
101  QString generateId() const;
102 
103  /// Ids of selected patches
104  std::set<QString> selectedPatches_;
105  };
106  }
107 
109 }
110 
112 
113 #endif /* OMNI_PATCH_LIST_H_ */
bool patchIsSelected(QString const &) const
Return flag whether patch with id is selected.
Definition: List.cpp:95
Id type for classes An Id must only contain alpha numerical characters and must begin with a letter...
Definition: Id.h:34
Patch * addPatch(QString const &_id, Id const &_typeId)
Add new patch with given type id. Returns nullptr if input with typeid does not exist.
Definition: List.cpp:26
patch::List PatchList
Definition: List.h:108
Patch * operator[](QString const &_id) const
Return patch at index.
void toStream(QDataStream &) const
Serialize to stream.
Definition: List.cpp:130
QString generateId() const
Generate a new id for input.
Definition: List.cpp:143
void clear()
Delete all patches.
Definition: List.cpp:64
void selectPatch(QString const &_id, bool _select=true)
Select / deselect patch.
Definition: List.cpp:82
void removePatch(QString const &_id)
Definition: List.cpp:70
std::map< QString, std::unique_ptr< Patch > > container_type
Definition: List.h:31
std::set< QString > selectedPatches_
Ids of selected patches.
Definition: List.h:104
#define OMNI_DECL_STREAM_OPERATORS(CLASS)
Definition: Interface.h:53
Patch * getPatch(QString const &_id)
Return pointer of input with id, nullptr if input does not exist.
Definition: List.cpp:50
void fromStream(QDataStream &)
Deserialize from stream.
Definition: List.cpp:114
Definition: Interface.h:32
QString currentId() const
Return ID of current patch.
Definition: List.cpp:77
void setCurrentId(QString const &)
Set current patch by id and deselected all other patches.
Definition: List.cpp:104
Patch * current()
Returns pointer to current patch Returns nullptr if currentIdx_ == -1 or input list is empty...
Definition: List.cpp:99
Definition: List.h:29