Expand brief documentation for classes

This commit is contained in:
Danny Robson 2011-06-23 22:06:28 +10:00
parent ea0cdb9f7b
commit 898d082fb0
4 changed files with 20 additions and 1 deletions

View File

@ -26,12 +26,18 @@
using namespace std; 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): errno_error::errno_error (int _errno):
runtime_error (strerror (_errno)), runtime_error (strerror (_errno)),
id (_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 (): errno_error::errno_error ():
runtime_error (strerror (errno)), runtime_error (strerror (errno)),
id (errno) id (errno)
@ -40,11 +46,13 @@ errno_error::errno_error ():
} }
/// Throw an errno_error exception if errno currently signals an error.
void void
errno_error::try_code () errno_error::try_code ()
{ try_code (errno); } { try_code (errno); }
/// Throw an errno_error exception if 'code' represents an error.
void void
errno_error::try_code(int code) { errno_error::try_code(int code) {
if (code != 0) if (code != 0)

View File

@ -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 { class errno_error : public std::runtime_error {
public: public:
int id; int id;

View File

@ -41,6 +41,7 @@ namespace json {
extern node* parse (const char *start, const char *stop); extern node* parse (const char *start, const char *stop);
extern node* parse (const char *start); extern node* parse (const char *start);
/// Abstract base for all JSON values
class node { class node {
public: public:
virtual ~node () { ; } virtual ~node () { ; }
@ -72,6 +73,7 @@ namespace json {
}; };
/// Represents a JSON object, and contains its children.
class object : public node { class object : public node {
protected: protected:
std::map<std::string, node*> m_values; std::map<std::string, node*> m_values;
@ -94,6 +96,7 @@ namespace json {
}; };
/// Represents a JSON array, and contains its children.
class array : public node { class array : public node {
protected: protected:
std::vector<node*> m_values; std::vector<node*> m_values;
@ -126,6 +129,7 @@ namespace json {
}; };
/// Represents a JSON string literal.
class string : public node { class string : public node {
protected: protected:
std::string m_value; std::string m_value;
@ -146,6 +150,7 @@ namespace json {
}; };
/// Represents a JSON integer/float literal.
class number : public node { class number : public node {
protected: protected:
double m_value; double m_value;
@ -166,6 +171,7 @@ namespace json {
}; };
/// Represents a JSON boolean literal.
class boolean : public node { class boolean : public node {
protected: protected:
bool m_value; bool m_value;
@ -183,6 +189,7 @@ namespace json {
}; };
/// Represents a JSON null value.
class null : public node { class null : public node {
public: public:
virtual bool is_null (void) const { return true; } 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 { class error : public std::runtime_error {
public: public:
error (const std::string &_what): error (const std::string &_what):

View File

@ -98,10 +98,12 @@ size_t elems(T (&)[N])
{ return N; } { return N; }
/// Convert a scalar from host byte order to network byte order
template <typename T> template <typename T>
T hton (T); T hton (T);
/// Convert a scalar from network byte order to host byte order
template <typename T> template <typename T>
T ntoh (T); T ntoh (T);