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 protected:
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);
57 
58  template <typename Type>
59  bool checkForObjectType(IOobject& object);
60 
61 public:
62 
63  TypeInfo("repository");
64 
66 
67  // - from a name, local path, and owner
68  repository(const word& name, const fileSystem& localPath, repository* owner = nullptr);
69 
70  // - no copy
71  repository(const repository&) = delete;
72 
73  // - no assignment
74  repository& operator=(const repository& )= delete;
75 
76  // - destructor
77  virtual ~repository();
78 
79 
81 
82  // - name of repository
83  word name()const;
84 
85  // - local path of repository
86  virtual fileSystem localPath()const;
87 
88  // full path of repository
89  virtual fileSystem path()const ;
90 
91  // - const pointer to the owner
92  const repository* owner()const;
93 
94  // - pointer to the owner
95  repository* owner();
96 
97  // - const ref to this repository
98  const repository& thisRepository()const;
99 
100  // - ref to this repository
102 
103  // - add rep to this repository
104  // return false if the name already exists
105  bool addToRepository(repository* rep);
106 
107  // - remove rep from the list of repositories
108  bool removeRepository(repository* rep);
109 
110 
112 
113  // - insert the object into repository if it does not exist
114  // return a refernce to underlying data object, this reference never invalidated
115  // until it is deleted from repository.
116  // issue a fatal error if it is already exists
117  // ** one time construction and no move/copy of object **
118  template<typename T, typename... Args>
119  T& emplaceObject(const objectFile& objf, Args&&... args);
120 
121  // - insert the object into repository if it does not exist
122  // return a refernce to underlying data object, this reference never invalidated
123  // until it is deleted from repository.
124  // - if the object already exist, after type check(if consistent), return the
125  // reference of the existing object and create no new object.
126  // ** one time construction and no move/copy of object **
127  template<typename T, typename... Args>
128  T& emplaceObjectOrGet(const objectFile& objf, Args&&... args);
129 
130  // - insert the object into repository and replace if it already exists (old object is destroyed)
131  // return a refernce to underlying data object, this reference never invalidated
132  // until it is deleted from repository.
133  // ** one time construction and no move/copy of object **
134  template<typename T, typename... Args>
135  T& emplaceReplaceObject(const objectFile& objf, Args&&... args);
136 
137 
138  // - Insert_or_replace the IOobejct into repository and change its ownership
139  // to this repository, take effect only if the object does not belong to
140  // any other repository
141  template<typename T>
143 
144 
145  // - Insert_or_replace the IOobejct into repository with new objectFile and
146  // change the ownership to this repository, take effect only if the object
147  // does not belong to any other repository
148  template<typename T>
149  T& insertReplaceObject(const objectFile& objf, uniquePtr<IOobject>&& ptr );
150 
151  // - rease an object from this repository
152  bool eraseObject(const word& name)
153  {
154  return objects_.erase(name) == 1;
155  }
156 
157 
159 
160  // - check if name of object exists
161  bool lookupObjectName(const word& nm)const;
162 
163  // - find the object and return the typeName of the object
164  word lookupObjectTypeName(const word& nm)const;
165 
166  // - check if name of object exists
167  // search all the repositories under the hood of Control (master repository)
168  bool globalLookupObjectName(const word& nm, bool downward = false)const;
169 
170  // - check if name of the repository exists
171  bool lookupRepositoryName(const word& nm)const;
172 
173  // - check if name (object and repository) exists
174  bool lookupName(const word nm)const;
175 
176  // - return number of objects
177  size_t numObjects()const;
178 
179  // - return number of repositories
180  size_t numRepositories()const;
181 
182  virtual
183  size_t outFilePrecision() const
184  {
185  if(owner_)
186  {
187  return owner_->outFilePrecision();
188  }else
189  {
190  return 6;
191  }
192  }
193 
194  // - return a ref to the underlaying data in the object
195  template<typename T>
196  T& lookupObject(const word& name);
197 
198  // - search the name and return a ref to repository
200 
201  // list of object names in this repository
202  wordList objectNames()const;
203 
204  // list of repository names in this repository
205  wordList repositoryNames()const;
206 
208  virtual bool write(bool verbose = false) const;
209 
210 };
211 
212 }
213 
214 #include "repositoryTemplates.cpp"
215 
216 #endif //__repository_hpp__
repositoryTemplates.cpp
pFlow::List< word >
pFlow::repository::localPath
virtual fileSystem localPath() const
Definition: repository.cpp:56
pFlow::repository::TypeInfo
TypeInfo("repository")
Lists.hpp
pFlow::repository::emplaceReplaceObject
T & emplaceReplaceObject(const objectFile &objf, Args &&... args)
Definition: repositoryTemplates.cpp:89
IOobject.hpp
pFlow::repository::eraseObject
bool eraseObject(const word &name)
Definition: repository.hpp:152
pFlow::repository::checkForObjectType
bool checkForObjectType(IOobject &object)
Definition: repositoryTemplates.cpp:32
pFlow::repository::lookupObject
T & lookupObject(const word &name)
Definition: repositoryTemplates.cpp:146
pFlow::repository::removeRepository
bool removeRepository(repository *rep)
Definition: repository.cpp:109
pFlow::repository::owner_
repository * owner_
Definition: repository.hpp:45
pFlow::repository::reportTypeError
word reportTypeError(IOobject &object)
pFlow::repository::repositories_
wordMap< repository * > repositories_
Definition: repository.hpp:52
pFlow::repository::~repository
virtual ~repository()
Definition: repository.cpp:43
pFlow::repository::owner
const repository * owner() const
Definition: repository.cpp:73
pFlow::repository::lookupObjectName
bool lookupObjectName(const word &nm) const
Definition: repository.cpp:117
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::repository::lookupObjectTypeName
word lookupObjectTypeName(const word &nm) const
Definition: repository.cpp:122
pFlow::repository::emplaceObject
T & emplaceObject(const objectFile &objf, Args &&... args)
Definition: repositoryTemplates.cpp:38
pFlow::repository::outFilePrecision
virtual size_t outFilePrecision() const
Definition: repository.hpp:183
pFlow::repository::numRepositories
size_t numRepositories() const
Definition: repository.cpp:195
fileSystem.hpp
pFlow::repository::write
virtual bool write(bool verbose=false) const
Definition: repository.cpp:239
pFlow
Definition: demComponent.hpp:28
pFlow::IOobject
Definition: IOobject.hpp:35
pFlow::repository::insertReplaceObject
T & insertReplaceObject(uniquePtr< IOobject > &&ptr)
Definition: repositoryTemplates.cpp:104
pFlow::repository::lookupRepositoryName
bool lookupRepositoryName(const word &nm) const
Definition: repository.cpp:178
pFlow::fileSystem
Definition: fileSystem.hpp:63
pFlow::repository::name
word name() const
Definition: repository.cpp:51
pFlow::repository::globalLookupObjectName
bool globalLookupObjectName(const word &nm, bool downward=false) const
Definition: repository.cpp:140
pFlow::repository::objects_
wordMap< IOobject > objects_
Definition: repository.hpp:48
pFlow::repository::repositoryNames
wordList repositoryNames() const
Definition: repository.cpp:227
pFlow::repository::thisRepository
const repository & thisRepository() const
Definition: repository.cpp:83
pFlow::repository::localPath_
fileSystem localPath_
Definition: repository.hpp:42
pFlow::repository::repository
repository(const word &name, const fileSystem &localPath, repository *owner=nullptr)
Definition: repository.cpp:26
pFlow::repository::addToRepository
bool addToRepository(repository *rep)
Definition: repository.cpp:93
pFlow::objectFile
Definition: objectFile.hpp:33
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:61
pFlow::repository::lookupName
bool lookupName(const word nm) const
Definition: repository.cpp:183
pFlow::repository::lookupRepository
repository & lookupRepository(const word &name)
Definition: repository.cpp:200
pFlow::repository::numObjects
size_t numObjects() const
Definition: repository.cpp:190
pFlow::repository::emplaceObjectOrGet
T & emplaceObjectOrGet(const objectFile &objf, Args &&... args)
Definition: repositoryTemplates.cpp:62
Maps.hpp
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::repository::objectNames
wordList objectNames() const
Definition: repository.cpp:217
pFlow::Map
Definition: Map.hpp:36
pFlow::repository
Definition: repository.hpp:34