byteman  1.3 (Build #225)
Bitstream relocation and manipulation tool
CommonDevice.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2022 Kristiyan Manev (University of Manchester)
3  *
4  * Licensed under the Apache License, Version 2.0(the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #ifndef COMMONDEVICE_H
18 #define COMMONDEVICE_H
19 
20 #include<iostream>
21 #include<string>
22 #include<time.h>
23 
25 {
26  public:
28  enableWarn = 1;
29  enableLog = 0;
30  };
31  virtual ~CommonDevice(){
32 
33  };
34  std::string instanceName;
36  int enableLog;
37  inline void printMessage(std::string message){
38  time_t timestamp = time(0);
39  struct tm tstruct;
40  char timeChars[80];
41  tstruct = *localtime(&timestamp);
42  strftime(timeChars, sizeof(timeChars), "%d %b %Y %H:%M:%S @ ", &tstruct);
43  std::cout << timeChars << instanceName << message << std::endl;
44  }
45  inline void warn(std::string message) {
46  #ifdef ENABLEWARN
47  if(enableWarn)
48  CommonDevice::printMessage(std::string(" warning: ").append(message));
49  #endif
50  }
51  inline void log(std::string message) {
52  #ifdef ENABLELOGS
53  if(enableLog)
54  CommonDevice::printMessage(std::string(" info : ").append(message));
55  #endif
56  }
57 };
58 
59 #endif //COMMONDEVICE_H
std::string instanceName
Definition: CommonDevice.h:33
void printMessage(std::string message)
Definition: CommonDevice.h:37
void log(std::string message)
Definition: CommonDevice.h:51
virtual ~CommonDevice()
Definition: CommonDevice.h:31
void warn(std::string message)
Definition: CommonDevice.h:45