| 1 | #pragma once
|
| 2 |
|
| 3 | #include "config.h"
|
| 4 |
|
| 5 | #include <string>
|
| 6 | #include <list>
|
| 7 | #include <set>
|
| 8 | #include <vector>
|
| 9 | #include <string_view>
|
| 10 |
|
| 11 |
|
| 12 | |
| 13 | * its (virtual) destructor and what() in c++11 mode, in violation of spec
|
| 14 |
|
| 15 | #ifdef __GNUC__
|
| 16 | #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
|
| 17 | #define EXCEPTION_NEEDS_THROW_SPEC
|
| 18 | #endif
|
| 19 | #endif
|
| 20 |
|
| 21 |
|
| 22 | namespace nix {
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 | using std::string;
|
| 27 | using std::list;
|
| 28 | using std::set;
|
| 29 | using std::vector;
|
| 30 |
|
| 31 |
|
| 32 | |
| 33 | a subclass. Catch Error instead.
|
| 34 | class BaseError : public std::exception
|
| 35 | {
|
| 36 | protected:
|
| 37 | string prefix_; |
| 38 | string err;
|
| 39 | public:
|
| 40 | unsigned int status; |
| 41 | BaseError(std::string_view fs, unsigned int status = 1);
|
| 42 | #ifdef EXCEPTION_NEEDS_THROW_SPEC
|
| 43 | ~BaseError() throw () { };
|
| 44 | const char * what() const throw () { return err.c_str(); }
|
| 45 | #else
|
| 46 | const char * what() const noexcept { return err.c_str(); }
|
| 47 | #endif
|
| 48 | const string & msg() const { return err; }
|
| 49 | const string & prefix() const { return prefix_; }
|
| 50 | BaseError & addPrefix(std::string fs);
|
| 51 | };
|
| 52 |
|
| 53 | #define MakeError(newClass, superClass) \
|
| 54 | class newClass : public superClass \
|
| 55 | { \
|
| 56 | public: \
|
| 57 | newClass(std::string_view fs, unsigned int status = 1) : superClass(fs, status) { }; \
|
| 58 | };
|
| 59 |
|
| 60 | MakeError(Error, BaseError)
|
| 61 |
|
| 62 | class SysError : public Error
|
| 63 | {
|
| 64 | public:
|
| 65 | int errNo;
|
| 66 | SysError(std::string_view fs);
|
| 67 | };
|
| 68 |
|
| 69 |
|
| 70 | using Strings = std::list<std::string>;
|
| 71 | using StringSet = std::set<std::string>;
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 | using Path = std::string;
|
| 76 | using Paths = std::list<Path>;
|
| 77 | using PathSet = std::set<Path>;
|
| 78 |
|
| 79 |
|
| 80 | enum Verbosity {
|
| 81 | lvlError = 0,
|
| 82 | lvlInfo,
|
| 83 | lvlTalkative,
|
| 84 | lvlChatty,
|
| 85 | lvlDebug,
|
| 86 | lvlVomit
|
| 87 | };
|
| 88 |
|
| 89 |
|
| 90 | }
|