14 #ifndef INCLUDED_basic_datacache_DataMap_hh
15 #define INCLUDED_basic_datacache_DataMap_hh
21 #include <platform/types.hh>
38 typedef std::map< std::string, std::map< std::string, utility::pointer::ReferenceCountOP > >
::iterator iterator;
54 std::string
const &
type,
55 std::string
const &
name,
59 bool has( std::string
const &
type, std::string
const &
name=
"" )
const;
60 template<
class Ty > Ty
get( std::string
const &
type, std::string
const &
name )
const;
61 template<
class Ty > utility::pointer::shared_ptr< Ty >
get_ptr( std::string
const &
type, std::string
const &
name )
const;
63 std::map< std::string, utility::pointer::ReferenceCountOP > &
operator [](
64 std::string
const &
type
71 std::map< std::string, std::map< std::string, utility::pointer::ReferenceCountOP > >
data_map_;
82 using namespace utility::pointer;
85 if ( !
has( type, name ) ) {
86 std::stringstream error_message;
87 error_message <<
"ERROR: Could not find "<<type<<
" and name "<<name<<
" in Datamap\n";
91 std::map< std::string, utility::pointer::ReferenceCountOP >
const dm(
data_map_.find( type )->second );
93 if ( it->first == name ) {
94 ret =
dynamic_cast< Ty
>( it->second.get() );
99 std::stringstream error_message;
100 error_message <<
"ERROR: Dynamic_cast failed for type "<<type<<
" and name "<<name<<
'\n';
112 utility::pointer::shared_ptr< Ty >
114 using namespace utility::pointer;
115 utility::pointer::shared_ptr< Ty > ret( 0 );
117 if ( !
has( type, name ) ) {
118 std::stringstream error_message;
119 error_message <<
"ERROR: Could not find "<<type<<
" and name "<<name<<
" in Datamap\n";
123 std::map< std::string, utility::pointer::ReferenceCountOP >
const dm(
data_map_.find( type )->second );
125 if ( it->first == name ) {
126 ret = utility::pointer::dynamic_pointer_cast< Ty >( it->second );
131 std::stringstream error_message;
132 error_message <<
"ERROR: Dynamic_cast failed for type "<<type<<
" and name "<<name<<
'\n';
142 template <
class Ty >
143 utility::pointer::shared_ptr< Ty >
145 utility::pointer::shared_ptr< Ty > obj;
146 if ( data.
has( type, name ) ) {
148 TR_hh<<
"Getting object-type, name "<<type<<
' '<<name<<
" from datamap"<<std::endl;
150 obj = utility::pointer::shared_ptr< Ty >(
new Ty );
151 data.
add( type, name, obj );
152 TR_hh<<
"Adding object-type, name "<<type<<
' '<<name<<
" to datamap"<<std::endl;
std::map< std::string, std::map< std::string, utility::pointer::ReferenceCountOP > >::iterator iterator
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
ReferenceCount base class – dispatch class.
static THREAD_LOCAL basic::Tracer TR_hh("basic.datacache.DataMap_hh")
Non-owning access smart pointer – dispatch class.
std::map< std::string, utility::pointer::ReferenceCountOP > & operator[](std::string const &type)
utility::pointer::shared_ptr< Ty > get_ptr(std::string const &type, std::string const &name) const
common derived classes for thrown exceptions
Base class for reference-counted polymorphic classes.
std::map< std::string, std::map< std::string, utility::pointer::ReferenceCountOP > >::const_iterator const_iterator
bool add(std::string const &type, std::string const &name, utility::pointer::ReferenceCountOP const op)
general-purpose store for any reference-count derived object
Ty get(std::string const &type, std::string const &name) const
boost::shared_ptr< ReferenceCount > ReferenceCountOP
utility::pointer::shared_ptr< Ty > get_set_from_datamap(std::string const &type, std::string const &name, basic::datacache::DataMap &data)
templated function for adding or getting an item from the datamap. Automatically checks whether an it...
platform::Size size() const
returns the size of the map (how many different types are in data_map_
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
rule< Scanner, string_closure::context_t > name
bool has(std::string const &type, std::string const &name="") const
std::map< std::string, std::map< std::string, utility::pointer::ReferenceCountOP > > data_map_