diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-01 05:24:54 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-01 05:24:54 +0000 |
commit | 9f187b46ae761e8275362d6c1533e9fe79028c7b (patch) | |
tree | e2625f63e0c84f172c877e1fe2cbe75adf678208 /cpp/sca/kernel/value.hpp | |
parent | 24021bd09a0d5c9664565a244c24e0bdef0908b8 (diff) |
Improved memory management using APR memory pools, changed frame allocation in eval library to support forward references and fixed memory leak in XML parsing code. Also simplified a bit the printing of lists to make them easier to read.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@831639 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | cpp/sca/kernel/value.hpp | 108 |
1 files changed, 85 insertions, 23 deletions
diff --git a/cpp/sca/kernel/value.hpp b/cpp/sca/kernel/value.hpp index d57264ff43..618bd7b622 100644 --- a/cpp/sca/kernel/value.hpp +++ b/cpp/sca/kernel/value.hpp @@ -60,7 +60,7 @@ class value { public: enum ValueType { - Undefined, Symbol, String, List, Number, Boolean, Character, Lambda + Undefined, Symbol, String, List, Number, Bool, Char, Lambda, Ptr, PoolPtr }; value() : @@ -84,10 +84,14 @@ public: str() = v.str(); case value::Number: num() = v.num(); - case value::Boolean: + case value::Bool: boo() = v.boo(); - case value::Character: + case value::Char: chr() = v.chr(); + case value::Ptr: + ptr() = v.ptr(); + case value::PoolPtr: + poolptr() = v.poolptr(); default: break; } @@ -108,10 +112,14 @@ public: str() = v.str(); case value::Number: num() = v.num(); - case value::Boolean: + case value::Bool: boo() = v.boo(); - case value::Character: + case value::Char: chr() = v.chr(); + case value::Ptr: + ptr() = v.ptr(); + case value::PoolPtr: + poolptr() = v.poolptr(); default: break; } @@ -165,13 +173,25 @@ public: } value(const bool boo) : - type(value::Boolean), data(vdata(result(boo))) { + type(value::Bool), data(vdata(result(boo))) { countValues++; countVValues++; } value(const char chr) : - type(value::Character), data(vdata(result(chr))) { + type(value::Char), data(vdata(result(chr))) { + countValues++; + countVValues++; + } + + value(const gc_ptr<value> ptr) : + type(value::Ptr), data(vdata(result(ptr))) { + countValues++; + countVValues++; + } + + value(const gc_pool_ptr<value> ptr) : + type(value::PoolPtr), data(vdata(result(ptr))) { countValues++; countVValues++; } @@ -198,10 +218,14 @@ public: return str()() == v.str()(); case value::Number: return num()() == v.num()(); - case value::Boolean: + case value::Bool: return boo()() == v.boo()(); - case value::Character: + case value::Char: return chr()() == v.chr()(); + case value::Ptr: + return ptr()() == v.ptr()(); + case value::PoolPtr: + return poolptr()() == v.poolptr()(); default: return false; } @@ -215,6 +239,8 @@ public: switch(type) { case value::List: case value::Lambda: + case value::Ptr: + case value::PoolPtr: return ""; case value::Symbol: case value::String: @@ -224,13 +250,13 @@ public: sos << num()(); return sos.str(); } - case value::Boolean: { + case value::Bool: { if(boo()()) return "true"; else return "false"; } - case value::Character: { + case value::Char: { std::ostringstream sos; sos << chr()(); return sos.str(); @@ -256,6 +282,14 @@ public: return chr()(); } + operator const gc_ptr<value>() const { + return ptr()(); + } + + operator const gc_pool_ptr<value>() const { + return poolptr()(); + } + operator const list<value>() const { return lst()(); } @@ -294,6 +328,14 @@ private: return vdata<char()> (); } + lambda<gc_ptr<value>()>& ptr() const { + return vdata<gc_ptr<value>()> (); + } + + lambda<gc_pool_ptr<value>()>& poolptr() const { + return vdata<gc_pool_ptr<value>()> (); + } + lambda<std::string()>& str() const { return vdata<std::string()> (); } @@ -328,18 +370,30 @@ std::ostream& operator<<(std::ostream& out, const value& v) { case value::Lambda: return out << "lambda::" << v.func(); case value::Symbol: - return out << "symbol::" << v.str()(); + return out << v.str()(); case value::String: - return out << "string::" << '\"' << v.str()() << '\"'; + return out << '\"' << v.str()() << '\"'; case value::Number: - return out << "number::" << v.num()(); - case value::Boolean: + return out << v.num()(); + case value::Bool: if(v.boo()()) - return out << "bool::" << "true"; + return out << "true"; else - return out << "bool::" << "false"; - case value::Character: - return out << "char::" << v.chr()(); + return out << "false"; + case value::Char: + return out << v.chr()(); + case value::Ptr: { + const gc_ptr<value> p = v.ptr()(); + if (p == gc_ptr<value>(NULL)) + return out << "pointer::null"; + return out << "pointer::" << *p; + } + case value::PoolPtr: { + const gc_pool_ptr<value> p = v.poolptr()(); + if (p == gc_pool_ptr<value>(NULL)) + return out << "pointer::null"; + return out << "pointer::" << *p; + } default: return out << "undefined"; } @@ -369,12 +423,20 @@ const bool isNumber(const value& value) { return value.type == value::Number; } -const bool isBoolean(const value& value) { - return value.type == value::Boolean; +const bool isBool(const value& value) { + return value.type == value::Bool; +} + +const bool isChar(const value& value) { + return value.type == value::Char; +} + +const bool isPtr(const value& value) { + return value.type == value::Ptr; } -const bool isCharacter(const value& value) { - return value.type == value::Character; +const bool isPoolPtr(const value& value) { + return value.type == value::PoolPtr; } const bool isTaggedList(const value& exp, value tag) { |