Commit d54ed819 authored by Nina Džugasová's avatar Nina Džugasová Committed by Tomáš Oberhuber
Browse files

Added documentation of 1-,2- and 3-dimensional StaticArray.

parent 52e9e14d
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -20,7 +20,7 @@ namespace Containers {
template< int, typename > class StaticArray;
template< int, typename > class StaticArray;


/**
/**
 * Array handles memory allocation and sharing of the same data between more Arrays.
 * \brief Array handles memory allocation and sharing of the same data between more Arrays.
 *
 *
 * \tparam Value Type of array values.
 * \tparam Value Type of array values.
 * \tparam Device Device type.
 * \tparam Device Device type.
+121 −21
Original line number Original line Diff line number Diff line
@@ -16,6 +16,12 @@
namespace TNL {
namespace TNL {
namespace Containers {   
namespace Containers {   


/**
 * \brief Array with constant size.
 *
 * \param Size Size of static array. Number of its elements.
 * \param Value Type of the values in static array.
 */
template< int Size, typename Value >
template< int Size, typename Value >
class StaticArray
class StaticArray
{
{
@@ -27,13 +33,17 @@ class StaticArray
   /**
   /**
    * \brief Basic constructor.
    * \brief Basic constructor.
    *
    *
    * Constructs an empty static array. Once it is constructed, its size can not be changed.
    * Constructs an empty static array.
    */
    */
   __cuda_callable__
   __cuda_callable__
   inline StaticArray();
   inline StaticArray();


   /**
   /**
    * \brief Constructor that sets all array components (with the number of \e Size) to value \e v.
    * \brief Constructor that sets all array components (with the number of \e Size) to value \e v.
    *
    * Once this static array is constructed, its size can not be changed.
    * \tparam _unused
    * \param v[Size] 
    */
    */
   // Note: the template avoids ambiguity of overloaded functions with literal 0 and pointer
   // Note: the template avoids ambiguity of overloaded functions with literal 0 and pointer
   // reference: https://stackoverflow.com/q/4610503
   // reference: https://stackoverflow.com/q/4610503
@@ -43,6 +53,8 @@ class StaticArray


   /**
   /**
    * \brief Constructor that sets all array components to value \e v.
    * \brief Constructor that sets all array components to value \e v.
    *
    * \param v Reference to a value.
    */
    */
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const Value& v );
   inline StaticArray( const Value& v );
@@ -67,11 +79,14 @@ class StaticArray
   inline int getSize() const;
   inline int getSize() const;


   /**
   /**
    * \brief Gets all data of this array.
    * \brief Gets all data of this static array.
    */
    */
   __cuda_callable__
   __cuda_callable__
   inline Value* getData();
   inline Value* getData();


   /**
    * \brief Gets all data of this static array.
    */
   __cuda_callable__
   __cuda_callable__
   inline const Value* getData() const;
   inline const Value* getData() const;


@@ -144,14 +159,27 @@ class StaticArray
    */
    */
   bool load( File& file);
   bool load( File& file);


   /**
    * \brief Sorts the elements in this static array into ascending order.
    */
   void sort();
   void sort();
 
 
   /**
    * \brief Writes the array values into stream \e str with specified \e separator.
    *
    * @param str Reference to a stream.
    * @param separator Character separating the array values in the stream \e str. 
    * Is set to " " by default.
    */
   std::ostream& write( std::ostream& str, const char* separator = " " ) const;
   std::ostream& write( std::ostream& str, const char* separator = " " ) const;


   protected:
   protected:
   Value data[ Size ];
   Value data[ Size ];
};
};


/**
 * \brief Specific static array with the size of 1. Works like the class StaticArray.
 */
template< typename Value >
template< typename Value >
class StaticArray< 1, Value >
class StaticArray< 1, Value >
{
{
@@ -160,58 +188,72 @@ class StaticArray< 1, Value >
   typedef int     IndexType;
   typedef int     IndexType;
   enum { size = 1 };
   enum { size = 1 };


   /** \brief See StaticArray::StaticArray().*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray();
   inline StaticArray();


   /** \brief See StaticArray::StaticArray(const Value v[Size]).*/
   // Note: the template avoids ambiguity of overloaded functions with literal 0 and pointer
   // Note: the template avoids ambiguity of overloaded functions with literal 0 and pointer
   // reference: https://stackoverflow.com/q/4610503
   // reference: https://stackoverflow.com/q/4610503
   template< typename _unused = void >
   template< typename _unused = void >
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const Value v[ size ] );
   inline StaticArray( const Value v[ size ] );


