TBTK
TBTKMacros.h
Go to the documentation of this file.
1 /* Copyright 2016 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
23 #ifndef COM_DAFER45_TBTK_MACRO
24 #define COM_DAFER45_TBTK_MACRO
25 
26 #include "Streams.h"
27 
28 #include <cstring>
29 #include <sstream>
30 
31 #define TBTKAssert(expression, function, message, hint) \
32  if(!(expression)){ \
33  TBTK::Util::Streams::err << "Error in " << function << "\n"; \
34  TBTK::Util::Streams::err << "\t" << message << "\n"; \
35  std::stringstream hintStream; \
36  hintStream << hint; \
37  if(std::strcmp(hintStream.str().c_str(), "") != 0) \
38  TBTK::Util::Streams::err << "\tHint: " << hint << "\n"; \
39  TBTK::Util::Streams::err << "\tWhere: " << __FILE__ << ", " << __LINE__ << "\n"; \
40  if(Util::Streams::logIsOpen()) \
41  Util::Streams::closeLog(); \
42  exit(1); \
43  }
44 
45 #define TBTKExit(function, message, hint) \
46  TBTK::Util::Streams::err << "Error in " << function << "\n"; \
47  TBTK::Util::Streams::err << "\t" << message << "\n"; \
48  std::stringstream hintStream; \
49  hintStream << hint; \
50  if(std::strcmp(hintStream.str().c_str(), "") != 0) \
51  TBTK::Util::Streams::err << "\tHint: " << hint << "\n"; \
52  TBTK::Util::Streams::err << "\tWhere: " << __FILE__ << ", " << __LINE__ << "\n"; \
53  if(Util::Streams::logIsOpen()) \
54  Util::Streams::closeLog(); \
55  exit(1);
56 
57 #define TBTKNotYetImplemented(function) \
58  TBTK::Util::Streams::err << "Error in " << function << "\n"; \
59  TBTK::Util::Streams::err << "\tNot yet implemented.\n"; \
60  TBTK::Util::Streams::err << "\tWhere: " << __FILE__ << ", " << __LINE__ << "\n"; \
61  if(Util::Streams::logIsOpen()) \
62  Util::Streams::closeLog(); \
63  exit(1);
64 
65 #endif
Streams for TBTK output.