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 
42 :
44 {}
45 
46 
48 (
49  const IOobject& io,
50  const PtrList<coordinateSystem>& lst
51 )
52 :
54 {}
55 
56 
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 // ************************************************************************* //
Foam::coordinateSystems::find
label find(const keyType &key) const
Find and return index for the first match, returns -1 if not found.
Definition: coordinateSystems.C:101
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::coordinateSystems::findIndex
label findIndex(const keyType &key) const
Find and return index for the first match, return -1 if not found.
Definition: coordinateSystems.C:132
Foam::coordinateSystems::coordinateSystems
coordinateSystems(const coordinateSystems &)
Disallow default bitwise copy construct.
Foam::IOPtrList
A PtrList of objects of type <T> with automated input and output.
Definition: IOPtrList.H:50
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::findIndex
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
Foam::keyType::isPattern
bool isPattern() const
Should be treated as a match rather than a literal string.
Definition: keyTypeI.H:76
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:117
Foam::coordinateSystems::toc
wordList toc() const
Return the table of contents (list of all keywords)
Definition: coordinateSystems.C:164
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:56
Foam::label
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
IOPtrList.H
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::PtrList< coordinateSystem >
Foam::coordinateSystems
Provides a centralized coordinateSystem collection.
Definition: coordinateSystems.H:71
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::findStrings
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
Foam::objectRegistry::foundObject
bool foundObject(const word &name) const
Is the named Type found?
Definition: objectRegistryTemplates.C:142
Foam::regIOobject::store
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:34
Foam::token::BEGIN_LIST
@ BEGIN_LIST
Definition: token.H:100
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePaths.H:130
Foam::coordinateSystems::writeData
bool writeData(Ostream &) const
Write data.
Definition: coordinateSystems.C:177
stringListOps.H
Operations on lists of strings.
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Definition: objectRegistryTemplates.C:165
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
Foam::coordinateSystems::New
static const coordinateSystems & New(const objectRegistry &)
Return previously registered or read construct from "constant".
Definition: coordinateSystems.C:71
Foam::defineTemplateTypeNameAndDebug
defineTemplateTypeNameAndDebug(IOPtrList< ensightPart >, 0)
Foam::IOobject::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: IOobject.H:110
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::findIndices
labelList findIndices(const ListType &, typename ListType::const_reference, const label start=0)
Find all occurences of given element. Linear search.
coordinateSystems.H
Foam::coordinateSystems::found
bool found(const keyType &key) const
Search for given key.
Definition: coordinateSystems.C:158
Foam::coordinateSystems::findIndices
labelList findIndices(const keyType &key) const
Find and return indices for all matches.
Definition: coordinateSystems.C:107
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::token::END_LIST
@ END_LIST
Definition: token.H:101
Foam::coordinateSystem
Base class for other coordinate system specifications.
Definition: coordinateSystem.H:85