summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-12-16 20:40:21 +0000
committerCarl Hetherington <cth@carlh.net>2015-12-16 20:40:21 +0000
commit5a843c4c224051237105a6e8de472ae9a216c001 (patch)
tree8b1b2695a78e1e503a4be9a4ad7c2e643a96bd14 /src
parent5877be91301e5dd54ca125c0acd7bfb1ecc3dcd6 (diff)
Replace use of cassert with exceptions.
Diffstat (limited to 'src')
-rw-r--r--src/exceptions.cc30
-rw-r--r--src/exceptions.h6
-rw-r--r--src/stl_binary_tables.cc4
-rw-r--r--src/stl_binary_writer.cc31
-rw-r--r--src/sub_assert.h22
-rw-r--r--src/wscript1
6 files changed, 77 insertions, 17 deletions
diff --git a/src/exceptions.cc b/src/exceptions.cc
new file mode 100644
index 0000000..f33a1e2
--- /dev/null
+++ b/src/exceptions.cc
@@ -0,0 +1,30 @@
+/*
+ Copyright (C) 2014-2015 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "compose.hpp"
+#include "exceptions.h"
+
+using std::string;
+using namespace sub;
+
+ProgrammingError::ProgrammingError (string file, int line)
+ : MessageError (String::compose ("Programming error at %1:%2", file, line))
+{
+
+}
diff --git a/src/exceptions.h b/src/exceptions.h
index 62be0d5..5995942 100644
--- a/src/exceptions.h
+++ b/src/exceptions.h
@@ -99,6 +99,12 @@ public:
{}
};
+class ProgrammingError : public MessageError
+{
+public:
+ ProgrammingError (std::string file, int line);
+};
+
}
#endif
diff --git a/src/stl_binary_tables.cc b/src/stl_binary_tables.cc
index f843421..db623bf 100644
--- a/src/stl_binary_tables.cc
+++ b/src/stl_binary_tables.cc
@@ -19,8 +19,8 @@
#include "stl_binary_tables.h"
#include "exceptions.h"
+#include "sub_assert.h"
#include "compose.hpp"
-#include <cassert>
using std::map;
using std::string;
@@ -55,7 +55,7 @@ enum_to_file (E k, map<F, STLBinaryCode<E> > m)
}
}
- assert (false);
+ SUB_ASSERT (false);
return F ();
}
diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc
index b9bd7e0..aa8943c 100644
--- a/src/stl_binary_writer.cc
+++ b/src/stl_binary_writer.cc
@@ -26,6 +26,7 @@
#include "iso6937.h"
#include "stl_util.h"
#include "compose.hpp"
+#include "sub_assert.h"
#include <boost/locale.hpp>
#include <list>
#include <cmath>
@@ -62,7 +63,7 @@ put_string (char* p, string s)
static void
put_string (char* p, unsigned int n, string s)
{
- assert (s.length() <= n);
+ SUB_ASSERT (s.length() <= n);
memcpy (p, s.c_str (), s.length ());
memset (p + s.length(), ' ', n - s.length ());
@@ -76,7 +77,7 @@ put_int_as_string (char* p, int v, unsigned int n)
s.imbue (std::locale::classic ());
s << setw (n) << setfill ('0');
s << v;
- assert (s.str().length() == n);
+ SUB_ASSERT (s.str().length() == n);
put_string (p, s.str ());
}
@@ -110,19 +111,19 @@ sub::write_stl_binary (
boost::filesystem::path file_name
)
{
- assert (original_programme_title.size() <= 32);
- assert (original_episode_title.size() <= 32);
- assert (translated_programme_title.size() <= 32);
- assert (translated_episode_title.size() <= 32);
- assert (translator_name.size() <= 32);
- assert (translator_contact_details.size() <= 32);
- assert (creation_date.size() == 6);
- assert (revision_date.size() == 6);
- assert (revision_number <= 99);
- assert (country_of_origin.size() == 3);
- assert (publisher.size() <= 32);
- assert (editor_name.size() <= 32);
- assert (editor_contact_details.size() <= 32);
+ SUB_ASSERT (original_programme_title.size() <= 32);
+ SUB_ASSERT (original_episode_title.size() <= 32);
+ SUB_ASSERT (translated_programme_title.size() <= 32);
+ SUB_ASSERT (translated_episode_title.size() <= 32);
+ SUB_ASSERT (translator_name.size() <= 32);
+ SUB_ASSERT (translator_contact_details.size() <= 32);
+ SUB_ASSERT (creation_date.size() == 6);
+ SUB_ASSERT (revision_date.size() == 6);
+ SUB_ASSERT (revision_number <= 99);
+ SUB_ASSERT (country_of_origin.size() == 3);
+ SUB_ASSERT (publisher.size() <= 32);
+ SUB_ASSERT (editor_name.size() <= 32);
+ SUB_ASSERT (editor_contact_details.size() <= 32);
char* buffer = new char[1024];
memset (buffer, 0, 1024);
diff --git a/src/sub_assert.h b/src/sub_assert.h
new file mode 100644
index 0000000..67c8abe
--- /dev/null
+++ b/src/sub_assert.h
@@ -0,0 +1,22 @@
+/*
+ Copyright (C) 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "exceptions.h"
+
+#define SUB_ASSERT(x) if (!(x)) throw ProgrammingError (__FILE__, __LINE__);
diff --git a/src/wscript b/src/wscript
index a054a91..eafd1c9 100644
--- a/src/wscript
+++ b/src/wscript
@@ -15,6 +15,7 @@ def build(bld):
colour.cc
dcp_reader.cc
effect.cc
+ exceptions.cc
font_size.cc
interop_dcp_reader.cc
iso6937.cc