From b84280e5123f41a42caeb7ebecfa3572f0c81d83 Mon Sep 17 00:00:00 2001 From: Michael Winkelmann Date: Wed, 6 Nov 2019 11:23:03 +0100 Subject: [PATCH] Id as QByteArray, Factory into omni, removed boostx stuff --- app/Canvas.cpp | 8 +- app/Canvas.h | 2 +- app/Input.cpp | 6 +- app/Mapping.cpp | 14 +-- app/Mapping.h | 2 +- lib/CMakeLists.txt | 1 - lib/include/boostx/type_info.hpp | 63 ----------- .../{boostx/factory.hpp => omni/Factory.h} | 61 +++++++--- lib/include/omni/Id.h | 107 ------------------ lib/include/omni/LengthUnit.h | 1 + lib/include/omni/TypeIdInterface.h | 11 +- lib/include/omni/exception.h | 4 +- lib/include/omni/geometry/PolarVec.h | 1 + lib/include/omni/input/List.h | 2 +- lib/include/omni/proj/Tuning.h | 2 +- lib/include/omni/serialization/PropertyMap.h | 2 +- lib/include/omni/serialization/pointer.h | 2 +- lib/include/omni/visual/ProjectorViewMode.h | 1 + lib/src/Id.cpp | 103 ----------------- lib/src/mapping/Interface.cpp | 2 +- 20 files changed, 76 insertions(+), 319 deletions(-) delete mode 100755 lib/include/boostx/type_info.hpp rename lib/include/{boostx/factory.hpp => omni/Factory.h} (77%) mode change 100755 => 100644 delete mode 100755 lib/include/omni/Id.h delete mode 100755 lib/src/Id.cpp diff --git a/app/Canvas.cpp b/app/Canvas.cpp index 52a96e89..3df205ec 100755 --- a/app/Canvas.cpp +++ b/app/Canvas.cpp @@ -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, @@ -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; } @@ -98,7 +98,7 @@ namespace omni { } } - void Canvas::selectCanvasType(QString _id) + void Canvas::selectCanvasType(QByteArray const& _id) { if (!dataModel() || signalsBlocked()) return; @@ -106,7 +106,7 @@ namespace omni { 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; } diff --git a/app/Canvas.h b/app/Canvas.h index 3d8fe80a..458542bf 100755 --- a/app/Canvas.h +++ b/app/Canvas.h @@ -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); diff --git a/app/Input.cpp b/app/Input.cpp index 90790aee..96178092 100755 --- a/app/Input.cpp +++ b/app/Input.cpp @@ -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()) @@ -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; @@ -231,7 +231,7 @@ namespace omni _row << _item; }; - _addItem(_input->getTypeId().str()); + _addItem(_input->getTypeId()); _addItem(_input->infoText()); model_->invisibleRootItem()->appendRow(_row); diff --git a/app/Mapping.cpp b/app/Mapping.cpp index f03401d6..e1b1644d 100755 --- a/app/Mapping.cpp +++ b/app/Mapping.cpp @@ -31,12 +31,13 @@ namespace omni { { this->setup(ui_); - connect(ui_->boxMappingSelect, SIGNAL(currentIndexChanged( - QString)), this, - SLOT(selectMappingType(QString))); + connect(ui_->boxMappingSelect, + qOverload(&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); } @@ -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; } @@ -75,7 +75,7 @@ namespace omni { return false; } - void Mapping::selectMappingType(QString const& _id) + void Mapping::selectMappingType(QByteArray const& _id) { if (!dataModel() || signalsBlocked()) return; diff --git a/app/Mapping.h b/app/Mapping.h index 694f2e44..e0aa4301 100755 --- a/app/Mapping.h +++ b/app/Mapping.h @@ -51,7 +51,7 @@ namespace omni { void dataModelChanged(); public slots: - void selectMappingType(QString const&); + void selectMappingType(const QByteArray &); private: /// Update widgets from current mapping diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7dd47629..889f8d10 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -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 diff --git a/lib/include/boostx/type_info.hpp b/lib/include/boostx/type_info.hpp deleted file mode 100755 index e40e2b87..00000000 --- a/lib/include/boostx/type_info.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/* Copyright (c) 2014-2015 "Omnidome" by Michael Winkelmann - * Dome Mapping Projection Software (http://omnido.me). - * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo) - * - * This file is part of Omnidome. - * - * Omnidome is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef BOOSTX_TYPE_INFO_HPP_ -#define BOOSTX_TYPE_INFO_HPP_ - -#include - -/// Convenience macro for declaring a type info struct - -#define BOOSTX_DECL_TYPE_INFO(NAME,TYPEID,STATIC_MEMBER,VIRTUAL_MEMBER)\ - template\ - struct NAME\ - {\ - typedef TYPEID typeid_type;\ - typeid_type operator()() const\ - {\ - return T::STATIC_MEMBER();\ - }\ - template\ - typeid_type operator()(PTR&& _ptr) const\ - {\ - return _ptr->VIRTUAL_MEMBER();\ - }\ - }; - -/// Convenience macro for defining a type id for a single class -#define BOOSTX_TYPE_ID(TYPEID_TYPE,TYPEID,STATIC_MEMBER,VIRTUAL_MEMBER)\ - inline static TYPEID_TYPE STATIC_MEMBER() { return TYPEID; }\ - inline virtual TYPEID_TYPE VIRTUAL_MEMBER() const override { return STATIC_MEMBER(); } - -namespace boostx -{ - /// Declare default type id mechanism - BOOSTX_DECL_TYPE_INFO( - type_info, // Name of type id struct - std::string, // Type id type - type_id, // Static member function - get_type_id // Virtual member function of abstract interface - ) -} - -#define BOOSTX_DECL_TYPE_ID_DEFAULT(TYPEID)\ - BOOSTX_TYPE_ID(std::string,TYPEID,type_id,get_type_id) - - -#endif /* BOOSTX_TYPE_INFO_HPP_ */ diff --git a/lib/include/boostx/factory.hpp b/lib/include/omni/Factory.h old mode 100755 new mode 100644 similarity index 77% rename from lib/include/boostx/factory.hpp rename to lib/include/omni/Factory.h index ff0d2cea..f009523d --- a/lib/include/boostx/factory.hpp +++ b/lib/include/omni/Factory.h @@ -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) * @@ -17,33 +17,54 @@ * along with this program. If not, see . */ -#ifndef BOOSTX_FACTORY_HPP_ -#define BOOSTX_FACTORY_HPP_ +#pragma once + +#include +#include #include #include #include #include -namespace boostx +namespace omni { + using Id = QByteArray; + + /// Id set typedef + typedef std::setIdSet; + + template + struct TypeInfo + { + using typeid_type = Id;\ + typeid_type operator()() const + { + return T::typeId(); + } + template + 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 class TYPEINFO, typename...ARGS> - struct factory + template + struct AbstractFactory { /// Typedef for our abstract interface typedef INTERFACE interface_type; /// Typedef for this factory type - typedef factory type; + typedef AbstractFactory type; /// Template alias for typeinfo type template - using typeinfo_type = TYPEINFO; + using typeinfo_type = TypeInfo; /// Get key type from typeinfo struct typedef typename typeinfo_type::typeid_type key_type; @@ -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 - void key_type_check() + static void key_type_check() { // Check if T is a base class of interface static_assert(std::is_base_of::value, @@ -123,15 +142,25 @@ namespace boostx template /// Return type id by calling the call operator of type info template - decltype(typeinfo_type()()) type_id() const + static decltype(typeinfo_type()()) type_id() { return typeinfo_type()(); } class_map_type _classes; - }; } +namespace std { + /// Template specialization for Id to make it hashable + template<> + struct hash + { + /// Use hash to produce hash value + inline size_t operator()(const omni::Id& _id) const + { + return hash()(_id.toStdString()); + } + }; +} -#endif /* BOOSTX_FACTORY_HPP_ */ diff --git a/lib/include/omni/Id.h b/lib/include/omni/Id.h deleted file mode 100755 index 79fe39c9..00000000 --- a/lib/include/omni/Id.h +++ /dev/null @@ -1,107 +0,0 @@ -/* Copyright (c) 2014-2015 "Omnidome" by Michael Winkelmann - * Dome Mapping Projection Software (http://omnido.me). - * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo) - * - * This file is part of Omnidome. - * - * Omnidome is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef OMNI_ID_H_ -#define OMNI_ID_H_ - -#include -#include -#include -#include -#include -#include - -namespace omni { - /**@brief Id type for classes - * @detail An Id must only contain alpha numerical characters - * and must begin with a letter - **/ - struct OMNI_EXPORT Id - { - /// Default constructor - Id(); - - /// Constructor from string - Id(QString const&); - - /// Constructor from const char* - Id(const char *); - - /// Returns string representation (const) - QString const& str() const; - - /// Cast operator returns copy of string representation - operator QString() const; - - /// Returns true if string is valid - bool valid() const; - - /// Comparison operator - bool operator<(const Id&) const; - - /// Returns true if two ids do not match - bool operator!=(const Id&) const; - - /// Returns true if two ids match - bool operator==(const Id&) const; - - private: - /// Make Id from string - void make(QString const&); - - /// Internal string buffer - QString str_; - }; - - BOOSTX_DECL_TYPE_INFO( - TypeInfo, - Id, - typeId, - getTypeId - ) - - /// Alias template for factories - template - using AbstractFactory = boostx::factory; - - /// Id set typedef - typedef std::setIdSet; -} - -namespace std { - /// Template specialization for Id to make it hashable - template<> - struct hash - { - /// Use hash to produce hash value - inline size_t operator()(const omni::Id& _id) const - { - return hash()(_id.str().toStdString()); - } - }; -} - - -/// Serialize omni::Id to stream -OMNI_EXPORT QDataStream& operator<<(QDataStream&, omni::Id const&); - -/// Deserialize omni::Id from stream -OMNI_EXPORT QDataStream& operator>>(QDataStream&, omni::Id&); - -#endif /* OMNI_ID_H_ */ diff --git a/lib/include/omni/LengthUnit.h b/lib/include/omni/LengthUnit.h index 411f3fb7..937ecbbe 100644 --- a/lib/include/omni/LengthUnit.h +++ b/lib/include/omni/LengthUnit.h @@ -21,6 +21,7 @@ #include #include +#include #include namespace omni { diff --git a/lib/include/omni/TypeIdInterface.h b/lib/include/omni/TypeIdInterface.h index 12ae90a3..187b0e20 100755 --- a/lib/include/omni/TypeIdInterface.h +++ b/lib/include/omni/TypeIdInterface.h @@ -17,10 +17,9 @@ * along with this program. If not, see . */ -#ifndef OMNI_TYPEIDINTERFACE_H_ -#define OMNI_TYPEIDINTERFACE_H_ +#pragma once -#include +#include namespace omni { /// Abstract Interface with a single virtual member function which returns @@ -37,8 +36,9 @@ namespace omni { }; } -#define OMNI_TYPEID(type_id) \ - BOOSTX_TYPE_ID(omni::Id, type_id, typeId, getTypeId) +#define OMNI_TYPEID(TYPEID) \ + inline static omni::Id typeId() { return TYPEID; }\ + inline virtual omni::Id getTypeId() const override { return typeId(); } #define OMNI_REGISTER_CLASS(FACTORY, CLASS_NAME) \ OMNI_TYPEID(# CLASS_NAME) \ @@ -46,4 +46,3 @@ namespace omni { factory().template reg(); \ } -#endif /* OMNI_TYPEIDINTERFACE_H_ */ diff --git a/lib/include/omni/exception.h b/lib/include/omni/exception.h index a122cd20..7301bf06 100755 --- a/lib/include/omni/exception.h +++ b/lib/include/omni/exception.h @@ -22,7 +22,7 @@ #include #include -#include +#include namespace omni { /// Base class for all exception. Throws a message with QString type @@ -93,7 +93,7 @@ namespace omni { QString message() const throw() { - return QString("Serialization Exception. Invalid Id: ") + id_.str(); + return QString("Serialization Exception. Invalid Id: ") + id_; } private: diff --git a/lib/include/omni/geometry/PolarVec.h b/lib/include/omni/geometry/PolarVec.h index 42e13fc0..51012a94 100755 --- a/lib/include/omni/geometry/PolarVec.h +++ b/lib/include/omni/geometry/PolarVec.h @@ -22,6 +22,7 @@ #include #include +#include #include #include diff --git a/lib/include/omni/input/List.h b/lib/include/omni/input/List.h index 443a7f17..2683dd4d 100755 --- a/lib/include/omni/input/List.h +++ b/lib/include/omni/input/List.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include diff --git a/lib/include/omni/proj/Tuning.h b/lib/include/omni/proj/Tuning.h index 71f9de73..fda69dcc 100755 --- a/lib/include/omni/proj/Tuning.h +++ b/lib/include/omni/proj/Tuning.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include diff --git a/lib/include/omni/serialization/PropertyMap.h b/lib/include/omni/serialization/PropertyMap.h index f821dad6..81ad7cb2 100644 --- a/lib/include/omni/serialization/PropertyMap.h +++ b/lib/include/omni/serialization/PropertyMap.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/lib/include/omni/serialization/pointer.h b/lib/include/omni/serialization/pointer.h index aaea62df..9e2a2fb8 100644 --- a/lib/include/omni/serialization/pointer.h +++ b/lib/include/omni/serialization/pointer.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include namespace omni { diff --git a/lib/include/omni/visual/ProjectorViewMode.h b/lib/include/omni/visual/ProjectorViewMode.h index 3eccc6a2..1706b18c 100644 --- a/lib/include/omni/visual/ProjectorViewMode.h +++ b/lib/include/omni/visual/ProjectorViewMode.h @@ -21,6 +21,7 @@ #ifndef OMNI_VISUAL_PROJECTORVIEWMODE_H_ #define OMNI_VISUAL_PROJECTORVIEWMODE_H_ +#include #include namespace omni { diff --git a/lib/src/Id.cpp b/lib/src/Id.cpp deleted file mode 100755 index bc37d0d0..00000000 --- a/lib/src/Id.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* Copyright (c) 2014-2015 "Omnidome" by Michael Winkelmann - * Dome Mapping Projection Software (http://omnido.me). - * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo) - * - * This file is part of Omnidome. - * - * Omnidome is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include - -#include -#include -#include - -namespace omni -{ - Id::Id() - { - } - - Id::Id(QString const& _str) - { - make(_str); - } - - Id::Id(const char* _c) - { - make(QString(_c)); - } - - QString const& Id::str() const - { - return str_; - } - - Id::operator QString() const - { - return str_; - } - - bool Id::valid() const - { - return !str_.isEmpty(); - } - - bool Id::operator<(const Id& _rhs) const - { - return this->str_ < _rhs.str_; - } - - bool Id::operator!=(const Id& _rhs) const - { - return !(*this == _rhs); - } - - bool Id::operator==(const Id& _rhs) const - { - return this->str_ == _rhs.str_; - } - - void Id::make(QString const& _str) - { - str_ = ""; - // An id must not be empty - if (_str.isEmpty()) return; - - // An Id must begin with a letter - if (!_str[0].isLetter()) return; - - // An id must only contain alpha numerical characters - // and underscores - for (auto& c : _str) - { - if (!c.isLetterOrNumber() && (!c.isPunct())) return; - } - str_=_str; - } -} - -QDataStream& operator<<(QDataStream& _stream, omni::Id const& _id) -{ - omni::serialization::serialize(_stream,_id.str()); - return _stream; -} - -QDataStream& operator>>(QDataStream& _stream, omni::Id& _id) -{ - QString _str; - omni::serialization::deserialize(_stream,_str); - _id = omni::Id(_str); - return _stream; -} diff --git a/lib/src/mapping/Interface.cpp b/lib/src/mapping/Interface.cpp index 4e9720ee..6e8b48ea 100755 --- a/lib/src/mapping/Interface.cpp +++ b/lib/src/mapping/Interface.cpp @@ -199,7 +199,7 @@ namespace omni { return visual::ShaderCompiler::compile(":/shaders/mapping/Template.frag") + visual::ShaderCompiler::compile(QString( - ":/shaders/mapping/") + getTypeId().str() + + ":/shaders/mapping/") + getTypeId() + ".frag"); }