Use uchardet to guess encoding of subtitle files and reject non-UTF-8.
[dcpomatic.git] / src / lib / exceptions.h
index 6bad7c9245bbb8ae833e4202841a08a3ccfc2896..6939f81a34765b68366d5b958019299e4a3f3ab8 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
-#ifndef DCPOMATIC_EXCEPTIONS_H
-#define DCPOMATIC_EXCEPTIONS_H
-
-/** @file  src/exceptions.h
+/** @file  src/lib/exceptions.h
  *  @brief Our exceptions.
  */
 
-#include <stdexcept>
-#include <cstring>
-#include <boost/exception/all.hpp>
-#include <boost/thread.hpp>
+#ifndef DCPOMATIC_EXCEPTIONS_H
+#define DCPOMATIC_EXCEPTIONS_H
+
 extern "C" {
 #include <libavutil/pixfmt.h>
 }
+#include <boost/filesystem.hpp>
+#include <stdexcept>
+#include <cstring>
 
 /** @class StringError
  *  @brief A parent class for exceptions using messages held in a std::string
@@ -39,9 +38,9 @@ class StringError : public std::exception
 {
 public:
        /** @param w Error message */
-       StringError (std::string w) {
-               _what = w;
-       }
+       StringError (std::string w)
+               : _what (w)
+       {}
 
        virtual ~StringError () throw () {}
 
@@ -87,7 +86,7 @@ public:
        /** @param m Error message.
         *  @param f Name of the file that this exception concerns.
         */
-       FileError (std::string m, std::string f)
+       FileError (std::string m, boost::filesystem::path f)
                : StringError (m)
                , _file (f)
        {}
@@ -95,15 +94,22 @@ public:
        virtual ~FileError () throw () {}
 
        /** @return name of the file that this exception concerns */
-       std::string file () const {
+       boost::filesystem::path file () const {
                return _file;
        }
 
 private:
        /** name of the file that this exception concerns */
-       std::string _file;
+       boost::filesystem::path _file;
+};
+
+class JoinError : public StringError
+{
+public:
+       JoinError (std::string s)
+               : StringError (s)
+       {}
 };
-       
 
 /** @class OpenFileError.
  *  @brief Indicates that some error occurred when trying to open a file.
@@ -112,8 +118,7 @@ class OpenFileError : public FileError
 {
 public:
        /** @param f File that we were trying to open */
-       /* XXX: should be boost::filesystem::path */
-       OpenFileError (std::string f);
+       OpenFileError (boost::filesystem::path f);
 };
 
 /** @class CreateFileError.
@@ -123,7 +128,7 @@ class CreateFileError : public FileError
 {
 public:
        /** @param f File that we were trying to create */
-       CreateFileError (std::string f);
+       CreateFileError (boost::filesystem::path f);
 };
 
 
@@ -136,7 +141,7 @@ public:
        /** @param f File that we were trying to read from.
         *  @param e errno value, or 0.
         */
-       ReadFileError (std::string f, int e = 0);
+       ReadFileError (boost::filesystem::path f, int e = 0);
 };
 
 /** @class WriteFileError.
@@ -148,7 +153,7 @@ public:
        /** @param f File that we were trying to write to.
         *  @param e errno value, or 0.
         */
-       WriteFileError (std::string f, int e);
+       WriteFileError (boost::filesystem::path f, int e);
 };
 
 /** @class SettingError.
@@ -198,7 +203,7 @@ public:
        {}
 };
 
-/** @class NetworkError.
+/** @class NetworkError
  *  @brief Indicates some problem with communication on the network.
  */
 class NetworkError : public StringError
@@ -209,37 +214,61 @@ public:
        {}
 };
 
+/** @class KDMError
+ *  @brief A problem with a KDM.
+ */
+class KDMError : public StringError
+{
+public:
+       KDMError (std::string s)
+               : StringError (s)
+       {}
+};
+
+/** @class PixelFormatError
+ *  @brief A problem with an unsupported pixel format.
+ */
 class PixelFormatError : public StringError
 {
 public:
        PixelFormatError (std::string o, AVPixelFormat f);
 };
 
-class ExceptionStore
+/** @class SubRipError
+ *  @brief An error that occurs while parsing a SubRip file.
+ */
+class SubRipError : public FileError
 {
 public:
-       bool thrown () const {
-               boost::mutex::scoped_lock lm (_mutex);
-               return _exception;
-       }
-       
-       void rethrow () {
-               boost::mutex::scoped_lock lm (_mutex);
-               boost::rethrow_exception (_exception);
-       }
+       SubRipError (std::string, std::string, boost::filesystem::path);
+};
 
-protected:     
-       
-       void store_current () {
-               boost::mutex::scoped_lock lm (_mutex);
-               _exception = boost::current_exception ();
-       }
+class DCPError : public StringError
+{
+public:
+       DCPError (std::string s)
+               : StringError (s)
+       {}
+};
 
-private:
-       boost::exception_ptr _exception;
-       mutable boost::mutex _mutex;
+class InvalidSignerError : public StringError
+{
+public:
+       InvalidSignerError ();
+};
+
+class ProgrammingError : public StringError
+{
+public:
+       ProgrammingError (std::string file, int line);
 };
 
-       
+class TextEncodingError : public StringError
+{
+public:
+       TextEncodingError (std::string s)
+               : StringError (s)
+       {}
+};
 
 #endif