   /** \brief See StaticArray::StaticArray(const Value& v).*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const Value& v );
   inline StaticArray( const Value& v );


   //! Copy constructor
   /** \brief See StaticArray::StaticArray( const StaticArray< Size, Value >& v ).*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const StaticArray< size, Value >& v );
   inline StaticArray( const StaticArray< size, Value >& v );


   /** \brief See StaticArray::getType().*/
   static String getType();
   static String getType();


   /** \brief See StaticArray::getSize().*/
   __cuda_callable__
   __cuda_callable__
   inline int getSize() const;
   inline int getSize() const;


   /** \brief See StaticArray::getData().*/
   __cuda_callable__
   __cuda_callable__
   inline Value* getData();
   inline Value* getData();


   /** \brief See StaticArray::getData() const.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value* getData() const;
   inline const Value* getData() const;


   
   /** \brief See StaticArray::operator[]( int i ) const.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value& operator[]( int i ) const;
   inline const Value& operator[]( int i ) const;


   /** \brief See StaticArray::operator[]( int i ).*/
   __cuda_callable__
   __cuda_callable__
   inline Value& operator[]( int i );
   inline Value& operator[]( int i );


   //! Returns the first coordinate
   /** \brief Returns the first coordinate - the first element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline Value& x();
   inline Value& x();


   //! Returns the first coordinate
   /** \brief Returns the first coordinate - the first element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value& x() const;
   inline const Value& x() const;


   /** \brief Similar to StaticArray::operator = ( const StaticArray< Size, Value >& array ) only with Size equal to 1.*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray< 1, Value >& operator = ( const StaticArray< 1, Value >& array );
   inline StaticArray< 1, Value >& operator = ( const StaticArray< 1, Value >& array );


   /** \brief See StaticArray::operator = (const Array& array).*/
   template< typename Array >
   template< typename Array >
   __cuda_callable__
   __cuda_callable__
   inline StaticArray< 1, Value >& operator = ( const Array& array );
   inline StaticArray< 1, Value >& operator = ( const Array& array );


   /** \brief See StaticArray::operator == (const Array& array) const.*/
   template< typename Array >
   template< typename Array >
   __cuda_callable__
   __cuda_callable__
   inline bool operator == ( const Array& array ) const;
   inline bool operator == ( const Array& array ) const;


   /** \brief See StaticArray::operator != (const Array& array) const.*/
   template< typename Array >
   template< typename Array >
   __cuda_callable__
   __cuda_callable__
   inline bool operator != ( const Array& array ) const;
   inline bool operator != ( const Array& array ) const;
@@ -220,22 +262,30 @@ class StaticArray< 1, Value >
   __cuda_callable__
   __cuda_callable__
   operator StaticArray< 1, OtherValue >() const;
   operator StaticArray< 1, OtherValue >() const;


   /** \brief See StaticArray::setValue().*/
   __cuda_callable__
   __cuda_callable__
   inline
   inline
   void setValue( const ValueType& val );
   void setValue( const ValueType& val );


   /** \brief See StaticArray::save().*/
   bool save( File& file ) const;
   bool save( File& file ) const;


   /** \brief See StaticArray::load().*/
   bool load( File& file);
   bool load( File& file);


   /** \brief See StaticArray::sort().*/
   void sort();
   void sort();
 
 
   /** \brief See StaticArray::write().*/
   std::ostream& write( std::ostream& str, const char* separator = " " ) const;
   std::ostream& write( std::ostream& str, const char* separator = " " ) const;


   protected:
   protected:
   Value data[ size ];
   Value data[ size ];
};
};


/**
 * \brief Specific static array with the size of 2. Works like the class StaticArray.
 */
template< typename Value >
template< typename Value >
class StaticArray< 2, Value >
class StaticArray< 2, Value >
{
{
@@ -244,70 +294,88 @@ class StaticArray< 2, Value >
   typedef int     IndexType;
   typedef int     IndexType;
   enum { size = 2 };
   enum { size = 2 };


   /** \brief See StaticArray::StaticArray().*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray();
   inline StaticArray();


   /** \brief See StaticArray::StaticArray(const Value v[Size]).*/
   // Note: the template avoids ambiguity of overloaded functions with literal 0 and pointer
   // Note: the template avoids ambiguity of overloaded functions with literal 0 and pointer
   // reference: https://stackoverflow.com/q/4610503
   // reference: https://stackoverflow.com/q/4610503
   template< typename _unused = void >
   template< typename _unused = void >
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const Value v[ size ] );
   inline StaticArray( const Value v[ size ] );


