ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / graph / graph.H
blob2a414980618710a4722f4b1683c4416b044fc5d7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM 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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  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 "string.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                 );
213                 // Selectors
215                     //- Return a reference to the selected writer
216                     static autoPtr<writer> New
217                     (
218                         const word& writeFormat
219                     );
222                 // Constructors
224                     //- Construct null
225                     writer()
226                     {}
229                 //- 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 path-name and format
256             void write(const fileName& pName, const word& format) const;
258             //- Write graph to file in given path, name and format
259             void write
260             (
261                 const fileName& path,
262                 const word& name,
263                 const word& format
264             ) const;
267     // Friend operators
269         //- Ostream Operator
270         friend Ostream& operator<<(Ostream&, const graph&);
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 } // End namespace Foam
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 #endif
282 // ************************************************************************* //