diff options
author | Karl Berry <karl@freefriends.org> | 2010-07-05 22:26:04 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2010-07-05 22:26:04 +0000 |
commit | 648027bec248a7b000741a507b507f6d89941ce5 (patch) | |
tree | ce3b82b43a8b17403eda43db782bbf2e5bf0e161 /Build/source/utils/asymptote/item.h | |
parent | 5ff8f96c8ab3bd3aeb8fed8d512c57134fb2a6cc (diff) |
asy 2.00
git-svn-id: svn://tug.org/texlive/trunk@19250 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/item.h')
-rw-r--r-- | Build/source/utils/asymptote/item.h | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/Build/source/utils/asymptote/item.h b/Build/source/utils/asymptote/item.h index 9a42f8bf2e2..7c4eec4522f 100644 --- a/Build/source/utils/asymptote/item.h +++ b/Build/source/utils/asymptote/item.h @@ -11,8 +11,12 @@ #include "common.h" #include <cfloat> #include <cmath> -#include <typeinfo> + +#if COMPACT #include <cassert> +#else +#include <typeinfo> +#endif namespace vm { @@ -28,6 +32,14 @@ extern const Int DefaultValue; // Identify an undefined item. extern const Int Undefined; + +// Values for true and false unlikely to match other values. +extern const Int BoolTruthValue; +extern const Int BoolFalseValue; + +inline Int valueFromBool(bool b) { + return b ? BoolTruthValue : BoolFalseValue; +} #endif extern const item Default; @@ -35,14 +47,12 @@ extern const item Default; class item : public gc { private: -#if !COMPACT - const std::type_info *kind; -#endif - union { Int i; double x; +#if !COMPACT bool b; +#endif void *p; }; @@ -60,7 +70,7 @@ public: item(double x) : x(x) {} item(bool b) - : b(b) {} + : i(valueFromBool(b)) {} item& operator= (int a) { i=a; return *this; } @@ -70,29 +80,31 @@ public: { i=a; return *this; } item& operator= (double a) { x=a; return *this; } - item& operator= (bool a) - { b=a; return *this; } + item& operator= (bool b) + { i=valueFromBool(b); return *this; } template<class T> item(T *p) - : p((void *) p) { + : i((Int) p) { assert(!empty()); } template<class T> - item(const T &P) - : p(new(UseGC) T(P)) { + item(const T &p) + : i((Int) new(UseGC) T(p)) { assert(!empty()); } template<class T> item& operator= (T *a) - { p=(void *) a; return *this; } + { i=(Int) a; return *this; } template<class T> item& operator= (const T &it) - { p=new(UseGC) T(it); return *this; } + { i=(Int) new(UseGC) T(it); return *this; } #else + const std::type_info *kind; + bool empty() const {return *kind == typeid(void);} @@ -257,8 +269,10 @@ template <> inline bool get<bool>(const item& it) { #if COMPACT - if(!it.empty()) - return it.b; + if(it.i == BoolTruthValue) + return true; + if(it.i == BoolFalseValue) + return false; #else if(*it.kind == typeid(bool)) return it.b; |