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-2016 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,
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  labelList indices;
104  if (key.isPattern())
105  {
106  indices = findStrings(key, toc());
107  }
108  else
109  {
110  indices.setSize(size());
111  label nFound = 0;
112  forAll(*this, i)
113  {
114  if (key == operator[](i).name())
115  {
116  indices[nFound++] = i;
117  }
118  }
119  indices.setSize(nFound);
120  }
121 
122  return indices;
123 }
124 
125 
127 {
128  if (key.isPattern())
129  {
130  labelList indices = findIndices(key);
131  // return first element
132  if (!indices.empty())
133  {
134  return indices[0];
135  }
136  }
137  else
138  {
139  forAll(*this, i)
140  {
141  if (key == operator[](i).name())
142  {
143  return i;
144  }
145  }
146  }
147 
148  return -1;
149 }
150 
151 
153 {
154  return findIndex(key) != -1;
155 }
156 
157 
159 {
160  wordList keywords(size());
161 
162  forAll(*this, i)
163  {
164  keywords[i] = operator[](i).name();
165  }
166 
167  return keywords;
168 }
169 
170 
172 {
173  os << nl << size() << nl << token::BEGIN_LIST;
174 
175  forAll(*this, i)
176  {
177  os << nl;
178  operator[](i).writeDict(os, true);
179  }
180 
181  os << token::END_LIST << nl;
182 
183  return os.good();
184 }
185 
186 
187 // ************************************************************************* //
Base class for other coordinate system specifications.
const Time & time() const
Return time.
A class for handling keywords in dictionaries.
Definition: keyType.H:64
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
wordList toc() const
Return the table of contents (list of all keywords)
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 foundObject(const word &name) const
Is the named Type found?
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:313
Provides a centralized coordinateSystem collection.
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
Operations on lists of strings.
bool found(const keyType &key) const
Search for given key.
bool writeData(Ostream &) const
Write data.
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
defineTemplateTypeNameAndDebug(IOPtrList< ensightPart >, 0)
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:34
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
defineTypeNameAndDebug(combustionModel, 0)
static const coordinateSystems & New(const objectRegistry &)
Return previously registered or read construct from "constant".
const T & operator[](const label) const
Return element const reference.
Definition: UPtrListI.H:103
void setSize(const label)
Reset size of List.
Definition: List.C:295
A PtrList of objects of type <T> with automated input and output.
Definition: IOPtrList.H:50
label findIndex(const keyType &key) const
Find and return index for the first match, return -1 if not found.
labelList findIndices(const keyType &key) const
Find and return indices for all matches.
Registry of regIOobjects.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
const word & name() const
Return name.
Definition: IOobject.H:260
bool isPattern() const
Should be treated as a match rather than a literal string.
Definition: keyTypeI.H:76
Namespace for OpenFOAM.
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29