   //! This sets all vector components to v
   /** \brief See StaticArray::StaticArray(const Value& v).*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const Value& v );
   inline StaticArray( const Value& v );


   /**
    * \brief Constructor that sets the two array components to value \e v1 and \e v2.
    *
    * \param v1 Reference to the value of first array/vector component.
    * \param v2 Reference to the value of second array/vector component.
    */
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const Value& v1, const Value& v2 );
   inline StaticArray( const Value& v1, const Value& v2 );


   //! Copy constructor
   /** \brief See StaticArray::StaticArray( const StaticArray< Size, Value >& v ).*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const StaticArray< size, Value >& v );
   inline StaticArray( const StaticArray< size, Value >& v );


   /** \brief See StaticArray::getType().*/
   static String getType();
   static String getType();


   /** \brief See StaticArray::getSize().*/
   __cuda_callable__
   __cuda_callable__
   inline int getSize() const;
   inline int getSize() const;


   /** \brief See StaticArray::getData().*/
   __cuda_callable__
   __cuda_callable__
   inline Value* getData();
   inline Value* getData();


   /** \brief See StaticArray::getData() const.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value* getData() const;
   inline const Value* getData() const;


   /** \brief See StaticArray::operator[]( int i ) const.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value& operator[]( int i ) const;
   inline const Value& operator[]( int i ) const;


   /** \brief See StaticArray::operator[]( int i ).*/
   __cuda_callable__
   __cuda_callable__
   inline Value& operator[]( int i );
   inline Value& operator[]( int i );


   //! Returns the first coordinate
   /** \brief Returns the first coordinate - the first element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline Value& x();
   inline Value& x();


   //! Returns the first coordinate
   /** \brief Returns the first coordinate - the first element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value& x() const;
   inline const Value& x() const;


   //! Returns the second coordinate
   /** \brief Returns the second coordinate - the second element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline Value& y();
   inline Value& y();


   //! Returns the second coordinate
   /** \brief Returns the second coordinate - the second element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value& y() const;
   inline const Value& y() const;


   /** \brief Similar to StaticArray::operator = ( const StaticArray< Size, Value >& array ) only with Size equal to 2.*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray< 2, Value >& operator = ( const StaticArray< 2, Value >& array );
   inline StaticArray< 2, Value >& operator = ( const StaticArray< 2, Value >& array );


   /** \brief See StaticArray::operator = (const Array& array).*/
   template< typename Array >
   template< typename Array >
   __cuda_callable__
   __cuda_callable__
   inline StaticArray< 2, Value >& operator = ( const Array& array );
   inline StaticArray< 2, Value >& operator = ( const Array& array );


   /** \brief See StaticArray::operator == (const Array& array) const.*/
   template< typename Array >
   template< typename Array >
   __cuda_callable__
   __cuda_callable__
   inline bool operator == ( const Array& array ) const;
   inline bool operator == ( const Array& array ) const;


   /** \brief See StaticArray::operator != (const Array& array) const.*/
   template< typename Array >
   template< typename Array >
   __cuda_callable__
   __cuda_callable__
   inline bool operator != ( const Array& array ) const;
   inline bool operator != ( const Array& array ) const;
@@ -316,21 +384,29 @@ class StaticArray< 2, Value >
   __cuda_callable__
   __cuda_callable__
   operator StaticArray< 2, OtherValue >() const;
   operator StaticArray< 2, OtherValue >() const;
 
 
   /** \brief See StaticArray::setValue().*/
   __cuda_callable__
   __cuda_callable__
   inline void setValue( const ValueType& val );
   inline void setValue( const ValueType& val );


   /** \brief See StaticArray::save().*/
   bool save( File& file ) const;
   bool save( File& file ) const;


   /** \brief See StaticArray::load().*/
   bool load( File& file);
   bool load( File& file);


   /** \brief See StaticArray::sort().*/
   void sort();
   void sort();


   /** \brief See StaticArray::write().*/
   std::ostream& write( std::ostream& str, const char* separator = " " ) const;
   std::ostream& write( std::ostream& str, const char* separator = " " ) const;


   protected:
   protected:
   Value data[ size ];
   Value data[ size ];
};
};


/**
 * \brief Specific static array with the size of 3. Works like the class StaticArray.
 */
template< typename Value >
template< typename Value >
class StaticArray< 3, Value >
class StaticArray< 3, Value >
{
{
@@ -339,78 +415,97 @@ class StaticArray< 3, Value >
   typedef int     IndexType;
   typedef int     IndexType;
   enum { size = 3 };
   enum { size = 3 };


   /** \brief See StaticArray::StaticArray().*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray();
   inline StaticArray();


   /** \brief See StaticArray::StaticArray(const Value v[ size ]).*/
   // Note: the template avoids ambiguity of overloaded functions with literal 0 and pointer
   // Note: the template avoids ambiguity of overloaded functions with literal 0 and pointer
   // reference: https://stackoverflow.com/q/4610503
   // reference: https://stackoverflow.com/q/4610503
   template< typename _unused = void >
   template< typename _unused = void >
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const Value v[ size ] );
   inline StaticArray( const Value v[ size ] );


