Skip to content
Snippets Groups Projects
Commit b08c465a authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

utils: Do not export matrix utils

Refs #70198
parent b5133ce7
No related branches found
No related tags found
No related merge requests found
...@@ -368,7 +368,6 @@ SET(libringclient_delegates_LIB_HDRS ...@@ -368,7 +368,6 @@ SET(libringclient_delegates_LIB_HDRS
SET( libringclient_extra_LIB_HDRS SET( libringclient_extra_LIB_HDRS
src/typedefs.h src/typedefs.h
src/typedefs.hpp
) )
IF(${ENABLE_LIBWRAP} MATCHES true) IF(${ENABLE_LIBWRAP} MATCHES true)
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
//Ring //Ring
#include "dbus/configurationmanager.h" #include "dbus/configurationmanager.h"
#include <certificatemodel.h> #include <certificatemodel.h>
#include "private/matrixutils.h"
class DetailsCache { class DetailsCache {
public: public:
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "certificate.h" #include "certificate.h"
#include "account.h" #include "account.h"
#include "delegates/certificateserializationdelegate.h" #include "delegates/certificateserializationdelegate.h"
#include "private/matrixutils.h"
enum class DetailType : uchar enum class DetailType : uchar
{ {
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include "account.h" #include "account.h"
#include "private/matrixutils.h"
class KeyExchangeModelPrivate class KeyExchangeModelPrivate
{ {
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include "call.h" #include "call.h"
#include "private/matrixutils.h"
//Qt //Qt
class QTimer; class QTimer;
......
/****************************************************************************
* Copyright (C) 2012-2015 by Savoir-Faire Linux *
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* *
* This library 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 2.1 of the License, or (at your option) any later version. *
* *
* This library 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 General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef MATRIXUTILS_H
#define MATRIXUTILS_H
//libSTDC++
#include <initializer_list>
#include <type_traits>
template<class T, class E>
struct TypedStateMachine
{
// no ctor/dtor and one public member variable for easy initialization
T _data[size_t(E::COUNT__)];
T& operator[](E v) {
if (size_t(v) >= size_t(E::COUNT__)) {
Q_ASSERT(false);
qDebug() << "State Machine Out of Bound" << size_t(v);
throw v;
}
return _data[size_t(v)];
}
const T& operator[](E v) const {
if (size_t(v) >= size_t(E::COUNT__)) {
Q_ASSERT(false);
qDebug() << "State Machine Out of Bound" << size_t(v);
throw v;
}
return _data[size_t(v)];
}
T *begin() {
return _data;
}
T *end() {
return _data + size_t(E::COUNT__);
}
};
/**
* This generic class represents a multidimensional enum class array.
* It safely converts them to integers. Each enum class needs a "COUNT__" item
* at the end."
*
* This struct enforces:
* * That the rows are indexed using enum_classes
* * That the size of the matrix matches the enum_class size
* * That the operators are within the matrix boundary
*/
template<class Row, typename Value, typename A = Value>
struct Matrix1D
{
Matrix1D(std::initializer_list< std::initializer_list<Value> > s);
explicit Matrix1D();
// Row is a built-in type ("int" by default)
Value operator[](Row v);
const Value operator[](Row v) const;
/**
* An Iterator for enum classes
*/
class Matrix1DEnumClassIter
{
public:
Matrix1DEnumClassIter (Matrix1D<Row, Value, A>* p_vec, int pos)
: pos_( pos ), p_vec_( p_vec ) {}
bool operator!= (const Matrix1DEnumClassIter& other) const;
bool operator== (const Matrix1DEnumClassIter& other) const;
void operator= (Value& other ) ;
void operator= (Value& other ) const;
//Row operator* () const;
//const Matrix1DEnumClassIter& operator++ ();
private:
int pos_;
Matrix1D<Row, Value, A> *p_vec_;
};
//Iterators
Matrix1DEnumClassIter begin();
Matrix1DEnumClassIter end();
// Only use for single reverse mappable arrays, will ASSERT otherwise
Row fromValue(const Value& value) const;
static void setReverseMapping(Matrix1D<Row,const char *> names);
//Setter
void setAt(Row,Value);
private:
QVector<Value> m_lData;
static QMap<A, Row> m_hReverseMapping;
};
/**
* A matrix with no value
*
* This is useful to use enum class in C++11 foreach loops
*
* @usage
* for (const MyEnum& value : EnumIterator<MyEnum>()) {
* std::cout << "Name: " << MyEnumNames[value] << std::endl;
* }
*/
template<class EnumClass>
struct EnumIterator
{
/**
* An Iterator for enum classes
*/
class EnumClassIter
{
public:
EnumClassIter (const EnumIterator<EnumClass>* p_vec, int pos)
: pos_( pos ), p_vec_( p_vec ) {}
bool operator!= (const EnumClassIter& other) const;
EnumClass operator* () const;
const EnumClassIter& operator++ ();
private:
int pos_;
const EnumIterator<EnumClass> *p_vec_;
};
EnumIterator();
//Iterators
EnumClassIter begin();
EnumClassIter end();
};
#include "matrixutils.hpp"
#endif
\ No newline at end of file
/**************************************************************************** /****************************************************************************
* Copyright (C) 2009-2015 by Savoir-Faire Linux * * Copyright (C) 2012-2015 by Savoir-Faire Linux *
* Author : Jrmy Quentin <jeremy.quentin@savoirfairelinux.com> * * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* * * *
* This library is free software; you can redistribute it and/or * * This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public * * modify it under the terms of the GNU Lesser General Public *
...@@ -135,13 +134,13 @@ bool Matrix1D<Row,Value,Accessor>::Matrix1DEnumClassIter::operator== (const Matr ...@@ -135,13 +134,13 @@ bool Matrix1D<Row,Value,Accessor>::Matrix1DEnumClassIter::operator== (const Matr
template<class Row, typename Value, typename Accessor> template<class Row, typename Value, typename Accessor>
void Matrix1D<Row,Value,Accessor>::Matrix1DEnumClassIter::operator= (Value& other) const void Matrix1D<Row,Value,Accessor>::Matrix1DEnumClassIter::operator= (Value& other) const
{ {
m_lData[pos_] = other; p_vec_->m_lData[pos_] = other;
} }
template<class Row, typename Value, typename Accessor> template<class Row, typename Value, typename Accessor>
void Matrix1D<Row,Value,Accessor>::Matrix1DEnumClassIter::operator= (Value& other) void Matrix1D<Row,Value,Accessor>::Matrix1DEnumClassIter::operator= (Value& other)
{ {
m_lData[pos_] = other; p_vec_->m_lData[pos_] = other;
} }
template<class Row, typename Value, typename Accessor> template<class Row, typename Value, typename Accessor>
......
...@@ -23,8 +23,9 @@ class Account; ...@@ -23,8 +23,9 @@ class Account;
class Certificate; class Certificate;
#include <certificate.h> #include <certificate.h>
#include "private/matrixutils.h"
class SecurityValidationModelPrivate class SecurityValidationModelPrivate : public QObject
{ {
public: public:
SecurityValidationModelPrivate(Account* account, SecurityValidationModel* parent); SecurityValidationModelPrivate(Account* account, SecurityValidationModel* parent);
...@@ -38,8 +39,6 @@ public: ...@@ -38,8 +39,6 @@ public:
Certificate* m_pCert; Certificate* m_pCert;
Certificate* m_pPrivateKey; Certificate* m_pPrivateKey;
//Mutator
void update();
///Messages to show to the end user ///Messages to show to the end user
static const QString messages[enum_class_size<SecurityValidationModel::AccountSecurityFlaw>()]; static const QString messages[enum_class_size<SecurityValidationModel::AccountSecurityFlaw>()];
...@@ -52,6 +51,10 @@ public: ...@@ -52,6 +51,10 @@ public:
static const TypedStateMachine< SecurityValidationModel::Severity , Certificate::Checks > certificateFlawSeverity ; static const TypedStateMachine< SecurityValidationModel::Severity , Certificate::Checks > certificateFlawSeverity ;
SecurityValidationModel* q_ptr; SecurityValidationModel* q_ptr;
public Q_SLOTS:
void update();
}; };
#endif #endif
\ No newline at end of file
...@@ -235,8 +235,14 @@ private: ...@@ -235,8 +235,14 @@ private:
}; };
SecurityValidationModelPrivate::SecurityValidationModelPrivate(Account* account, SecurityValidationModel* parent) : SecurityValidationModelPrivate::SecurityValidationModelPrivate(Account* account, SecurityValidationModel* parent) :
q_ptr(parent), m_pAccount(account), m_CurrentSecurityLevel(SecurityValidationModel::SecurityLevel::NONE) QObject(parent),q_ptr(parent), m_pAccount(account),
{ m_CurrentSecurityLevel(SecurityValidationModel::SecurityLevel::NONE)
{
QObject::connect(parent,&SecurityValidationModel::layoutChanged,this,&SecurityValidationModelPrivate::update);
QObject::connect(parent,&SecurityValidationModel::dataChanged ,this,&SecurityValidationModelPrivate::update);
QObject::connect(parent,&SecurityValidationModel::rowsInserted ,this,&SecurityValidationModelPrivate::update);
QObject::connect(parent,&SecurityValidationModel::rowsRemoved ,this,&SecurityValidationModelPrivate::update);
QObject::connect(parent,&SecurityValidationModel::modelReset ,this,&SecurityValidationModelPrivate::update);
} }
......
...@@ -27,10 +27,6 @@ ...@@ -27,10 +27,6 @@
#include <QtCore/QString> #include <QtCore/QString>
#include <QtCore/QDebug> #include <QtCore/QDebug>
//libSTDC++
#include <initializer_list>
#include <type_traits>
//Typedefs (required to avoid '<' and '>' in the DBus XML) //Typedefs (required to avoid '<' and '>' in the DBus XML)
typedef QMap<QString, QString> MapStringString ; typedef QMap<QString, QString> MapStringString ;
typedef QMap<QString, int> MapStringInt ; typedef QMap<QString, int> MapStringInt ;
...@@ -43,139 +39,6 @@ typedef QMap< QString, QVector<QString> > MapStringVectorStrin ...@@ -43,139 +39,6 @@ typedef QMap< QString, QVector<QString> > MapStringVectorStrin
typedef QMap< QString, QMap< QString, QStringList > > MapStringMapStringStringList ; typedef QMap< QString, QMap< QString, QStringList > > MapStringMapStringStringList ;
typedef QMap< QString, QStringList > MapStringStringList ; typedef QMap< QString, QStringList > MapStringStringList ;
template<class T, class E>
struct TypedStateMachine
{
// no ctor/dtor and one public member variable for easy initialization
T _data[size_t(E::COUNT__)];
T& operator[](E v) {
if (size_t(v) >= size_t(E::COUNT__)) {
Q_ASSERT(false);
qDebug() << "State Machine Out of Bound" << size_t(v);
throw v;
}
return _data[size_t(v)];
}
const T& operator[](E v) const {
if (size_t(v) >= size_t(E::COUNT__)) {
Q_ASSERT(false);
qDebug() << "State Machine Out of Bound" << size_t(v);
throw v;
}
return _data[size_t(v)];
}
T *begin() {
return _data;
}
T *end() {
return _data + size_t(E::COUNT__);
}
};
/**
* This generic class represents a multidimensional enum class array.
* It safely converts them to integers. Each enum class needs a "COUNT__" item
* at the end."
*
* This struct enforces:
* * That the rows are indexed using enum_classes
* * That the size of the matrix matches the enum_class size
* * That the operators are within the matrix boundary
*/
template<class Row, typename Value, typename A = Value>
struct Matrix1D
{
Matrix1D(std::initializer_list< std::initializer_list<Value> > s);
explicit Matrix1D();
// Row is a built-in type ("int" by default)
Value operator[](Row v);
const Value operator[](Row v) const;
/**
* An Iterator for enum classes
*/
class Matrix1DEnumClassIter
{
public:
Matrix1DEnumClassIter (const Matrix1D<Row, Value, A>* p_vec, int pos)
: pos_( pos ), p_vec_( p_vec ) {}
bool operator!= (const Matrix1DEnumClassIter& other) const;
bool operator== (const Matrix1DEnumClassIter& other) const;
void operator= (Value& other ) ;
void operator= (Value& other ) const;
//Row operator* () const;
//const Matrix1DEnumClassIter& operator++ ();
private:
int pos_;
const Matrix1D<Row, Value, A> *p_vec_;
};
//Iterators
Matrix1DEnumClassIter begin();
Matrix1DEnumClassIter end();
// Only use for single reverse mappable arrays, will ASSERT otherwise
Row fromValue(const Value& value) const;
static void setReverseMapping(Matrix1D<Row,const char *> names);
//Setter
void setAt(Row,Value);
private:
QVector<Value> m_lData;
static QMap<A, Row> m_hReverseMapping;
};
/**
* A matrix with no value
*
* This is useful to use enum class in C++11 foreach loops
*
* @usage
* for (const MyEnum& value : EnumIterator<MyEnum>()) {
* std::cout << "Name: " << MyEnumNames[value] << std::endl;
* }
*/
template<class EnumClass>
struct EnumIterator
{
/**
* An Iterator for enum classes
*/
class EnumClassIter
{
public:
EnumClassIter (const EnumIterator<EnumClass>* p_vec, int pos)
: pos_( pos ), p_vec_( p_vec ) {}
bool operator!= (const EnumClassIter& other) const;
EnumClass operator* () const;
const EnumClassIter& operator++ ();
private:
int pos_;
const EnumIterator<EnumClass> *p_vec_;
};
EnumIterator();
//Iterators
EnumClassIter begin();
EnumClassIter end();
};
/** /**
* This function add a safe way to get an enum class size * This function add a safe way to get an enum class size
* @note it cannot be "const" due to some compiler issues * @note it cannot be "const" due to some compiler issues
...@@ -188,12 +51,6 @@ template<typename A> constexpr int enum_class_size() { ...@@ -188,12 +51,6 @@ template<typename A> constexpr int enum_class_size() {
#define LIB_EXPORT Q_DECL_EXPORT #define LIB_EXPORT Q_DECL_EXPORT
#define LIB_IMPORT Q_DECL_IMPORT #define LIB_IMPORT Q_DECL_IMPORT
#if __GNUC__ < 4 || \
(__GNUC__ == 5 && (__GNUC_MINOR__ < 5 || \
(__GNUC_MINOR__ == 5)))
#define nullptr 0
#endif
//Doesn't work //Doesn't work
#if ((__GNUC_MINOR__ > 8) || (__GNUC_MINOR__ == 8)) #if ((__GNUC_MINOR__ > 8) || (__GNUC_MINOR__ == 8))
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
...@@ -204,7 +61,5 @@ template<typename A> constexpr int enum_class_size() { ...@@ -204,7 +61,5 @@ template<typename A> constexpr int enum_class_size() {
#define IGNORE_NULL(content) content #define IGNORE_NULL(content) content
#endif //ENABLE_IGNORE_NULL #endif //ENABLE_IGNORE_NULL
#include "typedefs.hpp"
#endif //TYPEDEFS_H #endif //TYPEDEFS_H
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "availableaccountmodel.h" #include "availableaccountmodel.h"
#include "delegates/pixmapmanipulationdelegate.h" #include "delegates/pixmapmanipulationdelegate.h"
#include "private/useractions.h" #include "private/useractions.h"
#include "private/matrixutils.h"
class ActiveUserActionModel : public QSortFilterProxyModel class ActiveUserActionModel : public QSortFilterProxyModel
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment