diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-09-26 21:45:45 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-09-26 21:45:45 +0900 |
| commit | 05104ba177d792b74c6455516e063c4d9a5a8ebd (patch) | |
| tree | f9b6d5733caed8dc67951da13e078e756df278db /src/ValueBase.h | |
| parent | 374955da0df726bc643d6466b97ece8b534ad3eb (diff) | |
Removed asString, asList, ... and use downcast<T> instead.
Diffstat (limited to 'src/ValueBase.h')
| -rw-r--r-- | src/ValueBase.h | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/src/ValueBase.h b/src/ValueBase.h index e13d12d2..763114d4 100644 --- a/src/ValueBase.h +++ b/src/ValueBase.h @@ -239,6 +239,8 @@ public: const SharedHandle<ValueBase>& get(const std::string& key) const; + SharedHandle<ValueBase>& get(const std::string& key); + // Returns the reference to object associated with given key. If // the key is not found, new pair with that key is created using // default values, which is then returned. In other words, this is @@ -321,42 +323,26 @@ private: template<typename T, typename VPtr> const T* downcast(const VPtr& v) { - DowncastValueBaseVisitor<T> visitor; - v->accept(visitor); - return visitor.getResult(); + if(v) { + DowncastValueBaseVisitor<T> visitor; + v->accept(visitor); + return visitor.getResult(); + } else { + return 0; + } } -const String* asString(const ValueBase* v); - -String* asString(ValueBase* v); - -String* asString(const SharedHandle<ValueBase>& v); - -const Integer* asInteger(const ValueBase* v); - -Integer* asInteger(ValueBase* v); - -Integer* asInteger(const SharedHandle<ValueBase>& v); - -const Bool* asBool(const ValueBase* v); - -Bool* asBool(const SharedHandle<ValueBase>& v); - -const Null* asNull(const ValueBase* v); - -Null* asNull(const SharedHandle<ValueBase>& v); - -const List* asList(const ValueBase* v); - -List* asList(ValueBase* v); - -List* asList(const SharedHandle<ValueBase>& v); - -const Dict* asDict(const ValueBase* v); - -Dict* asDict(ValueBase* v); - -Dict* asDict(const SharedHandle<ValueBase>& v); +template<typename T, typename VPtr> +T* downcast(VPtr& v) +{ + if(v) { + DowncastValueBaseVisitor<T> visitor; + v->accept(visitor); + return const_cast<T*>(visitor.getResult()); + } else { + return 0; + } +} } // namespace aria2 |