   //! This sets all vector components to v
   /** \brief See StaticArray::StaticArray(const Value& v).*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const Value& v );
   inline StaticArray( const Value& v );


   /**
    * \brief Constructor that sets the three array components to value \e v1 \e v2 and \e v3.
    *
    * \param v1 Reference to the value of first array/vector component.
    * \param v2 Reference to the value of second array/vector component.
    * \param v3 Reference to the value of third array/vector component.
    */
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const Value& v1, const Value& v2, const Value& v3 );
   inline StaticArray( const Value& v1, const Value& v2, const Value& v3 );


   //! Copy constructor
   /** \brief See StaticArray::StaticArray( const StaticArray< Size, Value >& v ).*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray( const StaticArray< size, Value >& v );
   inline StaticArray( const StaticArray< size, Value >& v );


   /** \brief See StaticArray::getType().*/
   static String getType();
   static String getType();


   /** \brief See StaticArray::getSize().*/
   __cuda_callable__
   __cuda_callable__
   inline int getSize() const;
   inline int getSize() const;


   /** \brief See StaticArray::getData().*/
   __cuda_callable__
   __cuda_callable__
   inline Value* getData();
   inline Value* getData();


   /** \brief See StaticArray::getData() const.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value* getData() const;
   inline const Value* getData() const;


   /** \brief See StaticArray::operator[]( int i ) const.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value& operator[]( int i ) const;
   inline const Value& operator[]( int i ) const;


   /** \brief See StaticArray::operator[]( int i ).*/
   __cuda_callable__
   __cuda_callable__
   inline Value& operator[]( int i );
   inline Value& operator[]( int i );


   //! Returns the first coordinate
   /** \brief Returns the first coordinate - the first element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline Value& x();
   inline Value& x();


   //! Returns the first coordinate
   /** \brief Returns the first coordinate - the first element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value& x() const;
   inline const Value& x() const;


   //! Returns the second coordinate
   /** \brief Returns the second coordinate - the second element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline Value& y();
   inline Value& y();


   //! Returns the second coordinate
   /** \brief Returns the second coordinate - the second element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value& y() const;
   inline const Value& y() const;


   //! Returns the third coordinate
   /** \brief Returns the third coordinate - the third element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline Value& z();
   inline Value& z();


   //! Returns the third coordinate
   /** \brief Returns the third coordinate - the third element of this static array.*/
   __cuda_callable__
   __cuda_callable__
   inline const Value& z() const;
   inline const Value& z() const;


   /** \brief Similar to StaticArray::operator = ( const StaticArray< Size, Value >& array ) only with Size equal to 3.*/
   __cuda_callable__
   __cuda_callable__
   inline StaticArray< 3, Value >& operator = ( const StaticArray< 3, Value >& array );
   inline StaticArray< 3, Value >& operator = ( const StaticArray< 3, Value >& array );


   /** \brief See StaticArray::operator = (const Array& array).*/
   template< typename Array >
   template< typename Array >
   __cuda_callable__
   __cuda_callable__
   inline StaticArray< 3, Value >& operator = ( const Array& array );
   inline StaticArray< 3, Value >& operator = ( const Array& array );


   /** \brief See StaticArray::operator == (const Array& array) const.*/
   template< typename Array >
   template< typename Array >
   __cuda_callable__
   __cuda_callable__
   inline bool operator == ( const Array& array ) const;
   inline bool operator == ( const Array& array ) const;


   /** \brief See StaticArray::operator != (const Array& array) const.*/
   template< typename Array >
   template< typename Array >
   __cuda_callable__
   __cuda_callable__
   inline bool operator != ( const Array& array ) const;
   inline bool operator != ( const Array& array ) const;
@@ -419,15 +514,20 @@ class StaticArray< 3, Value >
   __cuda_callable__
   __cuda_callable__
   operator StaticArray< 3, OtherValue >() const;
   operator StaticArray< 3, OtherValue >() const;


   /** \brief See StaticArray::setValue().*/
   __cuda_callable__
   __cuda_callable__
   inline void setValue( const ValueType& val );
   inline void setValue( const ValueType& val );


   /** \brief See StaticArray::save().*/
   bool save( File& file ) const;
   bool save( File& file ) const;


   /** \brief See StaticArray::load().*/
   bool load( File& file);
   bool load( File& file);


   /** \brief See StaticArray::sort().*/
   void sort();
   void sort();


   /** \brief See StaticArray::write().*/
   std::ostream& write( std::ostream& str, const char* separator = " " ) const;
   std::ostream& write( std::ostream& str, const char* separator = " " ) const;


   protected:
   protected: