Skip to content
Snippets Groups Projects
Select Git revision
  • 0d62fc079fe94153b87b7bfdc74c33a2c598e9bc
  • master default protected
  • release/202005
  • release/202001
  • release/201912
  • release/201911
  • release/releaseWindowsTestOne
  • release/windowsReleaseTest
  • release/releaseTest
  • release/releaseWindowsTest
  • release/201910
  • release/qt/201910
  • release/windows-test/201910
  • release/201908
  • release/201906
  • release/201905
  • release/201904
  • release/201903
  • release/201902
  • release/201901
  • release/201812
  • 4.0.0
  • 2.2.0
  • 2.1.0
  • 2.0.1
  • 2.0.0
  • 1.4.1
  • 1.4.0
  • 1.3.0
  • 1.2.0
  • 1.1.0
31 results

accountcreator.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    enumclass_utils.h 8.55 KiB
    /*
     *  Copyright (C) 2014-2015 Savoir-Faire Linux Inc.
     *
     *  Author: Emmanuel Lepage <emmanuel.lepage@savoirfairelinux.com>
     *
     *  This program is free software; you can redistribute it and/or modify
     *  it under the terms of the GNU 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 General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program; if not, write to the Free Software
     *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
     *
     */
    #ifndef ENUM_CLASS_UTILS_H
    #define ENUM_CLASS_UTILS_H
    
    #include <map>
    #include "logger.h"
    #include <type_traits>
    #include <vector>
    #include <cassert>
    
    namespace ring {
    
    /**
     * This function adds a safe way to get an enum class size
     * @note it cannot be unsigned to avoid some compiler warnings
     */
    template<typename A> constexpr inline int enum_class_size() {
       return size_t(A::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);
    
        // 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 EnumClassIter
        {
        public:
            EnumClassIter (const Matrix1D<Row, Value, A>* p_vec, int pos)
                : pos_( pos ), p_vec_( p_vec ) {}
    
            bool operator!= (const EnumClassIter& other) const;