Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / graph / graph.H
blob8bd1fef254c2d12732cdb1957775b04716d5aa1a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::graph
27 Description
28     Class to create, store and output qgraph files.
30 SourceFiles
31     graph.C
33 \*---------------------------------------------------------------------------*/
35 #ifndef graph_H
36 #define graph_H
38 #include "foamString.H"
39 #include "point.H"
40 #include "HashPtrTable.H"
41 #include "curve.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
48 // Forward declaration of friend functions and operators
50 class graph;
52 Ostream& operator<<(Ostream&, const graph&);
55 /*---------------------------------------------------------------------------*\
56                            Class graph Declaration
57 \*---------------------------------------------------------------------------*/
59 class graph
61     public HashPtrTable<curve>
63     // Private Data
65         string title_;
66         string xName_;
67         string yName_;
69         scalarField x_;
72         struct xy
73         {
74             scalar x_, y_;
76             xy()
77             {}
79         // Friend Operators
81             friend bool operator==(const xy& a, const xy& b)
82             {
83                 return equal(a.x_, b.x_) && equal(a.y_, b.y_);
84             }
86             friend bool operator!=(const xy& a, const xy& b)
87             {
88                 return !(a == b);
89             }
91             friend Istream& operator>>(Istream& is, xy& xyd)
92             {
93                 is >> xyd.x_ >> xyd.y_;
94                 return is;
95             }
97             friend Ostream& operator<<(Ostream& os, const xy& xyd)
98             {
99                 os << xyd.x_ << ' ' << xyd.y_;
100                 return os;
101             }
102         };
105     // Private Member Functions
107         void readCurves(Istream&);
110 public:
112     // Constructors
114         //- Construct from title and labels (no curves)
115         graph
116         (
117             const string& title,
118             const string& xName,
119             const string& yName,
120             const scalarField& x
121         );
123         //- Construct from title, labels and y data for 1 curve
124         graph
125         (
126             const string& title,
127             const string& xName,
128             const string& yName,
129             const scalarField& x,
130             const scalarField& y
131         );
133         //- Construct from Istream given title and labels
134         graph
135         (
136             const string& title,
137             const string& xName,
138             const string& yName,
139             Istream& is
140         );
142         //- Construct from Istream
143         graph(Istream& is);
146     // Member functions
148         // Access
150             const string& title() const
151             {
152                 return title_;
153             }
155             const string& xName() const
156             {
157                 return xName_;
158             }
160             const string& yName() const
161             {
162                 return yName_;
163             }
166             const scalarField& x() const
167             {
168                 return x_;
169             }
171             scalarField& x()
172             {
173                 return x_;
174             }
177             const scalarField& y() const;
179             scalarField& y();
182         // Write
184             //- Abstract base class for a graph writer
185             class writer
186             {
188             protected:
190                 void writeXY
191                 (
192                     const scalarField& x,
193                     const scalarField& y,
194                     Ostream&
195                 ) const;
197             public:
199                 //- Runtime type information
200                 TypeName("writer");
202                 //- Declare run-time constructor selection table
203                 declareRunTimeSelectionTable
204                 (
205                     autoPtr,
206                     writer,
207                     word,
208                     (),
209                     ()
210                 );
212                 // Selectors
214                     //- Return a reference to the selected writer
215                     static autoPtr<writer> New
216                     (
217                         const word& writeFormat
218                     );
221                 // Constructors
223                     //- Construct null
224                     writer()
225                     {}
228                 // Destructor
230                     virtual ~writer()
231                     {}
234                 // Member Functions
236                     // Access
238                         //- Return the appropriate fileName extension
239                         //  for this graph format
240                         virtual const word& ext() const = 0;
243                     // Write
245                         //- Write graph in appropriate format
246                         virtual void write(const graph&, Ostream&) const = 0;
247             };
249             //- Write out graph data as a simple table
250             void writeTable(Ostream&) const;
252             //- Write graph to stream in given format
253             void write(Ostream&, const word& format) const;
255             //- Write graph to file in given format
256             void write(const fileName& fName, const word& format) const;
259     // Friend operators
261         //- Ostream Operator
262         friend Ostream& operator<<(Ostream&, const graph&);
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 } // End namespace Foam
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 #endif
274 // ************************************************************************* //