浏览代码

cleaned up namespace in faults

master
Pete McNeil 4 年前
父节点
当前提交
ac969f3fb9
共有 1 个文件被更改,包括 27 次插入30 次删除
  1. 27
    30
      faults.hpp

+ 27
- 30
faults.hpp 查看文件

@@ -18,15 +18,14 @@
// A Runtime...() throws a runtime_error (self) with it's description in what().
// A Logic...() throws a logic_error (self) with it's description in what().
#ifndef MNR_faults
#define MNR_faults
#pragma once
#include <stdexcept>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
namespace codedweller {
const int DefaultExitCode = EXIT_FAILURE; // Use this when no code is provided.
@@ -34,62 +33,62 @@ class AbortCheck {
private:
const string myDescription; // This is what I have to say.
const std::string myDescription; // This is what I have to say.
public:
AbortCheck(const string& Text) : myDescription(Text) {} // I am constructed with a description
AbortCheck(const std::string& Text) : myDescription(Text) {} // I am constructed with a description
void operator()(bool X) const { // Apply me like assert(exp)
if(false == X) { // If the expression is false then we
cerr << myDescription << endl; // failed the check so we display our
std::cerr << myDescription << std::endl; // failed the check so we display our
abort(); // description and abort.
}
}
const string Description() { return myDescription; } // You can ask for my Description.
const std::string Description() { return myDescription; } // You can ask for my Description.
};
class AbortFault { // If this fault occurs we will abort.
private:
const string myDescription; // This is what I have to say.
const std::string myDescription; // This is what I have to say.
public:
AbortFault(const string& Text) : myDescription(Text) {} // I am constructed with a description
AbortFault(const std::string& Text) : myDescription(Text) {} // I am constructed with a description
void operator()(bool X) const { // Apply me like assert(! exp)
if(true == X) { // If the expression is true then we
cerr << myDescription << endl; // have a fault so we display our fault
std::cerr << myDescription << std::endl; // have a fault so we display our fault
abort(); // description and abort.
}
}
const string Description() const { return myDescription; } // You can ask for my Description.
const std::string Description() const { return myDescription; } // You can ask for my Description.
};
class ExitCheck { // If this check is false we will exit.
private:
const string myDescription; // This is what I have to say.
const std::string myDescription; // This is what I have to say.
const int myExitCode; // This is what I send to exit().
public:
ExitCheck(const string& Text, int Code=DefaultExitCode) : // I am constructed with a description
ExitCheck(const std::string& Text, int Code=DefaultExitCode) : // I am constructed with a description
myDescription(Text), myExitCode(Code) {} // and (optionlly) an exit code.
void operator()(bool X) const { // Apply me like assert(exp)
if(false == X) { // If the expression is false then we
cerr << myDescription << endl; // failed the check so we display our
std::cerr << myDescription << std::endl; // failed the check so we display our
exit(myExitCode); // description and exit with our code.
}
}
const string Description() { return myDescription; } // You can ask for my Description.
const std::string Description() { return myDescription; } // You can ask for my Description.
const int ExitCode() { return myExitCode; } // You can ask for my ExitCode.
};
@@ -97,30 +96,30 @@ class ExitFault {
private:
const string myDescription; // This is what I have to say.
const std::string myDescription; // This is what I have to say.
const int myExitCode; // This is what I send to exit().
public:
ExitFault(const string& Text, int Code=DefaultExitCode) : // I am constructed with a description
ExitFault(const std::string& Text, int Code=DefaultExitCode) : // I am constructed with a description
myDescription(Text), myExitCode(Code) {} // and (optionlly) an exit code.
void operator()(bool X) const { // Apply me like assert(! exp)
if(true == X) { // If the expression is true then we
cerr << myDescription << endl; // have a fault so we display our fault
std::cerr << myDescription << std::endl; // have a fault so we display our fault
exit(myExitCode); // description and exit with our code.
}
}
const string Description() const { return myDescription; } // You can ask for my Description.
const std::string Description() const { return myDescription; } // You can ask for my Description.
const int ExitCode() const { return myExitCode; } // You can ask for my ExitCode.
};
class RuntimeCheck : public runtime_error { // Throw if this check fails.
class RuntimeCheck : public std::runtime_error { // Throw if this check fails.
public:
RuntimeCheck(const string& Text) : runtime_error(Text) {} // Construct me with a description.
RuntimeCheck(const std::string& Text) : std::runtime_error(Text) {} // Construct me with a description.
void operator()(bool X) const { // Apply me like assert(exp)
if(false == X) { // If the expression is false then we
@@ -129,11 +128,11 @@ class RuntimeCheck : public runtime_error {
}
};
class RuntimeFault : public runtime_error { // Throw if we find this fault.
class RuntimeFault : public std::runtime_error { // Throw if we find this fault.
public:
RuntimeFault(const string& Text) : runtime_error(Text) {} // Construct me with a description.
RuntimeFault(const std::string& Text) : std::runtime_error(Text) {} // Construct me with a description.
void operator()(bool X) const { // Apply me like assert(exp)
if(true == X) { // If the expression is true then we
@@ -142,11 +141,11 @@ class RuntimeFault : public runtime_error {
}
};
class LogicCheck : public logic_error { // Throw if this check fails.
class LogicCheck : public std::logic_error { // Throw if this check fails.
public:
LogicCheck(const string& Text) : logic_error(Text) {} // Construct me with a description.
LogicCheck(const std::string& Text) : std::logic_error(Text) {} // Construct me with a description.
void operator()(bool X) const { // Apply me like assert(exp)
if(false == X) { // If the expression is false then we
@@ -155,11 +154,11 @@ class LogicCheck : public logic_error {
}
};
class LogicFault : public logic_error { // Throw if we find this fault.
class LogicFault : public std::logic_error { // Throw if we find this fault.
public:
LogicFault(const string& Text) : logic_error(Text) {} // Construct me with a description.
LogicFault(const std::string& Text) : std::logic_error(Text) {} // Construct me with a description.
void operator()(bool X) const { // Apply me like assert(exp)
if(true == X) { // If the expression is true then we
@@ -168,6 +167,4 @@ class LogicFault : public logic_error {
}
};
#endif
// End Of Include MNR_faults Once Only =========================================
} // End namespace codedweller

正在加载...
取消
保存