00001
00012 #ifndef ERROR_MESSAGES_H
00013 #define ERROR_MESSAGES_H
00014
00015 #include <string>
00016 #include <vector>
00017 #include <stdarg.h>
00018 #include <stdio.h>
00019
00020 using namespace std;
00021
00025 class single_error {
00026 public:
00028 string code;
00029
00031 string msg;
00032
00034 single_error(string code) {
00035
00036 this->code = code;
00037 this->msg = "";
00038 }
00039
00041 single_error(string code, string msg) {
00042
00043 this->code = code;
00044 this->msg = msg;
00045 }
00046 };
00047
00048
00049
00053 class error_msg {
00054 public:
00056 vector<single_error> errors_stack;
00057
00059 error_msg();
00063 error_msg(char * code) {
00064 errors_stack.push_back(single_error(code));
00065 }
00066
00067
00068
00069
00073
00074 error_msg(const char * code, const char * msg, ...) {
00075
00076
00077
00078 int len;
00079 va_list args;
00080 va_start( args, msg );
00081 char *buffer = new char[1024];
00082
00084 len = vsnprintf(buffer, 1024, msg, args ) + 1;
00085 if (len == 0) throw error_msg("OUTPUT", "Output does not work :-(");
00086
00087 errors_stack.push_back(single_error(code, buffer));
00088
00089 delete buffer;
00090 }
00091
00095 void add(single_error err) {
00096 errors_stack.push_back(err);
00097 }
00098
00102 void add(string code) {
00103 errors_stack.push_back(single_error(code));
00104 }
00105
00109 void add(string code, string msg) {
00110 errors_stack.push_back(single_error(code, msg));
00111 }
00112
00116 string what() {
00117 unsigned i;
00118 string result = "";
00119 for (i = 0; i < errors_stack.size(); i++) {
00120
00121 result = result + errors_stack[i].code + ": " + errors_stack[i].msg + "\n";
00122 }
00123 return result;
00124 }
00125
00126 };
00127
00128 #endif