summaryrefslogtreecommitdiff
path: root/graphics/asymptote/lexical.h
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/asymptote/lexical.h
Initial commit
Diffstat (limited to 'graphics/asymptote/lexical.h')
-rw-r--r--graphics/asymptote/lexical.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/graphics/asymptote/lexical.h b/graphics/asymptote/lexical.h
new file mode 100644
index 0000000000..fc3879961d
--- /dev/null
+++ b/graphics/asymptote/lexical.h
@@ -0,0 +1,23 @@
+#ifndef __lexical_h__
+#define __lexical_h__ 1
+
+#include <sstream>
+
+#include "common.h"
+
+namespace lexical {
+
+class bad_cast {};
+
+template <typename T>
+T cast(const string& s, bool tolerant=false)
+{
+ istringstream is(s);
+ T value;
+ if(is && is >> value && ((is >> std::ws).eof() || tolerant)) return value;
+ throw bad_cast();
+}
+
+}
+
+#endif