summaryrefslogtreecommitdiff
path: root/src/value.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-10-30 17:56:44 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-10-30 17:57:29 -0400
commit7ca80112fc817687481a40b65e4faa56a92c3ebe (patch)
treec371d1cb802795500dc9c174014b37c1058594ec /src/value.h
parent5f2c766e0dc5405c9fa86c39a521bd48079d4b30 (diff)
downloadfork-ledger-7ca80112fc817687481a40b65e4faa56a92c3ebe.tar.gz
fork-ledger-7ca80112fc817687481a40b65e4faa56a92c3ebe.tar.bz2
fork-ledger-7ca80112fc817687481a40b65e4faa56a92c3ebe.zip
Change the value_t::POINTER type to value_t::SCOPE
scope_t pointers are the only kind that are ever stored in value objects, so there was no need to make it generic and use boost::any.
Diffstat (limited to 'src/value.h')
-rw-r--r--src/value.h64
1 files changed, 17 insertions, 47 deletions
diff --git a/src/value.h b/src/value.h
index 31850894..1670be1b 100644
--- a/src/value.h
+++ b/src/value.h
@@ -56,6 +56,8 @@ namespace ledger {
DECLARE_EXCEPTION(value_error, std::runtime_error);
+class scope_t;
+
/**
* @class value_t
*
@@ -107,7 +109,7 @@ public:
STRING, // a string object
MASK, // a regular expression mask
SEQUENCE, // a vector of value_t objects
- POINTER // an opaque pointer of any type
+ SCOPE // a pointer to a scope
};
private:
@@ -134,7 +136,7 @@ private:
string, // STRING
mask_t, // MASK
sequence_t *, // SEQUENCE
- boost::any // POINTER
+ scope_t * // SCOPE
> data;
type_t type;
@@ -332,10 +334,9 @@ public:
set_sequence(val);
}
- template <typename T>
- explicit value_t(T * item) {
- TRACE_CTOR(value_t, "T *");
- set_pointer(item);
+ explicit value_t(scope_t * item) {
+ TRACE_CTOR(value_t, "scope_t *");
+ set_scope(item);
}
/**
@@ -687,50 +688,19 @@ public:
}
/**
- * Dealing with pointers is bit involved because we actually deal
- * with typed pointers. For example, if you call as_pointer it
- * returns a boost::any object, but if you use as_pointer<void>,
- * then it returns a void *. The latter form only succeeds if the
- * stored pointers was assigned to the value as a void*, otherwise
- * it throws an exception.
+ * Dealing with scope pointers.
*/
- bool is_pointer() const {
- return is_type(POINTER);
- }
- boost::any& as_any_pointer_lval() {
- VERIFY(is_pointer());
- _dup();
- return boost::get<boost::any>(storage->data);
- }
- template <typename T>
- T * as_pointer_lval() {
- return any_cast<T *>(as_any_pointer_lval());
- }
- template <typename T>
- T& as_ref_lval() {
- return *as_pointer_lval<T>();
- }
- const boost::any& as_any_pointer() const {
- VERIFY(is_pointer());
- return boost::get<boost::any>(storage->data);
+ bool is_scope() const {
+ return is_type(SCOPE);
}
- template <typename T>
- T * as_pointer() const {
- return any_cast<T *>(as_any_pointer());
+ scope_t * as_scope() const {
+ VERIFY(is_scope());
+ return boost::get<scope_t *>(storage->data);
}
- template <typename T>
- T& as_ref() const {
- return *as_pointer<T>();
- }
- void set_any_pointer(const boost::any& val) {
- set_type(POINTER);
+ void set_scope(scope_t * val) {
+ set_type(SCOPE);
storage->data = val;
}
- template <typename T>
- void set_pointer(T * val) {
- set_type(POINTER);
- storage->data = boost::any(val);
- }
/**
* Data conversion methods. These methods convert a value object to
@@ -902,8 +872,8 @@ public:
return _("a regexp");
case SEQUENCE:
return _("a sequence");
- case POINTER:
- return _("a pointer");
+ case SCOPE:
+ return _("a scope");
default:
assert(false);
break;