1 #ifndef __ERROR_HPP__
2 #define __ERROR_HPP__
3 
4 /* "Species" - a CoreWars evolver.  Copyright (C) 2003 'Varfar'
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; either version 1, or (at your option) any later
9  * version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20 
21 #include <string>
22 
23 class CSpeciesError { /* utility class to throw when an unrecoverable error occurs */
24 	public:
25 		enum CODE {
26 			MISC,
27 			MARS,
28 			BAD_SPECIES_STATE,
29 			BAD_OPCODE,
30 			NEG_OPCODEFREQ_HINT,
31 			ZERO_OPCODEFREQ_HINT_SUM,
32 			BAD_CRand,
33 			BAD_FILE,
34 			EVOLVING_SPECIES_CANNOT_ADD_BENCHMARK_WARRIOR,
35 			BENCHMARK_SPECIES_CANNOT_ADD_EVOLVING_CWarrior,
36 			CANNOT_OPEN_GENERATION_FILE,
37 			CWarrior_NOT_IN_GENERATION_FILE,
38 			GENERATION_FILE_ERROR,
39 			MARS_ALLOC_ERROR,
40 			CANNOT_OPEN_INI,
41 			BAD_GEN_FILE,
42 			BAD_RESUMEFILE,
43 			CODE_LAST
44 		};
45 		CSpeciesError(const CODE code,const char *s1 = 0,const char *s2 = 0);
code() const46 		CODE code() const { return _code; }
desc() const47 		std::string desc() const { return _desc; }
48 		static const char *code_desc(const CODE code); /* fetch a description of this error condition */
49 	private:
50 		CODE _code;
51 		std::string _desc;
52 };
53 
54 // easy macros
55 #define PANIC(x,s1,s2) throw new CSpeciesError(CSpeciesError::x,s1,s2);
56 
57 // utilities, not strictly error-related, but hey
58 
59 void string_append(std::string &s,unsigned int i); // very crude, ought to be a way to sort this out
60 
61 bool file_exists(std::string &s);
62 
63 #endif // __ERROR_HPP__
64