diff options
author | Ludovic Courtès <[email protected]> | 2014-12-17 23:00:42 +0100 |
---|---|---|
committer | Ludovic Courtès <[email protected]> | 2014-12-19 22:47:37 +0100 |
commit | 36457566f9917dc7c0c348d012816a2ca333ef1b (patch) | |
tree | 6f1d22a195ea2483b9ce539227d65e8e2a9c137d /nix/libutil/types.hh | |
parent | 2c7ee1672029aa43afb509af5b5f7261244fa2d1 (diff) |
Merge branch 'nix' into 'master'.
Diffstat (limited to 'nix/libutil/types.hh')
-rw-r--r-- | nix/libutil/types.hh | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/nix/libutil/types.hh b/nix/libutil/types.hh new file mode 100644 index 0000000000..4b5ce9a78c --- /dev/null +++ b/nix/libutil/types.hh @@ -0,0 +1,86 @@ +#pragma once + +#include "config.h" + +#include <string> +#include <list> +#include <set> + +#include <boost/format.hpp> + + +namespace nix { + + +/* Inherit some names from other namespaces for convenience. */ +using std::string; +using std::list; +using std::set; +using std::vector; +using boost::format; + + +struct FormatOrString +{ + string s; + FormatOrString(const string & s) : s(s) { }; + FormatOrString(const format & f) : s(f.str()) { }; + FormatOrString(const char * s) : s(s) { }; +}; + + +/* BaseError should generally not be caught, as it has Interrupted as + a subclass. Catch Error instead. */ +class BaseError : public std::exception +{ +protected: + string prefix_; // used for location traces etc. + string err; +public: + unsigned int status; // exit status + BaseError(const FormatOrString & fs, unsigned int status = 1); + ~BaseError() throw () { }; + const char * what() const throw () { return err.c_str(); } + const string & msg() const throw () { return err; } + const string & prefix() const throw () { return prefix_; } + BaseError & addPrefix(const FormatOrString & fs); +}; + +#define MakeError(newClass, superClass) \ + class newClass : public superClass \ + { \ + public: \ + newClass(const FormatOrString & fs, unsigned int status = 1) : superClass(fs, status) { }; \ + }; + +MakeError(Error, BaseError) + +class SysError : public Error +{ +public: + int errNo; + SysError(const FormatOrString & fs); +}; + + +typedef list<string> Strings; +typedef set<string> StringSet; + + +/* Paths are just strings. */ +typedef string Path; +typedef list<Path> Paths; +typedef set<Path> PathSet; + + +typedef enum { + lvlError = 0, + lvlInfo, + lvlTalkative, + lvlChatty, + lvlDebug, + lvlVomit +} Verbosity; + + +} |