Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes
omni::patch::List Class Reference

#include <List.h>

Inheritance diagram for omni::patch::List:
Inheritance graph
[legend]
Collaboration diagram for omni::patch::List:
Collaboration graph
[legend]

Public Types

typedef std::map< QString,
std::unique_ptr< Patch > > 
container_type
 

Public Member Functions

PatchaddPatch (QString const &_id, Id const &_typeId)
 Add new patch with given type id. Returns nullptr if input with typeid does not exist. More...
 
PatchaddPatch (QString const &_id, Patch *)
 Input with id and return pointer to input when successfully added. More...
 
std::pair< QString, Patch * > addPatch (Id const &_typeId)
 Add new input with given type id. Returns nullptr if input with typeid does not exist Id is automatically generated. More...
 
PatchgetPatch (QString const &_id)
 Return pointer of input with id, nullptr if input does not exist. More...
 
Patch const * getPatch (QString const &_id) const
 Return pointer of input with id, nullptr if input does not exist. More...
 
void removePatch (QString const &_id)
 
void clear ()
 Delete all patches. More...
 
QString currentId () const
 Return ID of current patch. More...
 
void setCurrentId (QString const &)
 Set current patch by id and deselected all other patches. More...
 
Patchoperator[] (QString const &_id) const
 Return patch at index. More...
 
Patchcurrent ()
 Returns pointer to current patch Returns nullptr if currentIdx_ == -1 or input list is empty. More...
 
void selectPatch (QString const &_id, bool _select=true)
 Select / deselect patch. More...
 
bool patchIsSelected (QString const &) const
 Return flag whether patch with id is selected. More...
 
void fromStream (QDataStream &)
 Deserialize from stream. More...
 
void toStream (QDataStream &) const
 Serialize to stream. More...
 

Private Member Functions

QString generateId () const
 Generate a new id for input. More...
 

Private Attributes

std::set< QString > selectedPatches_
 Ids of selected patches. More...
 

Member Typedef Documentation

typedef std::map<QString,std::unique_ptr<Patch> > omni::patch::List::container_type

Member Function Documentation

Patch * omni::patch::List::addPatch ( QString const &  _id,
Id const &  _typeId 
)

Add new patch with given type id. Returns nullptr if input with typeid does not exist.

Parameters
_idId for the patch
_typeIdType id of patch to determine which kind of input is created
26  {
27  std::unique_ptr<Patch> _patch(patch::Factory::create(_typeId));
28 
29  if (!_patch) return nullptr;
30 
31  container_type::operator[](_id) = std::move(_patch);
32  return container_type::at(_id).get();
33  }
static interface_type * create(const key_type &_key, const ARGS &..._args)
Instantiates an object of the class by id and constructor arguments.
Definition: factory.hpp:101
Patch * omni::patch::List::addPatch ( QString const &  _id,
Patch _patch 
)

Input with id and return pointer to input when successfully added.

41  {
42  if (container_type::count(_id) != 0) {
43  return nullptr;
44  }
45  container_type::operator[](_id).reset(_patch);
46  return container_type::operator[](_id).get();
47  }
std::pair< QString, Patch * > omni::patch::List::addPatch ( Id const &  _typeId)

Add new input with given type id. Returns nullptr if input with typeid does not exist Id is automatically generated.

Parameters
_typeIdType id of input to determine which kind of input is created
Returns
Pair with input id and pointer to added input
35  {
36  auto _id = generateId();
37 
38  return std::make_pair(_id, addPatch(_id, _typeId));
39  }
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
QString generateId() const
Generate a new id for input.
Definition: List.cpp:143
void omni::patch::List::clear ( )

Delete all patches.

64  {
65  container_type::clear();
66 
67  selectedPatches_.clear();
68  }
std::set< QString > selectedPatches_
Ids of selected patches.
Definition: List.h:104
Patch * omni::patch::List::current ( )

Returns pointer to current patch Returns nullptr if currentIdx_ == -1 or input list is empty.

99  {
100  return getPatch(currentId());
101  }
Patch * getPatch(QString const &_id)
Return pointer of input with id, nullptr if input does not exist.
Definition: List.cpp:50
QString currentId() const
Return ID of current patch.
Definition: List.cpp:77
QString omni::patch::List::currentId ( ) const

Return ID of current patch.

Return ID of current input.

