any.hxx | any.hxx | |||
---|---|---|---|---|
skipping to change at line 26 | skipping to change at line 26 | |||
namespace cutl | namespace cutl | |||
{ | { | |||
namespace container | namespace container | |||
{ | { | |||
class LIBCUTL_EXPORT any | class LIBCUTL_EXPORT any | |||
{ | { | |||
public: | public: | |||
struct LIBCUTL_EXPORT typing: exception {}; | struct LIBCUTL_EXPORT typing: exception {}; | |||
public: | public: | |||
any () | ||||
{ | ||||
} | ||||
template <typename X> | template <typename X> | |||
any (X const& x) | any (X const& x) | |||
: holder_ (new holder_impl<X> (x)) | : holder_ (new holder_impl<X> (x)) | |||
{ | { | |||
} | } | |||
any (any const& x) | any (any const& x) | |||
: holder_ (x.holder_->clone ()) | : holder_ (x.holder_->clone ()) | |||
{ | { | |||
} | } | |||
skipping to change at line 73 | skipping to change at line 77 | |||
template <typename X> | template <typename X> | |||
X const& | X const& | |||
value () const | value () const | |||
{ | { | |||
if (holder_impl<X>* p = dynamic_cast<holder_impl<X>*> (holder_.get ())) | if (holder_impl<X>* p = dynamic_cast<holder_impl<X>*> (holder_.get ())) | |||
return p->value (); | return p->value (); | |||
else | else | |||
throw typing (); | throw typing (); | |||
} | } | |||
public: | ||||
std::type_info const& | std::type_info const& | |||
type_info () const | type_info () const | |||
{ | { | |||
return holder_->type_info (); | return holder_->type_info (); | |||
} | } | |||
public: | ||||
bool | ||||
empty () const | ||||
{ | ||||
return holder_.get () == 0; | ||||
} | ||||
void | ||||
reset () | ||||
{ | ||||
return holder_.reset (); | ||||
} | ||||
private: | private: | |||
class LIBCUTL_EXPORT holder | class LIBCUTL_EXPORT holder | |||
{ | { | |||
public: | public: | |||
virtual | virtual | |||
~holder () {} | ~holder () {} | |||
virtual holder* | virtual holder* | |||
clone () const = 0; | clone () const = 0; | |||
End of changes. 3 change blocks. | ||||
1 lines changed or deleted | 17 lines changed or added | |||
context.hxx | context.hxx | |||
---|---|---|---|---|
skipping to change at line 91 | skipping to change at line 91 | |||
get (char const* key, X const& default_value) const | get (char const* key, X const& default_value) const | |||
{ | { | |||
return get<X> (std::string (key), default_value); | return get<X> (std::string (key), default_value); | |||
} | } | |||
template <typename X> | template <typename X> | |||
X const& | X const& | |||
get (std::string const& key, X const& default_value) const; | get (std::string const& key, X const& default_value) const; | |||
template <typename X> | template <typename X> | |||
void | X& | |||
set (char const* key, X const& value) | set (char const* key, X const& value) | |||
{ | { | |||
set<X> (std::string (key), value); | return set<X> (std::string (key), value); | |||
} | } | |||
template <typename X> | template <typename X> | |||
void | X& | |||
set (std::string const& key, X const& value); | set (std::string const& key, X const& value); | |||
void | void | |||
set (char const* key, container::any const& value) | ||||
{ | ||||
return set (std::string (key), value); | ||||
} | ||||
void | ||||
set (std::string const& key, container::any const& value); | ||||
void | ||||
remove (char const* key) | remove (char const* key) | |||
{ | { | |||
remove (std::string (key)); | remove (std::string (key)); | |||
} | } | |||
void | void | |||
remove (std::string const& key); | remove (std::string const& key); | |||
std::type_info const& | std::type_info const& | |||
type_info (char const* key) const | type_info (char const* key) const | |||
End of changes. 4 change blocks. | ||||
3 lines changed or deleted | 12 lines changed or added | |||
context.txx | context.txx | |||
---|---|---|---|---|
skipping to change at line 68 | skipping to change at line 68 | |||
{ | { | |||
return i->second. template value<X> (); | return i->second. template value<X> (); | |||
} | } | |||
catch (container::any::typing const&) | catch (container::any::typing const&) | |||
{ | { | |||
throw typing (); | throw typing (); | |||
} | } | |||
} | } | |||
template <typename X> | template <typename X> | |||
void context:: | X& context:: | |||
set (std::string const& key, X const& value) | set (std::string const& key, X const& value) | |||
{ | { | |||
try | try | |||
{ | { | |||
std::pair<map::iterator, bool> r ( | std::pair<map::iterator, bool> r ( | |||
map_.insert (map::value_type (key, value))); | map_.insert (map::value_type (key, value))); | |||
X& x (r.first->second. template value<X> ()); | ||||
if (!r.second) | if (!r.second) | |||
r.first->second. template value<X> () = value; | x = value; | |||
return x; | ||||
} | } | |||
catch (container::any::typing const&) | catch (container::any::typing const&) | |||
{ | { | |||
throw typing (); | throw typing (); | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
End of changes. 3 change blocks. | ||||
2 lines changed or deleted | 6 lines changed or added | |||