diff --git a/except.cpp b/except.cpp index 0943c03e..d932d089 100644 --- a/except.cpp +++ b/except.cpp @@ -26,12 +26,18 @@ using namespace std; +/// Construct an errno_error from a given error value. The error value MUST signal an error at +/// construction time. errno_error::errno_error (int _errno): runtime_error (strerror (_errno)), id (_errno) -{ ; } +{ + check_hard (_errno != 0); +} +/// Construct an errno_error from the current value of errno. errno MUST signal an error at +/// construction time. errno_error::errno_error (): runtime_error (strerror (errno)), id (errno) @@ -40,11 +46,13 @@ errno_error::errno_error (): } +/// Throw an errno_error exception if errno currently signals an error. void errno_error::try_code () { try_code (errno); } +/// Throw an errno_error exception if 'code' represents an error. void errno_error::try_code(int code) { if (code != 0) diff --git a/except.hpp b/except.hpp index 71c5dc68..e8a222f3 100644 --- a/except.hpp +++ b/except.hpp @@ -40,6 +40,7 @@ class unavailable_error : public std::runtime_error { }; +/// An exception class used for reporting errors signalled by errno. class errno_error : public std::runtime_error { public: int id; diff --git a/json.hpp b/json.hpp index bd265f72..7fcdd64f 100644 --- a/json.hpp +++ b/json.hpp @@ -41,6 +41,7 @@ namespace json { extern node* parse (const char *start, const char *stop); extern node* parse (const char *start); + /// Abstract base for all JSON values class node { public: virtual ~node () { ; } @@ -72,6 +73,7 @@ namespace json { }; + /// Represents a JSON object, and contains its children. class object : public node { protected: std::map m_values; @@ -94,6 +96,7 @@ namespace json { }; + /// Represents a JSON array, and contains its children. class array : public node { protected: std::vector m_values; @@ -126,6 +129,7 @@ namespace json { }; + /// Represents a JSON string literal. class string : public node { protected: std::string m_value; @@ -146,6 +150,7 @@ namespace json { }; + /// Represents a JSON integer/float literal. class number : public node { protected: double m_value; @@ -166,6 +171,7 @@ namespace json { }; + /// Represents a JSON boolean literal. class boolean : public node { protected: bool m_value; @@ -183,6 +189,7 @@ namespace json { }; + /// Represents a JSON null value. class null : public node { public: virtual bool is_null (void) const { return true; } @@ -193,6 +200,7 @@ namespace json { }; + /// The base class for all exceptions throw directly by the json namespace. class error : public std::runtime_error { public: error (const std::string &_what): diff --git a/types.hpp b/types.hpp index e9c5691a..3077fcf5 100644 --- a/types.hpp +++ b/types.hpp @@ -98,10 +98,12 @@ size_t elems(T (&)[N]) { return N; } +/// Convert a scalar from host byte order to network byte order template T hton (T); +/// Convert a scalar from network byte order to host byte order template T ntoh (T);