add a followviewport bool to uncontrolled_sounds, so that the c1 music doesn't get...
[openc2e.git] / exceptions.h
blob77f140ed7a311d30a1821e5472a80a75313bf06b
1 /*
2 * exceptions.h
3 * openc2e
5 * Created by Alyssa Milburn on Sat 13 Nov 2004.
6 * Copyright (c) 2004-2005 Alyssa Milburn. All rights reserved.
7 * Copyright (c) 2005-2006 Bryan Donlan. All rights reserved.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
20 #ifndef __C2EEXCEPTIONS_H
21 #define __C2EEXCEPTIONS_H
23 #include <exception>
24 #include <cstdlib>
25 #include <string>
26 #include <vector>
27 #include <sstream>
28 #include <assert.h>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/scoped_ptr.hpp>
32 class script;
34 class creaturesException : public std::exception {
35 protected:
36 bool malloced;
37 const char *r;
40 public:
41 virtual std::string prettyPrint() const { return std::string(what()); }
42 creaturesException(const creaturesException &e) throw() : std::exception() {
43 // catch clause missing & etc, we'll try to patch over it but you should fix it really.
44 fprintf(stderr, "QA: creaturesException copy constructor called.\n");
45 r = strdup(e.r);
46 malloced = true;
48 creaturesException(const char *s) throw() { r = s; malloced = false; }
49 creaturesException(const std::string &s) throw() {
50 r = strdup(s.c_str());
51 if (!r) {
52 abort();
54 malloced = true;
56 ~creaturesException() throw() {
57 if (malloced) free((void *)r);
59 const char* what() const throw() { return r; }
62 class caosException : public creaturesException {
63 protected:
64 boost::shared_ptr<class script> script;
65 int traceindex;
67 public:
68 /* debug hook, removeme */
69 virtual const char *what() const throw() { return this->creaturesException::what(); }
71 ~caosException() throw() { }
73 caosException(const std::string &d) throw() : creaturesException(d), traceindex(-1) { }
75 caosException(const char *d) throw() : creaturesException(d), traceindex(-1) { }
77 void trace(boost::shared_ptr<class script> scr, int traceindex = -1) throw();
79 virtual std::string prettyPrint() const;
84 static inline std::string buildExceptionString(const char *s, const char *file, int line) {
85 std::ostringstream oss;
86 oss << s << " at " << file << ':' << line;
87 return oss.str();
91 struct tracedAssertFailure : public creaturesException {
92 tracedAssertFailure(const char *s, const char *file, int line)
93 : creaturesException(buildExceptionString(s, file, line)) { }
97 class tokeniseFailure : public creaturesException {
98 public:
99 tokeniseFailure(const char *s) throw() : creaturesException(s) { }
100 tokeniseFailure(const std::string &s) throw() : creaturesException(s) { }
103 class parseFailure : public creaturesException {
104 public:
105 parseFailure(const char *s) throw()
106 : creaturesException(s), lineno(-1) { }
107 parseFailure(const std::string &s) throw()
108 : creaturesException(s), lineno(-1) { }
109 ~parseFailure() throw() { }
111 boost::shared_ptr<std::vector<class token> > context;
112 int ctxoffset;
113 std::string filename;
114 int lineno;
116 std::string prettyPrint() const;
119 typedef parseFailure parseException;
121 class genomeException : public creaturesException {
122 public:
123 genomeException(const char *s) throw() : creaturesException(s) { }
124 genomeException(const std::string &s) throw() : creaturesException(s) { }
127 #endif
128 /* vim: set noet: */