www.cemf.ir
repositoryTemplates.cpp
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 template <typename Type1>
24 {
25  word err;
26  err = "Object " + object.name() + " with type " + Type1::TYPENAME() +
27  "is requested, while the type " +
28  object.typeName() + "is found in repository " + this->name()+".";
29 
30  return err;
31 }
32 
33 template <typename Type>
35 {
36  return Type::TYPENAME() == object.typeName();
37 }
38 
39 template<typename T>
41 {
42  if( auto [iter, success] = objects_.findIf(name); success )
43  {
44 
45  if( checkType<T>(iter->second) )
46  {
47  return static_cast<T&>(*iter->second);
48 
49 
50  }else
51  {
53  reportTypeError<T>(*iter->second)<<endl;
54  fatalExit;
55  return static_cast<T&>(*iter->second);
56  }
57 
58  }
59  else
60  {
62  "Object with name " << name << " is not found in repository " << this->name()<<endl <<
63  "list of avaiable objest is \n" << objectNames();
64  fatalExit;
65  return static_cast<T&>(*iter->second);
66  }
67 }
68 
69 template<typename T>
70 const T& pFlow::repository::lookupObject(const word& name)const
71 {
72  if( auto [iter, success] = objects_.findIf(name); success )
73  {
74 
75  if( checkType<T>(iter->second) )
76  {
77  return static_cast<const T&>(*iter->second);
78  }
79  else
80  {
82  reportTypeError<T>(*iter->second)<<endl;
83  fatalExit;
84  return static_cast<T&>(*iter->second);
85  }
86 
87  }
88  else
89  {
91  "Object with name " << name << " is not found in repository " << this->name()<<endl <<
92  "list of avaiable objest is \n" << objectNames();
93  fatalExit;
94  return static_cast<T&>(*iter->second);
95  }
96 }
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
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::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::IOobject
Definition: IOobject.hpp:35
pFlow::repository::name
word name() const
Definition: repository.cpp:60
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77