summaryrefslogtreecommitdiffstats
path: root/raul/Symbol.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-08-12 16:29:52 +0000
committerDavid Robillard <d@drobilla.net>2012-08-12 16:29:52 +0000
commit4fe22a4f393e5e7731a07405767571da021602da (patch)
tree19db592b9c4c669645f110282da3265e226e991f /raul/Symbol.hpp
parent6ec0c7c6c4bb341926c45db99e7287cce91a8da2 (diff)
downloadraul-4fe22a4f393e5e7731a07405767571da021602da.tar.gz
raul-4fe22a4f393e5e7731a07405767571da021602da.tar.bz2
raul-4fe22a4f393e5e7731a07405767571da021602da.zip
Remove redundant Path::is_valid_name and Path::nameify.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4671 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'raul/Symbol.hpp')
-rw-r--r--raul/Symbol.hpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/raul/Symbol.hpp b/raul/Symbol.hpp
index 469a4cf..b872e3a 100644
--- a/raul/Symbol.hpp
+++ b/raul/Symbol.hpp
@@ -17,9 +17,9 @@
#ifndef RAUL_SYMBOL_HPP
#define RAUL_SYMBOL_HPP
-#include <cassert>
#include <cctype>
#include <cstring>
+#include <exception>
#include <iostream>
#include <string>
@@ -40,15 +40,26 @@ namespace Raul {
*/
class Symbol {
public:
+ class BadSymbol : public std::exception {
+ public:
+ explicit BadSymbol(const std::string& symbol) : _symbol(symbol) {}
+ ~BadSymbol() throw() {}
+ const char* what() const throw() { return _symbol.c_str(); }
+ private:
+ const std::string _symbol;
+ };
+
/** Construct a Symbol from an std::string.
*
* It is a fatal error to construct a Symbol from an invalid string,
* use is_valid first to check.
*/
- explicit Symbol(const std::basic_string<char>& symbol)
+ explicit Symbol(const std::basic_string<char>& symbol) throw(BadSymbol)
: _str(g_intern_string(symbol.c_str()))
{
- assert(is_valid(symbol));
+ if (!is_valid(symbol)) {
+ throw BadSymbol(symbol);
+ }
}
/** Construct a Symbol from a C string.
@@ -56,10 +67,12 @@ public:
* It is a fatal error to construct a Symbol from an invalid string,
* use is_valid first to check.
*/
- explicit Symbol(const char* csymbol)
+ explicit Symbol(const char* csymbol) throw(BadSymbol)
: _str(g_intern_string(csymbol))
{
- assert(is_valid(csymbol));
+ if (!is_valid(csymbol)) {
+ throw BadSymbol(csymbol);
+ }
}
Symbol& operator=(const Symbol& other) {