initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / graph / graph.H
blobcc7d96e90078e2df708f4898b1c63999548dae7f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::graph
28 Description
29     Class to create, store and output qgraph files.
31 SourceFiles
32     graph.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef graph_H
37 #define graph_H
39 #include "string.H"
40 #include "point.H"
41 #include "HashPtrTable.H"
42 #include "curve.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 // Forward declaration of friend functions and operators
51 class graph;
53 Ostream& operator<<(Ostream&, const graph&);
56 /*---------------------------------------------------------------------------*\
57                            Class graph Declaration
58 \*---------------------------------------------------------------------------*/
60 class graph
62     public HashPtrTable<curve>
64     // private data
66         string title_;
67         string xName_;
68         string yName_;
70         scalarField x_;
73         struct xy
74         {
75             scalar x_, y_;
77             xy()
78             {}
80         // Friend Operators
82             friend bool operator==(const xy& a, const xy& b)
83             {
84                 return equal(a.x_, b.x_) && equal(a.y_, b.y_);
85             }
87             friend bool operator!=(const xy& a, const xy& b)
88             {
89                 return !(a == b);
90             }
92             friend Istream& operator>>(Istream& is, xy& xyd)
93             {
94                 is >> xyd.x_ >> xyd.y_;
95                 return is;
96             }
98             friend Ostream& operator<<(Ostream& os, const xy& xyd)
99             {
100                 os << xyd.x_ << ' ' << xyd.y_;
101                 return os;
102             }
103         };
106     // private member functions
108         void readCurves(Istream&);
111 public:
113     // Constructors
115         //- Construct from title and labels (no curves)
116         graph
117         (
118             const string& title,
119             const string& xName,
120             const string& yName,
121             const scalarField& x
122         );
124         //- Construct from title, labels and y data for 1 curve
125         graph
126         (
127             const string& title,
128             const string& xName,
129             const string& yName,
130             const scalarField& x,
131             const scalarField& y
132         );
134         //- Construct from Istream given title and labels
135         graph
136         (
137             const string& title,
138             const string& xName,
139             const string& yName,
140             Istream& is
141         );
143         //- Construct from Istream
144         graph(Istream& is);
147     // Member functions
149         // Access
151             const string& title() const
152             {
153                 return title_;
154             }
156             const string& xName() const
157             {
158                 return xName_;
159             }
161             const string& yName() const
162             {
163                 return yName_;
164             }
167             const scalarField& x() const
168             {
169                 return x_;
170             }
172             scalarField& x()
173             {
174                 return x_;
175             }
178             const scalarField& y() const;
180             scalarField& y();
183         // Write
185             //- Abstract base class for a graph writer
186             class writer
187             {
189             protected:
191                 void writeXY
192                 (
193                     const scalarField& x,
194                     const scalarField& y,
195                     Ostream&
196                 ) const;
198             public:
200                 //- Runtime type information
201                 TypeName("writer");
203                 //- Declare run-time constructor selection table
204                 declareRunTimeSelectionTable
205                 (
206                     autoPtr,
207                     writer,
208                     word,
209                     (),
210                     ()
211                 );
212                 
214                 // Selectors
215                 
216                     //- Return a reference to the selected writer
217                     static autoPtr<writer> New
218                     (
219                         const word& writeFormat
220                     );
221                 
223                 // Constructors
225                     //- Construct null
226                     writer()
227                     {}
230                 // Destructor
232                     virtual ~writer()
233                     {}
236                 // Member Functions
238                     // Access
240                         //- Return the appropriate fileName extension
241                         //  for this graph format
242                         virtual const word& ext() const = 0;
245                     // Write
247                         //- Write graph in appropriate format
248                         virtual void write(const graph&, Ostream&) const = 0;
249             };
251             //- Write out graph data as a simple table
252             void writeTable(Ostream&) const;
254             //- Write graph to stream in given format
255             void write(Ostream&, const word& format) const;
257             //- Write graph to file in given format
258             void write(const fileName& fName, const word& format) const;
261     // Friend operators
263         //- Ostream Operator
264         friend Ostream& operator<<(Ostream&, const graph&);
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 } // End namespace Foam
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 #endif
276 // ************************************************************************* //