code format
This commit is contained in:
@@ -5,29 +5,29 @@
|
||||
* \~russian Класс для автоматизации приема структур
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Helper class to automate structs receive
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Helper class to automate structs receive
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser 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 free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||
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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIPARSEHELPER_H
|
||||
#define PIPARSEHELPER_H
|
||||
|
||||
#include "pip_io_utils_export.h"
|
||||
#include "piobject.h"
|
||||
#include "pip_io_utils_export.h"
|
||||
|
||||
|
||||
/** \class PIParseHelper
|
||||
@@ -84,17 +84,16 @@
|
||||
*
|
||||
**/
|
||||
|
||||
template <typename Key>
|
||||
template<typename Key>
|
||||
class PIParseHelper {
|
||||
public:
|
||||
|
||||
//! \brief Construct %PIParseHelper with target object \"p\"
|
||||
PIParseHelper(PIObject * p): parent(p) {}
|
||||
|
||||
|
||||
//! \brief Assign key \"key\" to event handler \"handler\" with 1 argument
|
||||
template <typename T, typename Ret>
|
||||
void assign(Key key, Ret(*handler)(void*,T)) {
|
||||
template<typename T, typename Ret>
|
||||
void assign(Key key, Ret (*handler)(void *, T)) {
|
||||
if (!parent) return;
|
||||
auto mf = PIObject::__meta_data().value(parent->classNameID());
|
||||
auto it = mf.eh_func.makeIterator();
|
||||
@@ -102,9 +101,10 @@ public:
|
||||
it.next();
|
||||
if (it.value().addr == handler) {
|
||||
void * addr = it.value().addr;
|
||||
auto func = [addr](PIObject * o, PIByteArray data){
|
||||
T v; data >> v;
|
||||
((void(*)(void*, T))addr)(o, v);
|
||||
auto func = [addr](PIObject * o, PIByteArray data) {
|
||||
T v;
|
||||
data >> v;
|
||||
((void (*)(void *, T))addr)(o, v);
|
||||
};
|
||||
functions[key] << func;
|
||||
break;
|
||||
@@ -114,8 +114,8 @@ public:
|
||||
|
||||
|
||||
//! \brief Assign key \"key\" to event handler \"handler\" without arguments
|
||||
template <typename Ret>
|
||||
void assign(Key key, Ret(*handler)(void*)) {
|
||||
template<typename Ret>
|
||||
void assign(Key key, Ret (*handler)(void *)) {
|
||||
if (!parent) return;
|
||||
auto mf = PIObject::__meta_data().value(parent->classNameID());
|
||||
auto it = mf.eh_func.makeIterator();
|
||||
@@ -123,9 +123,7 @@ public:
|
||||
it.next();
|
||||
if (it.value().addr == handler) {
|
||||
void * addr = it.value().addr;
|
||||
auto func = [addr](PIObject * o, PIByteArray ){
|
||||
((void(*)(void*))addr)(o);
|
||||
};
|
||||
auto func = [addr](PIObject * o, PIByteArray) { ((void (*)(void *))addr)(o); };
|
||||
functions[key] << func;
|
||||
break;
|
||||
}
|
||||
@@ -135,12 +133,13 @@ public:
|
||||
|
||||
//! \brief Assign key \"key\" to lambda-function \"func\" with 1 argument
|
||||
//! \note Important! Direct lambda functions are not allowed, see \ref PIParseHelper_lambda
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
void assign(Key key, std::function<void(T)> func) {
|
||||
if (!parent) return;
|
||||
auto lf = [func](PIObject * , PIByteArray data){
|
||||
auto lf = [func](PIObject *, PIByteArray data) {
|
||||
if (!data.isEmpty()) {
|
||||
T v; data >> v;
|
||||
T v;
|
||||
data >> v;
|
||||
func(v);
|
||||
}
|
||||
};
|
||||
@@ -152,9 +151,7 @@ public:
|
||||
//! \note Important! Direct lambda functions are not allowed, see \ref PIParseHelper_lambda
|
||||
void assign(Key key, std::function<void()> func) {
|
||||
if (!parent) return;
|
||||
auto lf = [func](PIObject * , PIByteArray ){
|
||||
func();
|
||||
};
|
||||
auto lf = [func](PIObject *, PIByteArray) { func(); };
|
||||
functions[key] << lf;
|
||||
}
|
||||
|
||||
@@ -170,7 +167,6 @@ public:
|
||||
private:
|
||||
PIMap<Key, PIVector<std::function<void(PIObject *, PIByteArray)>>> functions;
|
||||
PIObject * parent;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user