MEPP2 Project
Block.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 #include <iostream>
14 #include <chrono>
15 #include <ctime>
16 
17 namespace FEVV {
18 
40 class Block
41 {
42 public:
47  Block() = delete;
48 
53  Block(const Block &_Block) = delete;
54 
59  ~Block() = delete;
60 
67  static void begin(const std::string &_uid, const std::string &_message)
68  {
69  Block::InnerData data;
70  data.message = _message;
71  data.startClock = std::chrono::system_clock::now();
72  Block::blocks.insert({_uid, data});
73 
74 #if(defined(UNIX))
75  std::cout << "\033[0m\033[1m\033[32m"; // Bold + green color
76 #endif
77  std::cout << "################";
78  for(unsigned int i = 0; i < _message.length(); ++i)
79  {
80  std::cout << "#";
81  }
82  std::cout << "#" << std::endl;
83  std::cout << "# Begin block: " << _message << " #" << std::endl;
84  std::cout << "################";
85  for(unsigned int i = 0; i < _message.length(); ++i)
86  {
87  std::cout << "#";
88  }
89  std::cout << "#" << std::endl;
90 #if(defined(UNIX))
91  std::cout << "\033[0m"; // reset
92 #endif
93  }
94 
100  static void end(const std::string &_uid)
101  {
102  if(Block::blocks.find(_uid) == Block::blocks.end())
103  {
104  std::cerr << "Can't found a block with this uid: " << _uid << std::endl;
105  return;
106  }
107 
108  Block::InnerData data = Block::blocks.at(_uid);
109  std::chrono::time_point< std::chrono::system_clock > endClock;
110  endClock = std::chrono::system_clock::now();
111  std::chrono::duration< double > elapsed_seconds =
112  endClock - data.startClock;
113 
114 #if(defined(UNIX))
115  std::cout << "\033[0m\033[1m\033[32m"; // Bold + green color
116 #endif
117  std::cout << "################";
118  for(unsigned int i = 0; i < data.message.length(); ++i)
119  {
120  std::cout << "#";
121  }
122  std::cout << "#" << std::endl;
123 
124  std::cout << "# End block: " << data.message << " #" << std::endl;
125  std::cout << "# Elapsed time: " << elapsed_seconds.count() << "s #"
126  << std::endl;
127 
128  std::cout << "################";
129  for(unsigned int i = 0; i < data.message.length(); ++i)
130  {
131  std::cout << "#";
132  }
133  std::cout << "#" << std::endl;
134 #if(defined(UNIX))
135  std::cout << "\033[0m"; // reset
136 #endif
137 
138  Block::blocks.erase(_uid);
139  }
140 
141 protected:
142  struct InnerData
143  {
144  InnerData() = default;
145  ~InnerData() = default;
146  std::string message;
147  std::chrono::time_point< std::chrono::system_clock > startClock;
148  };
149 
150  static std::map< std::string, Block::InnerData > blocks;
151 };
152 
153 } // namespace FEVV
154 
155 std::map< std::string, FEVV::Block::InnerData > FEVV::Block::blocks =
156  std::map< std::string, FEVV::Block::InnerData >();
FEVV::Block::begin
static void begin(const std::string &_uid, const std::string &_message)
Definition: Block.h:67
FEVV::Block::end
static void end(const std::string &_uid)
Definition: Block.h:100
FEVV::Block::InnerData::startClock
std::chrono::time_point< std::chrono::system_clock > startClock
Definition: Block.h:147
FEVV::Block::Block
Block()=delete
FEVV::Block::blocks
static std::map< std::string, Block::InnerData > blocks
Definition: Block.h:150
FEVV::Block::InnerData
Definition: Block.h:143
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Block
This class may be used to draw blocks in your code. It will show the elapsed time between the begin a...
Definition: Block.h:41
FEVV::Block::InnerData::InnerData
InnerData()=default
FEVV::Block::InnerData::message
std::string message
Definition: Block.h:146
FEVV::Block::~Block
~Block()=delete
FEVV::Block::Block
Block(const Block &_Block)=delete
FEVV::Block::InnerData::~InnerData
~InnerData()=default