DynamicAny:operator [] fix (did not compile w/ VS 2003)

This commit is contained in:
Aleksandar Fabijanic
2008-02-02 21:55:14 +00:00
parent 9dde6fb1ef
commit be815af919
5 changed files with 46 additions and 186 deletions

View File

@@ -345,13 +345,31 @@ public:
bool isStruct() const;
/// Returns true if DynamicAny represents a struct
DynamicAny& operator [] (std::vector<DynamicAny>::size_type n);
template <typename T>
DynamicAny& operator [] (T n)
/// Index operator, only use on DynamicAnys where isArray
/// returns true! In all other cases a BadCastException is thrown!
{
DynamicAnyHolderImpl<std::vector<DynamicAny> >* pHolder =
dynamic_cast<DynamicAnyHolderImpl<std::vector<DynamicAny> > *>(_pHolder);
if (pHolder)
return pHolder->operator[](n);
else
throw BadCastException();
}
const DynamicAny& operator [] (std::vector<DynamicAny>::size_type n) const;
template <typename T>
const DynamicAny& operator [] (T n) const
/// const Index operator, only use on DynamicAnys where isArray
/// returns true! In all other cases a BadCastException is thrown!
{
const DynamicAnyHolderImpl<std::vector<DynamicAny> >* pHolder =
dynamic_cast<const DynamicAnyHolderImpl<std::vector<DynamicAny> > *>(_pHolder);
if (pHolder)
return pHolder->operator[](n);
else
throw BadCastException();
}
DynamicAny& operator [] (const std::string& name);
/// Index operator by name, only use on DynamicAnys where isStruct
@@ -361,6 +379,14 @@ public:
/// Index operator by name, only use on DynamicAnys where isStruct
/// returns true! In all other cases a BadCastException is thrown!
DynamicAny& operator [] (const char* name);
/// Index operator by name, only use on DynamicAnys where isStruct
/// returns true! In all other cases a BadCastException is thrown!
const DynamicAny& operator [] (const char* name) const;
/// Index operator by name, only use on DynamicAnys where isStruct
/// returns true! In all other cases a BadCastException is thrown!
const std::type_info& type() const;
/// Returns the type information of the stored content.
@@ -442,6 +468,18 @@ inline const std::type_info& DynamicAny::type() const
}
inline DynamicAny& DynamicAny::operator [] (const char* name)
{
return operator [] (std::string(name));
}
inline const DynamicAny& DynamicAny::operator [] (const char* name) const
{
return operator [] (std::string(name));
}
inline const DynamicAny DynamicAny::operator + (const char* other) const
{
return convert<std::string>() + other;