77  {
78  return selectedPatches_.empty() ? QString("") : *selectedPatches_.begin();
79  }
std::set< QString > selectedPatches_
Ids of selected patches.
Definition: List.h:104
void omni::patch::List::fromStream ( QDataStream &  _is)

Deserialize from stream.

114  {
115  int _size = 0;
116  deserialize(_is, _size);
117 
118  for (int i = 0; i < _size; ++i) {
119  auto _id = deserializeReturn<QString>(_is);
120  deserializePtr(_is, [&](Id const& _typeId) ->
121  patch::Interface *
122  {
123  return addPatch(_id, _typeId);
124  });
125  }
127  }
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
std::set< QString > selectedPatches_
Ids of selected patches.
Definition: List.h:104
STREAM & deserialize(STREAM &_stream, T &_t, ARGS &&..._args)
Deserialize object of type T from stream with optional additional arguments.
Definition: traits.h:125
STREAM & deserializePtr(STREAM &_stream, F _f, ARGS &&..._args)
Deserialize a pointer from stream. Functor f must return a pointer which is constructed from a facto...
Definition: pointer.h:78
QString omni::patch::List::generateId ( ) const
private

Generate a new id for input.

143  {
144  QString _id("0");
145 
146  for (size_t i = 0; i <= size(); ++i) {
147  _id = QString("%1").arg(i);
148 
149  if (getPatch(_id) == nullptr)
150  {
151  return _id;
152  }
153  }
154  return _id;
155  }
Patch * getPatch(QString const &_id)
Return pointer of input with id, nullptr if input does not exist.
Definition: List.cpp:50
Patch * omni::patch::List::getPatch ( QString const &  _id)

Return pointer of input with id, nullptr if input does not exist.

50  {
51  if (!container_type::count(_id)) return nullptr;
52 
53  return container_type::at(_id).get();
54  }
Patch const * omni::patch::List::getPatch ( QString const &  _id) const

Return pointer of input with id, nullptr if input does not exist.

57  {
58  if (!container_type::count(_id)) return nullptr;
59 
60  return container_type::at(_id).get();
61  }
Patch* omni::patch::List::operator[] ( QString const &  _id) const

Return patch at index.

bool omni::patch::List::patchIsSelected ( QString const &  _id) const

Return flag whether patch with id is selected.

95  {
96  return selectedPatches_.count(_id) > 0;
97  }
std::set< QString > selectedPatches_
Ids of selected patches.
Definition: List.h:104
void omni::patch::List::removePatch ( QString const &  _id)
70  {
71  container_type::erase(_id);
72 
73  selectedPatches_.erase(_id);
74  }
std::set< QString > selectedPatches_
Ids of selected patches.
Definition: List.h:104
void omni::patch::List::selectPatch ( QString const &  _id,
bool  _select = true 
)

Select / deselect patch.

82  {
83  auto *_patch = getPatch(_id);
84 
85  if (!_patch) return;
86 
87  if (_select) {
88  selectedPatches_.insert(_id);
89  } else {
90  selectedPatches_.erase(_id);
91  }
92  }
std::set< QString > selectedPatches_
Ids of selected patches.
Definition: List.h:104
Patch * getPatch(QString const &_id)
Return pointer of input with id, nullptr if input does not exist.
Definition: List.cpp:50
void omni::patch::List::setCurrentId ( QString const &  _currentId)

Set current patch by id and deselected all other patches.

Set current input by ID.

104  {
105  selectedPatches_.clear();
106 
107  if (getPatch(_currentId) == nullptr) {
108  return;
109  }
110  selectedPatches_.insert(_currentId);
111  }
std::set< QString > selectedPatches_
Ids of selected patches.
Definition: List.h:104
Patch * getPatch(QString const &_id)
Return pointer of input with id, nullptr if input does not exist.
Definition: List.cpp:50
void omni::patch::List::toStream ( QDataStream &  _os) const

Serialize to stream.

130  {
131  serialize(_os, int(size()));
132 
133  for (auto& _idPatch : (*this)) {
134  auto& _id = _idPatch.first;
135  auto& _patch = _idPatch.second;
136  serialize(_os, _id);
137  serialize(_os, _patch.get());
138  }
139 
141  }
STREAM & serialize(STREAM &_stream, T const &_t)
Serialize object to stream.
Definition: traits.h:140
std::set< QString > selectedPatches_
Ids of selected patches.
Definition: List.h:104

Field Documentation

std::set<QString> omni::patch::List::selectedPatches_
private

Ids of selected patches.


The documentation for this class was generated from the following files: