www.cemf.ir
repository.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 
22 #ifndef __repository_hpp__
23 #define __repository_hpp__
24 
25 
26 #include "fileSystem.hpp"
27 #include "Maps.hpp"
28 #include "Lists.hpp"
29 #include "IOobject.hpp"
30 
31 namespace pFlow
32 {
33 
35 {
36 private:
37 
38  // - repository name
40 
41  // - local path of repository, relative to owner
43 
44  // - owner of this repository, if any
46 
47  // - sorted names of objects with object index in vector of objects
49 
50  // - list of repositories that this repository owns
51  // - it is not a managed list of pointers!
53 
54 
55  template <typename Type1>
56  word reportTypeError (IOobject& object)const;
57 
58  template <typename Type>
59  static
60  bool checkForObjectType(IOobject& object);
61 
62 public:
63 
64  TypeInfo("repository");
65 
67 
68  // - from a name, local path, and owner
69  repository(const word& name, const fileSystem& localPath, repository* owner = nullptr);
70 
71  // - no copy
72  repository(const repository&) = delete;
73 
74  // - no assignment
75  repository& operator=(const repository& )= delete;
76 
77  // - destructor
78  virtual ~repository();
79 
80 
82 
83  // - name of repository
84  word name()const;
85 
86  // - local path of repository
87  virtual fileSystem localPath()const;
88 
89  // full path of repository
90  virtual fileSystem path()const ;
91 
92  // - const pointer to the owner
93  const repository* owner()const;
94 
95  // - pointer to the owner
96  repository* owner();
97 
98  // - const ref to this repository
99  const repository& thisRepository()const;
100 
101  // - ref to this repository
103 
106  bool addToRepository(repository* rep);
107 
109  bool removeFromRepository(repository* rep);
110 
112  bool addToRepository(IOobject* io);
113 
115  bool removeFromRepository(IOobject* io);
116 
117  repository* releaseOwner(bool fromOwner = false);
118 
119  virtual
120  bool isIncluded(const word& objName)const
121  {
122  if(owner_)
123  return owner_->isIncluded(objName);
124  return false;
125  }
126 
127  virtual
128  bool isExcluded(const word& objName)const
129  {
130  if(owner_)
131  return owner_->isExcluded(objName);
132  return false;
133  }
134 
136 
137  // - check if name of object exists
138  bool lookupObjectName(const word& nm)const;
139 
140  // - find the object and return the typeName of the object
141  word lookupObjectTypeName(const word& nm)const;
142 
143  // - check if name of object exists
144  // search all the repositories under the hood of Control (master repository)
145  bool globalLookupObjectName(const word& nm, bool downward = false)const;
146 
147  // - check if name of the repository exists
148  bool lookupRepositoryName(const word& nm)const;
149 
150  // - check if name (object and repository) exists
151  bool lookupName(const word nm)const;
152 
153  // - return number of objects
154  size_t numObjects()const;
155 
156  // - return number of repositories
157  size_t numRepositories()const;
158 
159  virtual
160  size_t outFilePrecision() const
161  {
162  if(owner_)
163  {
164  return owner_->outFilePrecision();
165  }else
166  {
167  return 6;
168  }
169  }
170 
172  template<typename T>
173  T& lookupObject(const word& name);
174 
176  template<typename T>
177  const T& lookupObject(const word& name)const;
178 
179  // - search the name and return a ref to repository
181 
182  // list of object names in this repository
183  wordList objectNames()const;
184 
185  // list of repository names in this repository
186  wordList repositoryNames()const;
187 
188 
190  virtual bool outFileBinary()const
191  {
192  if(owner_)
193  return owner_->outFileBinary();
194  else
195  return false;
196  }
197  virtual bool write(bool verbose = false) const;
198 
199 };
200 
201 }
202 
203 #include "repositoryTemplates.cpp"
204 
205 #endif //__repository_hpp__
pFlow::repository::releaseOwner
repository * releaseOwner(bool fromOwner=false)
Definition: repository.cpp:131
repositoryTemplates.cpp
pFlow::List< word >
pFlow::repository::localPath
virtual fileSystem localPath() const
Definition: repository.cpp:65
pFlow::repository::TypeInfo
TypeInfo("repository")
pFlow::repository::isExcluded
virtual bool isExcluded(const word &objName) const
Definition: repository.hpp:128
Lists.hpp
IOobject.hpp
pFlow::repository::checkForObjectType
static bool checkForObjectType(IOobject &object)
Definition: repositoryTemplates.cpp:34
pFlow::repository::reportTypeError
word reportTypeError(IOobject &object) const
pFlow::repository::lookupObject
T & lookupObject(const word &name)
return a ref to the underlaying data in the object
Definition: repositoryTemplates.cpp:40
pFlow::repository::owner_
repository * owner_
Definition: repository.hpp:45
pFlow::repository::outFileBinary
virtual bool outFileBinary() const
Definition: repository.hpp:190
pFlow::repository::repositories_
wordMap< repository * > repositories_
Definition: repository.hpp:52
pFlow::repository::~repository
virtual ~repository()
Definition: repository.cpp:42
pFlow::repository::isIncluded
virtual bool isIncluded(const word &objName) const
Definition: repository.hpp:120
pFlow::repository::owner
const repository * owner() const
Definition: repository.cpp:82
pFlow::repository::lookupObjectName
bool lookupObjectName(const word &nm) const
Definition: repository.cpp:157
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::repository::lookupObjectTypeName
word lookupObjectTypeName(const word &nm) const
Definition: repository.cpp:163
pFlow::repository::outFilePrecision
virtual size_t outFilePrecision() const
Definition: repository.hpp:160
pFlow::repository::numRepositories
size_t numRepositories() const
Definition: repository.cpp:234
fileSystem.hpp
pFlow::repository::write
virtual bool write(bool verbose=false) const
Definition: repository.cpp:278
pFlow
Definition: demGeometry.hpp:27
pFlow::IOobject
Definition: IOobject.hpp:35
pFlow::repository::lookupRepositoryName
bool lookupRepositoryName(const word &nm) const
Definition: repository.cpp:217
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
pFlow::repository::name
word name() const
Definition: repository.cpp:60
pFlow::repository::globalLookupObjectName
bool globalLookupObjectName(const word &nm, bool downward=false) const
Definition: repository.cpp:181
pFlow::repository::repositoryNames
wordList repositoryNames() const
Definition: repository.cpp:266
pFlow::repository::thisRepository
const repository & thisRepository() const
Definition: repository.cpp:92
pFlow::repository::localPath_
fileSystem localPath_
Definition: repository.hpp:42
pFlow::repository::objects_
wordMap< IOobject * > objects_
Definition: repository.hpp:48
pFlow::repository::repository
repository(const word &name, const fileSystem &localPath, repository *owner=nullptr)
Definition: repository.cpp:25
pFlow::repository::addToRepository
bool addToRepository(repository *rep)
add repository to this repository return false if the name already exists
Definition: repository.cpp:102
pFlow::repository::name_
word name_
Definition: repository.hpp:39
pFlow::repository::operator=
repository & operator=(const repository &)=delete
pFlow::repository::path
virtual fileSystem path() const
Definition: repository.cpp:70
pFlow::repository::removeFromRepository
bool removeFromRepository(repository *rep)
remove rep from the list of repositories
Definition: repository.cpp:118
pFlow::repository::lookupName
bool lookupName(const word nm) const
Definition: repository.cpp:222
pFlow::repository::lookupRepository
repository & lookupRepository(const word &name)
Definition: repository.cpp:239
pFlow::repository::numObjects
size_t numObjects() const
Definition: repository.cpp:229
Maps.hpp
pFlow::repository::objectNames
wordList objectNames() const
Definition: repository.cpp:256
pFlow::Map
Definition: Map.hpp:36
pFlow::repository
Definition: repository.hpp:34