OpenFOAM logo
Open Source CFD Toolkit

colourI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     colour
00027 
00028 Description
00029 
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #include "colour.H"
00034 #include "IOstreams.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040 
00041 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00042 
00043 // Construct null
00044 inline colour::colour()
00045 :
00046     name_(""),
00047     r_(0),
00048     g_(0),
00049     b_(0)
00050 {}
00051 
00052 
00053 // Construct from components
00054 inline colour::colour
00055 (
00056     const word& name,
00057     const scalar r,
00058     const scalar g,
00059     const scalar b
00060 )
00061 :
00062     name_(name),
00063     r_(r),
00064     g_(g),
00065     b_(b)
00066 {}
00067 
00068 
00069 // Construct from Istream
00070 inline colour::colour(Istream& is)
00071 :
00072     name_(is)
00073 {
00074     //- Read beginning of colour
00075     is.readBegin("colour");
00076 
00077     is >> r_ >> g_ >> b_;
00078 
00079     //- Read end of colour
00080     is.readEnd("colour");
00081 
00082     //- Check state of Istream
00083     is.check("colour::colour(Istream& is)");
00084 }
00085 
00086 
00087 // Construct as copy
00088 inline colour::colour(const colour& c)
00089 :
00090     name_(c.name_),
00091     r_(c.r_),
00092     g_(c.g_),
00093     b_(c.b_)
00094 {}
00095 
00096 
00097 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00098 
00099 inline colour::~colour()
00100 {}
00101 
00102 
00103 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00104 
00105 inline const word& colour::name() const
00106 {
00107     return name_;
00108 }
00109 
00110 inline scalar colour::r() const
00111 {
00112     return r_;
00113 }
00114 
00115 inline scalar colour::g() const
00116 {
00117     return g_;
00118 }
00119 
00120 inline scalar colour::b() const
00121 {
00122     return b_;
00123 }
00124 
00125 
00126 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00127 
00128 inline void colour::operator=(const colour& c)
00129 {
00130     name_ = c.name_;
00131     r_ = c.r_;
00132     g_ = c.g_;
00133     b_ = c.b_;
00134 }
00135 
00136 
00137 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00138 
00139 inline bool operator==(const colour& c1, const colour& c2)
00140 {
00141     return
00142     (
00143         c1.name_ == c2.name_
00144      && c1.r_ == c2.r_
00145      && c1.g_ == c2.g_
00146      && c1.b_ == c2.b_
00147     );
00148 }
00149 
00150 
00151 inline bool operator!=(const colour& c1, const colour& c2)
00152 {
00153     return !(c1 == c2);
00154 }
00155 
00156 
00157 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00158 
00159 inline Istream& operator>>(Istream& is, colour& c)
00160 {
00161     is >> c.name_;
00162 
00163     //- Read beginning of colour
00164     is.readBegin("colour");
00165 
00166     is >> c.r_ >> c.g_ >> c.b_;
00167 
00168     //- Read end of colour
00169     is.readEnd("colour");
00170 
00171     //- Check state of Istream
00172     is.check("Istream& operator>>(Istream&, colour&)");
00173 
00174     return is;
00175 }
00176 
00177 
00178 inline Ostream& operator<<(Ostream& os, const colour& c)
00179 {
00180     os  << c.name_
00181         << token::SPACE
00182         << token::BEGIN_LIST
00183         << c.r_
00184         << token::SPACE
00185         << c.g_
00186         << token::SPACE
00187         << c.b_
00188         << token::END_LIST;
00189 
00190     //- Check state of IOstream
00191     os.check("Ostream& operator<<(Ostream&, const colour&)");
00192 
00193     return os;
00194 }
00195 
00196 
00197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00198 
00199 } // End namespace Foam
00200 
00201 // ************************************************************************* //
For further information go to www.openfoam.org