src/types.h

changeset 75
bf8c57437231
parent 74
007fbadfa7f9
child 81
071715c17296
equal deleted inserted replaced
74:007fbadfa7f9 75:bf8c57437231
1 /* 1 /*
2 Copyright (c) 2013-2014, Santeri Piippo 2 Copyright (c) 2012-2014, Santeri Piippo
3 All rights reserved. 3 All rights reserved.
4 4
5 Redistribution and use in source and binary forms, with or without 5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met: 6 modification, are permitted provided that the following conditions are met:
7 7
31 #ifndef BOTC_TYPES_H 31 #ifndef BOTC_TYPES_H
32 #define BOTC_TYPES_H 32 #define BOTC_TYPES_H
33 33
34 #include <cstdlib> 34 #include <cstdlib>
35 #include <stdexcept> 35 #include <stdexcept>
36 #include "str.h"
37 36
38 static const std::nullptr_t null = nullptr; 37 static const std::nullptr_t null = nullptr;
39 38
40 class script_error : public std::exception 39 template<class T> inline T abs (T a)
41 { 40 {
42 public: 41 return (a >= 0) ? a : -a;
43 script_error (const string& msg) : m_msg (msg) {} 42 }
44
45 inline const char* what() const throw()
46 {
47 return m_msg.c_str();
48 }
49
50 private:
51 string m_msg;
52 };
53
54 #ifndef IN_IDE_PARSER
55 # define error(...) throw script_error (format (__VA_ARGS__))
56 #else
57 // kdevelop stuff
58 using FILE = void; // blargh
59 void error (void, ...);
60 #endif
61 43
62 #endif // BOTC_TYPES_H 44 #endif // BOTC_TYPES_H

mercurial