colourTables.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2019 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "colourTable.H"
29#include "etcFiles.H"
30#include "IFstream.H"
31#include "HashSet.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35Foam::HashPtrTable<Foam::colourTable> Foam::colourTable::tables_;
36
37
38
39const Foam::Enum
40<
42>
44({
45 { predefinedType::COOL_WARM, "coolToWarm" },
46 { predefinedType::COLD_HOT, "coldAndHot" },
47 { predefinedType::FIRE, "fire" },
48 { predefinedType::RAINBOW, "rainbow" },
49 { predefinedType::GREYSCALE, "greyscale" },
50 { predefinedType::XRAY, "xray" },
51});
52
53
54// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
55
56void Foam::colourTable::constructTables()
57{
58 if (tables_.size())
59 {
61 << "attempt to re-construct colourTables when they already exist"
62 << exit(FatalError);
63 }
64
65 IFstream is(findEtcFile("colourTables", true)); // Mandatory file
66
67 HashPtrTable<colourTable> newEntries(is);
68 tables_.swap(newEntries);
69
70 Info<< "loaded " << tables_.sortedToc()
71 << " from etc/colourTable" << endl;
72
73 Info<< "== " << tables_ << nl;
74}
75
76
78{
79 if (tables_.empty())
80 {
81 constructTables();
82 }
83
84 return tables_;
85}
86
87
89{
90 if (tables_.empty())
91 {
92 constructTables();
93 }
94
95 const auto iter = tables_.cfind(tableName);
96
97 if (iter.good())
98 {
99 const colourTable* p = iter.val();
100 return p;
101 }
102
103 return nullptr;
104}
105
106
108{
109 return ptr(predefinedNames[tbl]);
110}
111
112
114{
115 const colourTable* p = ptr(tableName);
116
117 if (!p)
118 {
120 << "No such colourTable: " << tableName
121 << exit(FatalError);
122 }
123
124 return *p;
125}
126
127
129{
130 return ref(predefinedNames[tbl]);
131}
132
133
134// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Definition: HashPtrTable.H:68
Base class for generating a colour table from node points.
Definition: colourTable.H:80
static const colourTable * ptr(const word &tableName)
Look up pointer to colourTable by name, or nullptr on failure.
Definition: colourTables.C:88
static const Enum< predefinedType > predefinedNames
Enumeration names for predefinedType.
Definition: colourTable.H:108
predefinedType
Enumeration of commonly used colour tables.
Definition: colourTable.H:94
static const HashPtrTable< colourTable > & tables()
Predefined tables.
Definition: colourTables.C:77
reference ref() const
A reference to the entry (Error if not found)
Definition: dictionary.H:225
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
rDeltaT ref()
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Functions to search 'etc' directories for configuration files etc.
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
Definition: etcFiles.C:446
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53