coordinateSystems.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 | Copyright (C) 2011-2015 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
25 
26 #include "coordinateSystems.H"
27 #include "IOPtrList.H"
28 #include "Time.H"
29 #include "stringListOps.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(coordinateSystems, 0);
36  defineTemplateTypeNameAndDebug(IOPtrList<coordinateSystem>, 0);
37 }
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
41 Foam::coordinateSystems::coordinateSystems(const IOobject& io)
42 :
44 {}
45 
46 
47 Foam::coordinateSystems::coordinateSystems
48 (
49  const IOobject& io,
50  const PtrList<coordinateSystem>& lst
51 )
52 :
54 {}
55 
56 
57 Foam::coordinateSystems::coordinateSystems
58 (
59  const IOobject& io,
60  const Xfer<PtrList<coordinateSystem> >& lst
61 )
62 :
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
68 
69 // Read construct from registry, or return previously registered
71 (
72  const objectRegistry& obr
73 )
74 {
75  if (obr.foundObject<coordinateSystems>(typeName))
76  {
77  return obr.lookupObject<coordinateSystems>(typeName);
78  }
79  else
80  {
81  return obr.store
82  (
84  (
85  IOobject
86  (
87  typeName,
88  obr.time().constant(),
89  obr,
92  )
93  )
94  );
95  }
96 }
97 
98 
99 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 
102 {
103  return findIndex(key);
104 }
105 
106 
108 {
109  labelList indices;
110  if (key.isPattern())
111  {
112  indices = findStrings(key, toc());
113  }
114  else
115  {
116  indices.setSize(size());
117  label nFound = 0;
118  forAll(*this, i)
119  {
120  if (key == operator[](i).name())
121  {
122  indices[nFound++] = i;
123  }
124  }
125  indices.setSize(nFound);
126  }
127 
128  return indices;
129 }
130 
131 
133 {
134  if (key.isPattern())
135  {
136  labelList indices = findIndices(key);
137  // return first element
138  if (!indices.empty())
139  {
140  return indices[0];
141  }
142  }
143  else
144  {
145  forAll(*this, i)
146  {
147  if (key == operator[](i).name())
148  {
149  return i;
150  }
151  }
152  }
153 
154  return -1;
155 }
156 
157 
159 {
160  return findIndex(key) != -1;
161 }
162 
163 
165 {
166  wordList keywords(size());
167 
168  forAll(*this, i)
169  {
170  keywords[i] = operator[](i).name();
171  }
172 
173  return keywords;
174 }
175 
176 
178 {
179  os << nl << size() << nl << token::BEGIN_LIST;
180 
181  forAll(*this, i)
182  {
183  os << nl;
184  operator[](i).writeDict(os, true);
185  }
186 
187  os << token::END_LIST << nl;
188 
189  return os.good();
190 }
191 
192 
193 // ************************************************************************* //
label size() const
Return the number of elements in the PtrList.
Base class for other coordinate system specifications.
bool empty() const
Return true if the UList is empty (ie, size() is zero).
Definition: UListI.H:313
bool foundObject(const word &name) const
Is the named Type found?
bool found(const keyType &key) const
Search for given key.
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
bool isPattern() const
Should be treated as a match rather than a literal string.
Definition: keyTypeI.H:76
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
A PtrList of objects of type <T> with automated input and output.
Definition: IOPtrList.H:50
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
Namespace for OpenFOAM.
A class for handling keywords in dictionaries.
Definition: keyType.H:56
bool writeData(Ostream &) const
Write data.
static const char nl
Definition: Ostream.H:260
void setSize(const label)
Reset size of List.
Definition: List.C:318
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
label find(const keyType &key) const
Find and return index for the first match, returns -1 if not found.
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:34
#define forAll(list, i)
Definition: UList.H:421
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
label findIndex(const keyType &key) const
Find and return index for the first match, return -1 if not found.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
labelList findIndices(const keyType &key) const
Find and return indices for all matches.
const word & name() const
Return name.
Definition: IOobject.H:260
const word & name() const
Return name.
defineTemplateTypeNameAndDebug(IOPtrList< ensightPart >, 0)
Registry of regIOobjects.
Operations on lists of strings.
static const coordinateSystems & New(const objectRegistry &)
Return previously registered or read construct from "constant".
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const Time & time() const
Return time.
wordList toc() const
Return the table of contents (list of all keywords)
Provides a centralized coordinateSystem collection.
defineTypeNameAndDebug(combustionModel, 0)
const coordinateSystem & operator[](const label) const
Return element const reference.