FreeFOAM The Cross-Platform CFD Toolkit
instant.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Class
25  Foam::instant
26 
27 Description
28  An instant of time. Contains the time value and name.
29 
30 SourceFiles
31  instant.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef instant_H
36 #define instant_H
37 
38 #include <OpenFOAM/word.H>
39 #include <OpenFOAM/scalar.H>
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 // Forward declaration of friend functions and operators
47 
48 class instant;
49 
50 // Friend Operators
51 
52 bool operator==(const instant&, const instant&);
53 bool operator!=(const instant&, const instant&);
54 
55 // IOstream Operators
56 
57 Istream& operator>>(Istream&, instant&);
58 Ostream& operator<<(Ostream&, const instant&);
59 
60 
61 /*---------------------------------------------------------------------------*\
62  Class instant Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 class instant
66 {
67  // Private data
68 
69  scalar value_;
70  word name_;
71 
72 public:
73 
74  // Public classes
75 
76  //- Less function class used in sorting instants
77  class less
78  {
79  public:
80 
81  bool operator()(const instant& a, const instant& b) const
82  {
83  return a.value() < b.value();
84  }
85  };
86 
87 
88  // Static data members
89 
90  static const char* const typeName;
91 
92 
93  // Constructors
94 
95  //- Construct null
96  instant();
97 
98  //- Construct from components
99  instant(const scalar, const word&);
100 
101  //- Construct from time value
102  instant(const scalar);
103 
104  //- Construct from word
105  instant(const word&);
106 
107 
108  // Member Functions
109 
110  // Access
111 
112  //- Value (const access)
113  scalar value() const
114  {
115  return value_;
116  }
117 
118  //- Value (non-const access)
119  scalar& value()
120  {
121  return value_;
122  }
123 
124  //- Name (const access)
125  const word& name() const
126  {
127  return name_;
128  }
129 
130  //- Name (non-const access)
132  {
133  return name_;
134  }
135 
136 
137  // Friend Operators
138 
139  friend bool operator==(const instant&, const instant&);
140  friend bool operator!=(const instant&, const instant&);
141 
142 
143  // IOstream Operators
144 
145  friend Istream& operator>>(Istream&, instant&);
146  friend Ostream& operator<<(Ostream&, const instant&);
147 };
148 
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 } // End namespace Foam
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 #endif
157 
158 // ************************ vim: set sw=4 sts=4 et: ************************ //