summaryrefslogtreecommitdiff
path: root/graphics/asymptote/item.h
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/asymptote/item.h')
-rw-r--r--graphics/asymptote/item.h94
1 files changed, 47 insertions, 47 deletions
diff --git a/graphics/asymptote/item.h b/graphics/asymptote/item.h
index 60fb89fe6e..70d4923445 100644
--- a/graphics/asymptote/item.h
+++ b/graphics/asymptote/item.h
@@ -29,7 +29,7 @@ T get(const item&);
#if COMPACT
// Identify a default argument.
extern const Int DefaultValue;
-
+
// Identify an undefined item.
extern const Int Undefined;
@@ -41,16 +41,16 @@ inline Int valueFromBool(bool b) {
return b ? BoolTruthValue : BoolFalseValue;
}
#endif
-
+
extern const item Default;
class item : public gc {
private:
-
+
#if !COMPACT
const std::type_info *kind;
#endif
-
+
union {
Int i;
double x;
@@ -61,12 +61,12 @@ private:
};
public:
-#if COMPACT
+#if COMPACT
bool empty() const
{return i >= Undefined;}
-
+
item() : i(Undefined) {}
-
+
item(Int i)
: i(i) {}
item(int i)
@@ -75,7 +75,7 @@ public:
: x(x) {}
item(bool b)
: i(valueFromBool(b)) {}
-
+
item& operator= (int a)
{ i=a; return *this; }
item& operator= (unsigned int a)
@@ -86,33 +86,33 @@ public:
{ x=a; return *this; }
item& operator= (bool b)
{ i=valueFromBool(b); return *this; }
-
+
template<class T>
item(T *p)
: p((void *) p) {
assert(!empty());
}
-
+
template<class T>
item(const T &p)
: p(new(UseGC) T(p)) {
assert(!empty());
}
-
+
template<class T>
item& operator= (T *a)
{ p=(void *) a; return *this; }
-
+
template<class T>
item& operator= (const T &it)
{ p=new(UseGC) T(it); return *this; }
-#else
+#else
bool empty() const
{return *kind == typeid(void);}
-
+
item()
: kind(&typeid(void)) {}
-
+
item(Int i)
: kind(&typeid(Int)), i(i) {}
item(int i)
@@ -121,7 +121,7 @@ public:
: kind(&typeid(double)), x(x) {}
item(bool b)
: kind(&typeid(bool)), b(b) {}
-
+
item& operator= (int a)
{ kind=&typeid(Int); i=a; return *this; }
item& operator= (unsigned int a)
@@ -132,69 +132,69 @@ public:
{ kind=&typeid(double); x=a; return *this; }
item& operator= (bool a)
{ kind=&typeid(bool); b=a; return *this; }
-
+
template<class T>
item(T *p)
: kind(&typeid(T)), p((void *) p) {}
-
+
template<class T>
item(const T &p)
: kind(&typeid(T)), p(new(UseGC) T(p)) {}
-
+
template<class T>
item& operator= (T *a)
{ kind=&typeid(T); p=(void *) a; return *this; }
-
+
template<class T>
item& operator= (const T &it)
{ kind=&typeid(T); p=new(UseGC) T(it); return *this; }
-
+
const std::type_info &type() const
{ return *kind; }
-#endif
-
+#endif
+
template<typename T>
friend inline T get(const item&);
friend inline bool isdefault(const item&);
-
+
friend ostream& operator<< (ostream& out, const item& i);
private:
template <typename T>
struct help;
-
+
template <typename T>
struct help<T*> {
static T* unwrap(const item& it)
{
-#if COMPACT
+#if COMPACT
if(!it.empty())
return (T*) it.p;
-#else
+#else
if(*it.kind == typeid(T))
return (T*) it.p;
-#endif
+#endif
throw vm::bad_item_value();
}
};
-
+
template <typename T>
struct help {
static T& unwrap(const item& it)
{
-#if COMPACT
+#if COMPACT
if(!it.empty())
return *(T*) it.p;
-#else
+#else
if(*it.kind == typeid(T))
return *(T*) it.p;
-#endif
+#endif
throw vm::bad_item_value();
}
};
};
-
+
#ifdef SIMPLE_FRAME
// In the simple implementation, a frame is just an array of items.
typedef item frame;
@@ -231,7 +231,7 @@ public:
size_t size()
{ return vars.size(); }
-
+
// Extends vars to ensure it has a place for any variable indexed up to n.
void extend(size_t n) {
if(vars.size() < n)
@@ -245,31 +245,31 @@ template<typename T>
inline T get(const item& it)
{
return item::help<T>::unwrap(it);
-}
+}
template <>
inline int get<int>(const item&)
{
throw vm::bad_item_value();
}
-
+
template <>
inline Int get<Int>(const item& it)
{
-#if COMPACT
+#if COMPACT
if(!it.empty())
return it.i;
#else
if(*it.kind == typeid(Int))
return it.i;
-#endif
+#endif
throw vm::bad_item_value();
}
-
+
template <>
inline double get<double>(const item& it)
{
-#if COMPACT
+#if COMPACT
if(!it.empty())
return it.x;
#else
@@ -282,15 +282,15 @@ inline double get<double>(const item& it)
template <>
inline bool get<bool>(const item& it)
{
-#if COMPACT
+#if COMPACT
if(it.i == BoolTruthValue)
return true;
if(it.i == BoolFalseValue)
return false;
-#else
+#else
if(*it.kind == typeid(bool))
return it.b;
-#endif
+#endif
throw vm::bad_item_value();
}
@@ -301,12 +301,12 @@ struct default_t : public gc {};
inline bool isdefault(const item& it)
{
-#if COMPACT
+#if COMPACT
return it.i == DefaultValue;
-#else
+#else
return *it.kind == typeid(default_t);
-#endif
-}
+#endif
+}
ostream& operator<< (ostream& out, const item& i);