Timers.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 #ifndef __Timerss_hpp__
22 #define __Timerss_hpp__
23 
24 
25 
26 #include "List.hpp"
27 #include "Timer.hpp"
28 
29 
30 namespace pFlow
31 {
32 
33 class Timers
34 :
35  public pFlow::Timer
36 {
37 protected:
38 
40 
42 
43 public:
44 
45  TypeInfo("Timers");
46 
47 
48  Timers(const word& name)
49  :
50  Timer(name)
51  {}
52 
53  Timers(const word& name, Timers* parrent)
54  :
55  Timer(name, parrent)
56  {
57  if(parrent_)
58  {
59  level_ = parrent_->level()+1;
60  }
61  }
62 
63  virtual ~Timers()
64  {
65  for(auto& timer:timers_)
66  {
67  timer->removeParrent();
68  }
69  }
70 
71  // add a timer to this node
73  {
74  return makeUnique<Timer>(name, this);
75  }
76 
77 
79  {
80  timers_.push_back(timer);
81  }
82 
84  {
85  timers_.erase(timers_.find(timer));
86  }
87 
88  virtual int32 level()const
89  {
90  return level_;
91  }
92 
93  virtual bool master()const
94  {
95  return true;
96  }
97 
98  real accTimersTotal()const override;
99 
100  virtual bool write(iOstream& os, bool subTree = true)const;
101 
102 
103  virtual bool read(iIstream& is)
104  {
105  return true;
106  }
107 
108 };
109 
110 inline iOstream& operator<<(iOstream& os, const Timers& t)
111 {
112  t.write(os, true);
113  return os;
114 }
115 
117 {
118  return is;
119 }
120 
121 }
122 
123 
124 #endif //__Timers_hpp__
pFlow::List< pFlow::Timer * >
pFlow::Timers::~Timers
virtual ~Timers()
Definition: Timers.hpp:63
pFlow::Timers::addToList
void addToList(Timer *timer)
Definition: Timers.hpp:78
pFlow::Timers::Timers
Timers(const word &name)
Definition: Timers.hpp:48
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::Timers::read
virtual bool read(iIstream &is)
Definition: Timers.hpp:103
pFlow::Timers::master
virtual bool master() const
Definition: Timers.hpp:93
List.hpp
pFlow::List::find
constIterator find(const T &val) const
Definition: ListI.hpp:92
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::Timers::TypeInfo
TypeInfo("Timers")
pFlow::Timers
Definition: Timers.hpp:33
pFlow
Definition: demComponent.hpp:28
pFlow::Timer::parrent_
Timers * parrent_
Definition: Timer.hpp:60
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::Timers::level
virtual int32 level() const
Definition: Timers.hpp:88
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::Timer
Definition: Timer.hpp:39
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::Timers::Timers
Timers(const word &name, Timers *parrent)
Definition: Timers.hpp:53
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::Timer::name
const word & name() const
Definition: Timer.hpp:77
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::Timers::accTimersTotal
real accTimersTotal() const override
Definition: Timers.cpp:24
Timer.hpp
pFlow::Timers::level_
int32 level_
Definition: Timers.hpp:41
pFlow::Timers::removeFromList
void removeFromList(Timer *timer)
Definition: Timers.hpp:83
pFlow::Timer::timer
std::chrono::high_resolution_clock timer
Definition: Timer.hpp:43
pFlow::Timers::write
virtual bool write(iOstream &os, bool subTree=true) const
Definition: Timers.cpp:46
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::Timers::timers_
List< pFlow::Timer * > timers_
Definition: Timers.hpp:39
pFlow::Timers::addTimer
uniquePtr< Timer > addTimer(const word &name)
Definition: Timers.hpp:72