FRWGraph.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  FRWGraph
26 
27 Description
28  This class is an implementation of a graph with the fixed row width.
29  The implementation is memory efficient.
30 
31 SourceFiles
32  FRWGraphI.H
33  FRWGraph.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef FRWGraph_H
38 #define FRWGraph_H
39 
40 #include "label.H"
41 #include "LongList.H"
42 #include "FixedList.H"
43 #include "bool.H"
44 #include "error.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
52 
53 template<class T, label width>
54 class FRWGraph;
55 
56 template<class T, label width>
57 Ostream& operator<<
58 (
59  Ostream&,
60  const FRWGraph<T, width>&
61 );
62 template<class T, label width>
63 Istream& operator>>
64 (
65  Istream&,
67 );
68 
69 /*---------------------------------------------------------------------------*\
70  Class FRWGraph Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 template<class T, label width>
74 class FRWGraph
75 {
76  // Private data
77  //- list containing the data
79 
80  //- number of rows
81  label nRows_;
82 
83  // Private member functions
84  //- check index
85  void checkIndex(const label i, const label j) const;
86 
87 public:
88 
89  // Constructors
90 
91  //- Construct null
92  inline FRWGraph();
93 
94  //- Construct given size
95  explicit inline FRWGraph(const label size);
96 
97  //- Construct to given size and initialize
98  explicit inline FRWGraph(const label size, const T& t);
99 
100  //- Copy contructor
101  inline FRWGraph(const FRWGraph<T, width>&);
102 
103  // Destructor
104 
105  inline ~FRWGraph();
106 
107  // Member Functions
108 
109  // Access
110 
111  //- Returns the number of rows
112  inline label size() const;
113 
114  //- Returns the size of a given row (obsolete)
115  inline label sizeOfRow(const label rowI) const;
116 
117  // Edit
118 
119  //- Reset the number of rows
120  void setSize(const label);
121 
122  //- Clear the graph
123  // Allocated size does not change
124  void clear();
125 
126  // Member Operators
127 
128  //- Append a row at the end of the graph
129  inline void appendFixedList(const FixedList<T, width>& l);
130 
131  //- Set row with the list
132  inline void setRow(const label rowI, const FixedList<T, width>& l);
133 
134  //- check if the element is in the given row (takes linear time)
135  inline bool contains(const label rowI, const T& e) const;
136  inline label containsAtPosition(const label rowI, const T& e) const;
137 
138  //- get and set operators
139  inline const T& operator()(const label i, const label j) const;
140  inline T& operator()(const label i, const label j);
141 
142  //- Assignment operator
143  inline void operator=(const FRWGraph<T, width>&);
144 
145 
146  // IOstream operators
147 
148  // Write FRWGraph to Ostream.
149  friend Ostream& operator<< <T, width>
150  (
151  Ostream&,
152  const FRWGraph<T, width>&
153  );
154 
155  //- Read from Istream, discarding contents of existing FRWGraph.
156 /* friend Istream& operator>> <T, width>
157  (
158  Istream&,
159  FRWGraph<T, width>&
160  );
161 */
162 };
163 
164 
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 
167 } // End namespace Foam
168 
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170 
171 #include "FRWGraphI.H"
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 #ifdef NoRepository
176 # include "FRWGraph.C"
177 #endif
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 #endif
182 
183 // ************************************************************************* //
Foam::FRWGraph::clear
void clear()
Clear the graph.
Definition: FRWGraphI.H:121
LongList.H
Foam::FRWGraph::setRow
void setRow(const label rowI, const FixedList< T, width > &l)
Set row with the list.
Definition: FRWGraphI.H:140
Foam::FRWGraph::operator=
void operator=(const FRWGraph< T, width > &)
Assignment operator.
Definition: FRWGraphI.H:212
FRWGraphI.H
Foam::FRWGraph::size
label size() const
Returns the number of rows.
Definition: FRWGraphI.H:102
Foam::FRWGraph::~FRWGraph
~FRWGraph()
Definition: FRWGraphI.H:95
Foam::FRWGraph::setSize
void setSize(const label)
Reset the number of rows.
Definition: FRWGraphI.H:114
Foam::LongList< T >
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
error.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
Foam::FRWGraph::contains
bool contains(const label rowI, const T &e) const
check if the element is in the given row (takes linear time)
Definition: FRWGraphI.H:152
bool.H
System bool.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::FRWGraph::nRows_
label nRows_
number of rows
Definition: FRWGraph.H:80
Foam::FRWGraph::containsAtPosition
label containsAtPosition(const label rowI, const T &e) const
Definition: FRWGraphI.H:168
Foam::FRWGraph::operator()
const T & operator()(const label i, const label j) const
get and set operators
Definition: FRWGraphI.H:185
Foam::FRWGraph::data_
LongList< T > data_
list containing the data
Definition: FRWGraph.H:77
label.H
Foam::FixedList
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:53
Foam::FRWGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the size of a given row (obsolete)
Definition: FRWGraphI.H:108
Foam::FRWGraph::checkIndex
void checkIndex(const label i, const label j) const
check index
Definition: FRWGraphI.H:27
FRWGraph.C
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
FixedList.H
Foam::FRWGraph::FRWGraph
FRWGraph()
Construct null.
Definition: FRWGraphI.H:54
Foam::FRWGraph
Definition: FRWGraph.H:53
Foam::FRWGraph::appendFixedList
void appendFixedList(const FixedList< T, width > &l)
Append a row at the end of the graph.
Definition: FRWGraphI.H:129