graphRow.H 4.01 KB
Newer Older
Franjo's avatar
Franjo committed
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | cfMesh: A library for mesh generation
   \\    /   O peration     |
    \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
     \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
Andrew Heather's avatar
Andrew Heather committed
9
    This file is part of OpenFOAM.
Franjo's avatar
Franjo committed
10

Andrew Heather's avatar
Andrew Heather committed
11 12 13 14
    OpenFOAM 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.
Franjo's avatar
Franjo committed
15

Andrew Heather's avatar
Andrew Heather committed
16
    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
Franjo's avatar
Franjo committed
17 18 19 20 21
    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
Andrew Heather's avatar
Andrew Heather committed
22
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
Franjo's avatar
Franjo committed
23 24

Class
25
    Foam::graphRow
Franjo's avatar
Franjo committed
26 27

Description
28
    This class provides non-const access to a row of a graph
Franjo's avatar
Franjo committed
29 30 31 32 33 34 35 36 37 38 39 40 41

SourceFiles
    graphRowI.H

\*---------------------------------------------------------------------------*/

#ifndef graphRow_H
#define graphRow_H

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
42 43 44
class Ostream;
template<class graphType> class graphRow;
template<class graphType> class graphConstRow;
Andrew Heather's avatar
Andrew Heather committed
45

Franjo's avatar
Franjo committed
46 47 48
template<class graphType>
Ostream& operator<<(Ostream&, const graphRow<graphType>&);

49

Franjo's avatar
Franjo committed
50
/*---------------------------------------------------------------------------*\
Andrew Heather's avatar
Andrew Heather committed
51
                          Class graphRow Declaration
Franjo's avatar
Franjo committed
52 53 54 55 56 57
\*---------------------------------------------------------------------------*/

template<class graphType>
class graphRow
{
    // Private data
Andrew Heather's avatar
Andrew Heather committed
58

59
        //- Reference to the graph
Franjo's avatar
Franjo committed
60
        graphType& data_;
Andrew Heather's avatar
Andrew Heather committed
61

62
        //- Row number
Franjo's avatar
Franjo committed
63 64
        const label rowI_;

65 66
    // Allow copy construct from non-const to const version
    friend class graphConstRow<graphType>;
Andrew Heather's avatar
Andrew Heather committed
67 68


Franjo's avatar
Franjo committed
69 70 71 72 73
public:

    // Constructors

        //- Construct from graph and row number
74
        inline graphRow(graphType& g, const label i);
Franjo's avatar
Franjo committed
75 76

        //- Copy contructor
77
        inline graphRow(const graphRow<graphType>& r);
Franjo's avatar
Franjo committed
78 79


Andrew Heather's avatar
Andrew Heather committed
80
    //- Destructor
81
    ~graphRow() = default;
Andrew Heather's avatar
Andrew Heather committed
82

Franjo's avatar
Franjo committed
83 84 85

    // Member Functions

86
        //- Return the number of elements in the row
Franjo's avatar
Franjo committed
87 88
        inline label size() const;

89 90
        //- Reset the number of elements in the row
        inline void setSize(const label s);
Franjo's avatar
Franjo committed
91

92
        //- Clear the row
Franjo's avatar
Franjo committed
93 94
        inline void clear();

Andrew Heather's avatar
Andrew Heather committed
95

Franjo's avatar
Franjo committed
96
    // Member Operators
Andrew Heather's avatar
Andrew Heather committed
97

Franjo's avatar
Franjo committed
98 99
        //- Append an element to the given row
        inline void append(const label);
Andrew Heather's avatar
Andrew Heather committed
100

Franjo's avatar
Franjo committed
101 102
        //- Append an element to the given row if it does not exist there
        inline void appendIfNotIn(const label);
Andrew Heather's avatar
Andrew Heather committed
103

Franjo's avatar
Franjo committed
104 105
        //- check if the element is in the given row (takes linear time)
        inline bool contains(const label e) const;
106 107
        inline bool found(const label e) const;
        inline label find(const label e) const;
Andrew Heather's avatar
Andrew Heather committed
108

Franjo's avatar
Franjo committed
109 110 111
        //- set and get operators
        inline label operator[](const label) const;
        inline label& operator[](const label);
Andrew Heather's avatar
Andrew Heather committed
112

113 114
        //- Copy contents from another row
        inline void operator=(const graphRow<graphType>& rhs);
Andrew Heather's avatar
Andrew Heather committed
115

116 117 118
        //- Copy contents from a list
        template<class ListType>
        inline void operator=(const ListType& rhs);
Franjo's avatar
Franjo committed
119

Andrew Heather's avatar
Andrew Heather committed
120

Franjo's avatar
Franjo committed
121 122
    // IOstream operators

123
        //- Write graphRow contents to Ostream.
Franjo's avatar
Franjo committed
124 125
        friend Ostream& operator<< <graphType>
        (
126 127
            Ostream& os,
            const graphRow<graphType>& r
Franjo's avatar
Franjo committed
128 129 130 131
        );

};

Andrew Heather's avatar
Andrew Heather committed
132

Franjo's avatar
Franjo committed
133 134 135 136 137 138 139 140 141 142 143 144 145
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "graphRowI.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //