summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b4f950e)
raw | patch | inline | side by side (parent: b4f950e)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Sat, 17 Nov 2007 23:06:41 +0000 (23:06 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Sat, 17 Nov 2007 23:06:41 +0000 (23:06 +0000) |
src/2geom/Makefile_insert | patch | blob | history | |
src/2geom/basic-intersection.cpp | patch | blob | history | |
src/2geom/exception.h | [new file with mode: 0644] | patch | blob |
src/2geom/path.cpp | patch | blob | history | |
src/2geom/path.h | patch | blob | history | |
src/2geom/sbasis.h | patch | blob | history | |
src/2geom/svg-path-parser.h | patch | blob | history | |
src/2geom/utils.h | patch | blob | history |
index d10b18764468170903abc2b6da195a45176451e1..fd2de092ce730dcb0389fd65855450181f00d300 100644 (file)
2geom/d2-sbasis.cpp \\r
2geom/d2-sbasis.h \\r
2geom/d2.h \\r
+ 2geom/exception.h \\r
2geom/geom.cpp \\r
2geom/geom.h \\r
2geom/interval.h \\r
index ee1244a7390da29b41830a3001b4a8b6ae2011cc..28b3c6f2091ea3ce678e1c05ab8e51087e80bc2e 100644 (file)
#include "basic-intersection.h"
+#include "exception.h"
unsigned intersect_steps = 0;
diff --git a/src/2geom/exception.h b/src/2geom/exception.h
--- /dev/null
+++ b/src/2geom/exception.h
@@ -0,0 +1,119 @@
+#ifndef LIB2GEOM_EXCEPTION_HEADER
+#define LIB2GEOM_EXCEPTION_HEADER
+
+/** Defines the different types of exceptions that 2geom can throw.
+ *
+ * Copyright 2007 Johan Engelen <goejendaagh@zonnet.nl>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ */
+
+#include <exception>
+#include <string>
+
+namespace Geom {
+
+// Base exception class, all 2geom exceptions should be derrived from this one.
+class Exception : public std::exception {
+public:
+ Exception(const char * message, const char *file, const int line)
+ : msgstr("Exception thrown: ")
+ {
+ msgstr += message;
+ msgstr += " (";
+ msgstr += file;
+ msgstr += ":";
+ msgstr += line;
+ msgstr += ")";
+ }
+
+ virtual ~Exception() throw() {} // necessary to destroy the string object!!!
+
+ virtual const char * what() const throw (){
+ return msgstr.c_str();
+ }
+protected:
+ std::string msgstr;
+};
+
+//-----------------------------------------------------------------------
+// Two main exception classes: LogicalError and RangeError.
+// Logical errors are 2geom faults/bugs, RangeErrors are 'user' faults.
+// This way, the 'user' can distinguish between groups of exceptions
+// ('user' is the coder that uses lib2geom)
+class LogicalError : public Exception {
+public:
+ LogicalError(const char * message, const char *file, const int line)
+ : Exception(message, file, line) {}
+};
+#define throwLogicalError(message) throw(LogicalError(message, __FILE__, __LINE__))
+
+class RangeError : public Exception {
+public:
+ RangeError(const char * message, const char *file, const int line)
+ : Exception(message, file, line) {}
+};
+#define throwRangeError(message) throw(RangeError(message, __FILE__, __LINE__))
+
+//-----------------------------------------------------------------------
+// Special case exceptions. Best used with the defines :)
+
+class NotImplemented : public LogicalError {
+public:
+ NotImplemented(const char *file, const int line)
+ : LogicalError("Method not implemented", file, line) {}
+};
+#define throwNotImplemented(i) throw(NotImplemented(__FILE__, __LINE__))
+
+class InvariantsViolation : public LogicalError {
+public:
+ InvariantsViolation(const char *file, const int line)
+ : LogicalError("Invariants violation", file, line) {}
+};
+#define throwInvariantsViolation(i) throw(InvariantsViolation(__FILE__, __LINE__))
+#define assert_invariants(e) ((e) ? (void)0 : throwInvariantsViolation())
+
+class NotInvertible : public RangeError {
+public:
+ NotInvertible(const char *file, const int line)
+ : RangeError("Function does not have a unique inverse", file, line) {}
+};
+#define throwNotInvertible(i) throw(NotInvertible(__FILE__, __LINE__))
+
+class ContinuityError : public RangeError {
+public:
+ ContinuityError(const char *file, const int line)
+ : RangeError("Non-contiguous path", file, line) {}
+};
+#define throwContinuityError(i) throw(ContinuityError(__FILE__, __LINE__))
+
+struct SVGPathParseError : public std::exception {
+ char const *what() const throw() { return "parse error"; }
+};
+
+
+} // namespace Geom
+
+#endif
diff --git a/src/2geom/path.cpp b/src/2geom/path.cpp
index ba6643ae4af9a29b0c950aa223ee5b93a200f775..3d8d5ead3cafd63bfd00732abb85b6f5c882c220 100644 (file)
--- a/src/2geom/path.cpp
+++ b/src/2geom/path.cpp
void Path::append(Curve const &curve) {
if ( curves_.front() != final_ && !are_near(curve.initialPoint(), (*final_)[0], eps) ) {
- throw ContinuityError();
+ throwContinuityError();
}
do_append(curve.duplicate());
}
if ( curves_.front() != final_ ) {
for ( int i = 0 ; i < 2 ; ++i ) {
if ( !are_near(curve[i][0][0], (*final_)[0][i], eps) ) {
- throw ContinuityError();
+ throwContinuityError();
}
}
}
if ( first != last ) {
if ( first_replaced != curves_.begin() ) {
if ( !are_near( (*first_replaced)->initialPoint(), (*first)->initialPoint(), eps ) ) {
- throw ContinuityError();
+ throwContinuityError();
}
}
if ( last_replaced != (curves_.end()-1) ) {
if ( !are_near( (*(last_replaced-1))->finalPoint(), (*(last-1))->finalPoint(), eps ) ) {
- throw ContinuityError();
+ throwContinuityError();
}
}
} else if ( first_replaced != last_replaced && first_replaced != curves_.begin() && last_replaced != curves_.end()-1) {
if ( !are_near((*first_replaced)->initialPoint(), (*(last_replaced-1))->finalPoint(), eps ) ) {
- throw ContinuityError();
+ throwContinuityError();
}
}
}
diff --git a/src/2geom/path.h b/src/2geom/path.h
index 053bc06c960fb9da48f495e0c2bce7ea4490c1c1..988babe3e2f077e3de03480b5b6007c43c2d2ede 100644 (file)
--- a/src/2geom/path.h
+++ b/src/2geom/path.h
#include "point.h"
#include <iterator>
#include <algorithm>
-#include <exception>
-#include <stdexcept>
+#include "exception.h"
#include "d2.h"
#include "matrix.h"
#include "bezier.h"
Iterator impl_;
};
-class ContinuityError : public std::runtime_error {
-public:
- ContinuityError() : runtime_error("non-contiguous path") {}
- ContinuityError(std::string const &message) : runtime_error(message) {}
-};
-
class Path {
private:
typedef std::vector<Curve *> Sequence;
diff --git a/src/2geom/sbasis.h b/src/2geom/sbasis.h
index df41dca584fd8d1da82ebf5c73eb044620c3d049..acaa190a6471c38a40ac4d5d12c3d76eba2c7444 100644 (file)
--- a/src/2geom/sbasis.h
+++ b/src/2geom/sbasis.h
#include "linear.h"
#include "interval.h"
#include "utils.h"
+#include "exception.h"
namespace Geom {
std::vector<double> valueAndDerivatives(double /*t*/, unsigned /*n*/) const {
//TODO
throwNotImplemented();
- //throw(NotImplemented(__FILE__, __LINE__));
}
SBasis toSBasis() const { return SBasis(*this); }
index 4017df45867187c4035083d24c6ad3ad603db7d3..98a885361dff03cbeb925abedd855a248aa93821 100644 (file)
#include <vector>
#include <iterator>
-#include <exception>
+#include <stdexcept>
+#include "exception.h"
#include "point.h"
#include "svg-path.h"
namespace Geom {
-struct SVGPathParseError : public std::exception {
- char const *what() const throw() { return "parse error"; }
-};
-
void parse_svg_path(char const *str, SVGPathSink &sink) throw(SVGPathParseError);
inline std::vector<Path> parse_svg_path(char const *str) throw(SVGPathParseError) {
diff --git a/src/2geom/utils.h b/src/2geom/utils.h
index cd2a9c26ce3c0c3e003ccbe61b9974b792565fea..c5c5793389d83b2effe4198584a3129802c25b91 100644 (file)
--- a/src/2geom/utils.h
+++ b/src/2geom/utils.h
*/
#include <cmath>
-#include <stdexcept>
namespace Geom {
-
-//#######################################################################
-// Base exception class, all 2geom exceptions should be derrived from this one.
-class Exception : public std::exception {
-public:
- Exception(const char * message, const char *file, const int line) {
- msgstr = "Exception thrown: ";
- msgstr += message;
- msgstr += " (";
- msgstr += file;
- msgstr += ":";
- msgstr += line;
- msgstr += ")";
- };
- virtual ~Exception() throw() {}; // necessary to destroy the string object!!!
- virtual const char * what() const throw () { return msgstr.c_str(); }
-protected:
- std::string msgstr;
-};
-
-//-----------------------------------------------------------------------
-// Two main exception classes: LogicalError and RangeError.
-// Logical errors are 2geom faults/bugs, RangeErrors are 'user' faults.
-// This way, the 'user' can distinguish between groups of exceptions
-// ('user' is the coder that uses lib2geom)
-class LogicalError : public Exception {
-public:
- LogicalError(const char * message, const char *file, const int line)
- : Exception(message, file, line) {};
-};
-#define throwLogicalError(message) throw(LogicalError(message, __FILE__, __LINE__))
-
-class RangeError : public Exception {
-public:
- RangeError(const char * message, const char *file, const int line)
- : Exception(message, file, line) {};
-};
-#define throwRangeError(message) throw(RangeError(message, __FILE__, __LINE__))
-
-//-----------------------------------------------------------------------
-// Special case exceptions. Best used with the defines :)
-
-class NotImplemented : public LogicalError {
-public:
- NotImplemented(const char *file, const int line)
- : LogicalError("Method not implemented", file, line) {};
-};
-#define throwNotImplemented(i) throw(NotImplemented(__FILE__, __LINE__))
-
-class InvariantsViolation : public LogicalError {
-public:
- InvariantsViolation(const char *file, const int line)
- : LogicalError("Invariants violation", file, line) {};
-};
-#define throwInvariantsViolation(i) throw(InvariantsViolation(__FILE__, __LINE__))
-#define assert_invariants(e) ((e) ? (void)0 : throwInvariantsViolation())
-
-class NotInvertible : public RangeError {
-public:
- NotInvertible(const char *file, const int line)
- : RangeError("Function does not have a unique inverse", file, line) {};
-};
-#define throwNotInvertible(i) throw(NotInvertible(__FILE__, __LINE__))
-
-//#######################################################################
-
// proper logical xor
inline bool logical_xor (bool a, bool b) { return (a || b) && !(a && b); }