Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
Array.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 #ifndef _TLP_GEO_ARRAY_H
20 #define _TLP_GEO_ARRAY_H
21 
22 #include <cassert>
23 #include <iostream>
24 #include <tulip/tulipconf.h>
25 
26 namespace tlp {
27 
28 /**
29  * @brief Fixed-size array encapsulation.
30  * @ingroup Structures
31  * In debug mode, a bound check is performed at each access.
32  * Stream operators implementations are provided.
33  *
34  * @author : David Auber auber@tulip-software.org
35  */
36 template <typename Obj,unsigned int SIZE>
37 struct Array {
38  /**
39  * @brief array The underlying array of data.
40  */
41  Obj array[SIZE];
42 
43  /**
44  * @brief operator [] Read-only accessor.
45  * @param i The index of the element to read.
46  * @return The element at index i.
47  */
48  inline Obj operator[](const unsigned int i) const;
49 
50  /**
51  * @brief operator [] Write accessor.
52  * @param i The index at which to write a value.
53  * @return A reference to the value at index i.
54  */
55  inline Obj& operator[](const unsigned int i);
56 };
57 
58 template <typename Obj,unsigned int SIZE>
59 /**
60  * @brief operator << stream operator to easily print an array, or save it to a file.
61  * @param os The stream to output to.
62  * @param array The array to output.
63  * @return The stream to output to, to chain calls.
64  */
65 std::ostream& operator<<(std::ostream &os,const Array<Obj,SIZE> &array);
66 
67 template <typename Obj,unsigned int SIZE>
68 /**
69  * @brief operator >> stream operator to easily read an array
70  * @param is The stream to read from.
71  * @param array A reference to an array, that will be written to.
72  * @return The stream to read from, to chain calls.
73  */
74 std::istream& operator>>(std::istream &is, Array<Obj,SIZE> &array);
75 
76 //template <typename Obj,unsigned int SIZE>
77 //QDebug operator<<(QDebug dbg,const Array<Obj,SIZE>& s);
78 }
79 
80 #include "cxx/Array.cxx"
81 
82 #endif
Obj array[SIZE]
array The underlying array of data.
Definition: Array.h:41
std::istream & operator>>(std::istream &is, Array< Obj, SIZE > &array)
operator >> stream operator to easily read an array
Definition: Array.cxx:58
Obj operator[](const unsigned int i) const
operator [] Read-only accessor.
Definition: Array.cxx:22
Fixed-size array encapsulation.In debug mode, a bound check is performed at each access. Stream operators implementations are provided.
Definition: Array.h:37