Skip to content

Commit

Permalink
Id as QByteArray, Factory into omni, removed boostx stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelWinkelmann committed Nov 6, 2019
1 parent 3131dc4 commit b84280e
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 319 deletions.
8 changes: 4 additions & 4 deletions app/Canvas.cpp
Expand Up @@ -38,7 +38,7 @@ namespace omni {
// Add canvas types from Factory
for (auto& _idCanvasClass : omni::canvas::Interface::factory().classes())
{
QString _id = _idCanvasClass.first.str();
auto& _id = _idCanvasClass.first;
ui_->boxCanvasSelect->addItem(QIcon(QString(":/canvas/") + _id +
QString(
".png")), _id,
Expand Down Expand Up @@ -66,7 +66,7 @@ namespace omni {
{
QString _id = ui_->boxCanvasSelect->itemData(i).toString();

if (_id == dataModel()->canvas()->getTypeId().str())
if (_id == dataModel()->canvas()->getTypeId())
{
_index = i;
}
Expand Down Expand Up @@ -98,15 +98,15 @@ namespace omni {
}
}

void Canvas::selectCanvasType(QString _id)
void Canvas::selectCanvasType(QByteArray const& _id)
{
if (!dataModel() || signalsBlocked()) return;

tryWithExceptionList<Exception>([&]() {
canvasMemory_.store(dataModel()->canvas());

/// Dont do anything if type id has not changed
if (dataModel()->canvas()->getTypeId().str() == _id) {
if (dataModel()->canvas()->getTypeId() == _id) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Canvas.h
Expand Up @@ -53,7 +53,7 @@ namespace omni {

public slots:
/// Select canvas type with id
void selectCanvasType(QString);
void selectCanvasType(QByteArray const&);

/// Set size of scene for canvas parameter widget
void updateSceneSize(bool);
Expand Down
6 changes: 3 additions & 3 deletions app/Input.cpp
Expand Up @@ -66,7 +66,7 @@ namespace omni
auto* _input = omni::input::Interface::factory().create(_idInputClass.first);
if (!_input) continue;

auto _id = _idInputClass.first.str();
auto& _id = _idInputClass.first;

auto _categories = _input->categories();
if (_categories.empty())
Expand Down Expand Up @@ -110,7 +110,7 @@ namespace omni
{
if (!dataModel()) return;

auto _idInput = dataModel()->inputs().addInput(_action->text());
auto _idInput = dataModel()->inputs().addInput(_action->text().toLatin1());
auto& _input = _idInput;

if (!_input) return;
Expand Down Expand Up @@ -231,7 +231,7 @@ namespace omni
_row << _item;
};

_addItem(_input->getTypeId().str());
_addItem(_input->getTypeId());
_addItem(_input->infoText());

model_->invisibleRootItem()->appendRow(_row);
Expand Down
14 changes: 7 additions & 7 deletions app/Mapping.cpp
Expand Up @@ -31,12 +31,13 @@ namespace omni {
{
this->setup(ui_);

connect(ui_->boxMappingSelect, SIGNAL(currentIndexChanged(
QString)), this,
SLOT(selectMappingType(QString)));
connect(ui_->boxMappingSelect,
qOverload<int>(&QComboBox::currentIndexChanged),
[this](){ this->selectMappingType(
ui_->boxMappingSelect->currentText().toLatin1()); });

for (auto& _idMappingClass : omni::mapping::Interface::factory().classes()) {
QString _id = _idMappingClass.first.str();
auto& _id = _idMappingClass.first;
ui_->boxMappingSelect->addItem(QIcon(QString(":/mapping/") + _id +
QString(".png")), _id);
}
Expand All @@ -58,8 +59,7 @@ namespace omni {
for (int i = 0; i < ui_->boxMappingSelect->count(); ++i)
{
QString _id = ui_->boxMappingSelect->itemData(i).toString();

if (_id == dataModel()->mapping()->getTypeId().str())
if (_id == dataModel()->mapping()->getTypeId())
{
_index = i;
}
Expand All @@ -75,7 +75,7 @@ namespace omni {
return false;
}

void Mapping::selectMappingType(QString const& _id)
void Mapping::selectMappingType(QByteArray const& _id)
{
if (!dataModel() || signalsBlocked()) return;

Expand Down
2 changes: 1 addition & 1 deletion app/Mapping.h
Expand Up @@ -51,7 +51,7 @@ namespace omni {
void dataModelChanged();

public slots:
void selectMappingType(QString const&);
void selectMappingType(const QByteArray &);

private:
/// Update widgets from current mapping
Expand Down
1 change: 0 additions & 1 deletion lib/CMakeLists.txt
Expand Up @@ -15,7 +15,6 @@ set(SOURCES
src/canvas/Dome.cpp
src/canvas/Envelope.cpp
src/canvas/Interface.cpp
src/Id.cpp
src/LengthUnit.cpp
src/PluginInfo.cpp
src/PluginLoader.cpp
Expand Down
63 changes: 0 additions & 63 deletions lib/include/boostx/type_info.hpp

This file was deleted.

61 changes: 45 additions & 16 deletions lib/include/boostx/factory.hpp → lib/include/omni/Factory.h 100755 → 100644
@@ -1,4 +1,4 @@
/* Copyright (c) 2014-2015 "Omnidome" by Michael Winkelmann
/* Copyright (c) 2014-2019 "Omnidome" by Michael Winkelmann
* Dome Mapping Projection Software (http://omnido.me).
* Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
*
Expand All @@ -17,33 +17,54 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef BOOSTX_FACTORY_HPP_
#define BOOSTX_FACTORY_HPP_

#pragma once

#include <set>
#include <QByteArray>
#include <unordered_map>
#include <functional>
#include <type_traits>
#include <omni/global.h>

namespace boostx
namespace omni
{
using Id = QByteArray;

/// Id set typedef
typedef std::set<Id>IdSet;

template<typename T>
struct TypeInfo
{
using typeid_type = Id;\
typeid_type operator()() const
{
return T::typeId();
}
template<typename PTR>
typeid_type operator()(PTR&& _ptr) const
{
return _ptr->getTypeId();
}
};

/**@brief The central factory class.
* @tparam INTERFACE Typename of the abstract interface
* @tparam TYPEINFO Template template parameter for the typeinfo
* @tparam ...ARGS Template parameter which comply to the constructor signature of the interface
*/
template<typename INTERFACE, template<class> class TYPEINFO, typename...ARGS>
struct factory
template<typename INTERFACE, typename...ARGS>
struct AbstractFactory
{
/// Typedef for our abstract interface
typedef INTERFACE interface_type;

/// Typedef for this factory type
typedef factory<interface_type,TYPEINFO,ARGS...> type;
typedef AbstractFactory<interface_type,ARGS...> type;

/// Template alias for typeinfo type
template<typename T>
using typeinfo_type = TYPEINFO<T>;
using typeinfo_type = TypeInfo<T>;

/// Get key type from typeinfo struct
typedef typename typeinfo_type<interface_type>::typeid_type key_type;
Expand Down Expand Up @@ -99,17 +120,15 @@ namespace boostx
}

/// Gives readonly access to registered classes
class_map_type const& classes()
class_map_type const& classes() const
{
return _classes;
}



private:
/// Checks if key types are the same
template<typename T>
void key_type_check()
static void key_type_check()
{
// Check if T is a base class of interface
static_assert(std::is_base_of<interface_type,T>::value,
Expand All @@ -123,15 +142,25 @@ namespace boostx

template<typename T>
/// Return type id by calling the call operator of type info template
decltype(typeinfo_type<T>()()) type_id() const
static decltype(typeinfo_type<T>()()) type_id()
{
return typeinfo_type<T>()();
}

class_map_type _classes;

};
}

namespace std {
/// Template specialization for Id to make it hashable
template<>
struct hash<omni::Id>
{
/// Use hash<std::string> to produce hash value
inline size_t operator()(const omni::Id& _id) const
{
return hash<std::string>()(_id.toStdString());
}
};
}

#endif /* BOOSTX_FACTORY_HPP_ */

0 comments on commit b84280e

Please sign in to comment.