diff --git a/src/common/aka_array.hh b/src/common/aka_array.hh index 557051299..a1c08394c 100644 --- a/src/common/aka_array.hh +++ b/src/common/aka_array.hh @@ -1,392 +1,397 @@ /** * @file aka_array.hh * * @author Till Junge * @author Nicolas Richart * * @date creation: Fri Jun 18 2010 * @date last modification: Fri Jan 22 2016 * * @brief Array container for Akantu * This container differs from the std::vector from the fact it as 2 dimensions * a main dimension and the size stored per entries * * @section LICENSE * * Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de * Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des * Solides) * * Akantu 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. * * Akantu 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 Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_VECTOR_HH__ #define __AKANTU_VECTOR_HH__ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" /* -------------------------------------------------------------------------- */ #include #include /* -------------------------------------------------------------------------- */ namespace akantu { /// class that afford to store vectors in static memory class ArrayBase { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: - ArrayBase(ID id = ""); + explicit ArrayBase(ID id = ""); virtual ~ArrayBase(); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// get the amount of space allocated in bytes inline UInt getMemorySize() const; /// set the size to zero without freeing the allocated space inline void empty(); /// function to print the containt of the class virtual void printself(std::ostream & stream, int indent = 0) const; /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: /// Get the real size allocated in memory AKANTU_GET_MACRO(AllocatedSize, allocated_size, UInt); /// Get the Size of the Array AKANTU_GET_MACRO(Size, size, UInt); /// Get the number of components AKANTU_GET_MACRO(NbComponent, nb_component, UInt); /// Get the name of th array AKANTU_GET_MACRO(ID, id, const ID &); /// Set the name of th array AKANTU_SET_MACRO(ID, id, const ID &); // AKANTU_GET_MACRO(Tag, tag, const std::string &); // AKANTU_SET_MACRO(Tag, tag, const std::string &); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: /// id of the vector ID id; /// the size allocated UInt allocated_size{0}; /// the size used UInt size{0}; /// number of components UInt nb_component{1}; /// size of the stored type UInt size_of_type{0}; }; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ template class Array : public ArrayBase { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: using value_type = T; using reference = value_type &; using pointer_type = value_type *; using const_reference = const value_type &; /// Allocation of a new vector - inline Array(UInt size = 0, UInt nb_component = 1, const ID & id = ""); + explicit inline Array(UInt size = 0, UInt nb_component = 1, const ID & id = ""); /// Allocation of a new vector with a default value Array(UInt size, UInt nb_component, const value_type def_values[], const ID & id = ""); /// Allocation of a new vector with a default value Array(UInt size, UInt nb_component, const_reference value, const ID & id = ""); /// Copy constructor (deep copy if deep=true) Array(const Array & vect, bool deep = true, const ID & id = ""); #ifndef SWIG /// Copy constructor (deep copy) - Array(const std::vector & vect); + explicit Array(const std::vector & vect); #endif inline ~Array() override; Array & operator=(const Array & a) { /// this is to let STL allocate and copy arrays in the case of /// std::vector::resize AKANTU_DEBUG_ASSERT(this->size == 0, "Cannot copy akantu::Array"); return const_cast(a); } /* ------------------------------------------------------------------------ */ /* Iterator */ /* ------------------------------------------------------------------------ */ /// \todo protected: does not compile with intel check why public: template ::value> class iterator_internal; public: /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ template class const_iterator; template class iterator; /* ------------------------------------------------------------------------ */ /// iterator for Array of nb_component = 1 using scalar_iterator = iterator; /// const_iterator for Array of nb_component = 1 using const_scalar_iterator = const_iterator; /// iterator rerturning Vectors of size n on entries of Array with /// nb_component = n using vector_iterator = iterator>; /// const_iterator rerturning Vectors of n size on entries of Array with /// nb_component = n using const_vector_iterator = const_iterator>; /// iterator rerturning Matrices of size (m, n) on entries of Array with /// nb_component = m*n using matrix_iterator = iterator>; /// const iterator rerturning Matrices of size (m, n) on entries of Array with /// nb_component = m*n using const_matrix_iterator = const_iterator>; /* ------------------------------------------------------------------------ */ /// Get an iterator that behaves like a pointer T * to the first entry inline scalar_iterator begin(); /// Get an iterator that behaves like a pointer T * to the end of the Array inline scalar_iterator end(); /// Get a const_iterator to the beginging of an Array of scalar inline const_scalar_iterator begin() const; /// Get a const_iterator to the end of an Array of scalar inline const_scalar_iterator end() const; /// Get a scalar_iterator on the beginning of the Array considered of shape /// (new_size) inline scalar_iterator begin_reinterpret(UInt new_size); /// Get a scalar_iterator on the end of the Array considered of shape /// (new_size) inline scalar_iterator end_reinterpret(UInt new_size); /// Get a const_scalar_iterator on the beginning of the Array considered of /// shape (new_size) inline const_scalar_iterator begin_reinterpret(UInt new_size) const; /// Get a const_scalar_iterator on the end of the Array considered of shape /// (new_size) inline const_scalar_iterator end_reinterpret(UInt new_size) const; /* ------------------------------------------------------------------------ */ /// Get a vector_iterator on the beginning of the Array inline vector_iterator begin(UInt n); /// Get a vector_iterator on the end of the Array inline vector_iterator end(UInt n); /// Get a vector_iterator on the beginning of the Array inline const_vector_iterator begin(UInt n) const; /// Get a vector_iterator on the end of the Array inline const_vector_iterator end(UInt n) const; /// Get a vector_iterator on the begining of the Array considered of shape /// (new_size, n) inline vector_iterator begin_reinterpret(UInt n, UInt new_size); /// Get a vector_iterator on the end of the Array considered of shape /// (new_size, n) inline vector_iterator end_reinterpret(UInt n, UInt new_size); /// Get a const_vector_iterator on the begining of the Array considered of /// shape (new_size, n) inline const_vector_iterator begin_reinterpret(UInt n, UInt new_size) const; /// Get a const_vector_iterator on the end of the Array considered of shape /// (new_size, n) inline const_vector_iterator end_reinterpret(UInt n, UInt new_size) const; /* ------------------------------------------------------------------------ */ /// Get a matrix_iterator on the begining of the Array (Matrices of size (m, /// n)) inline matrix_iterator begin(UInt m, UInt n); /// Get a matrix_iterator on the end of the Array (Matrices of size (m, n)) inline matrix_iterator end(UInt m, UInt n); /// Get a const_matrix_iterator on the begining of the Array (Matrices of size /// (m, n)) inline const_matrix_iterator begin(UInt m, UInt n) const; /// Get a const_matrix_iterator on the end of the Array (Matrices of size (m, /// n)) inline const_matrix_iterator end(UInt m, UInt n) const; /// Get a matrix_iterator on the begining of the Array considered of shape /// (new_size, m*n) inline matrix_iterator begin_reinterpret(UInt m, UInt n, UInt size); /// Get a matrix_iterator on the end of the Array considered of shape /// (new_size, m*n) inline matrix_iterator end_reinterpret(UInt m, UInt n, UInt size); /// Get a const_matrix_iterator on the begining of the Array considered of /// shape (new_size, m*n) inline const_matrix_iterator begin_reinterpret(UInt m, UInt n, UInt size) const; /// Get a const_matrix_iterator on the end of the Array considered of shape /// (new_size, m*n) inline const_matrix_iterator end_reinterpret(UInt m, UInt n, UInt size) const; /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// append a tuple of size nb_component containing value inline void push_back(const_reference value); /// append a vector // inline void push_back(const value_type new_elem[]); /// append a Vector or a Matrix template