00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "Teuchos_RefCountPtr.hpp"
00030 #include "Teuchos_TestForException.hpp"
00031
00032 namespace Teuchos {
00033
00034 void PrivateUtilityPack::throw_null( const std::string &type_name )
00035 {
00036 TEST_FOR_EXCEPTION(
00037 true, std::logic_error
00038 ,"RefCountPtr<"<<type_name<<">::assert_not_null() : You can not "
00039 " call operator->() or operator*() if get()==NULL!" );
00040 }
00041
00042 namespace PrivateUtilityPack {
00043
00044 void RefCountPtr_node::set_extra_data( const any &extra_data, const std::string& name, bool force_unique, EPrePostDestruction destroy_when )
00045 {
00046 if(extra_data_map_==NULL) {
00047 extra_data_map_ = new extra_data_map_t;
00048 }
00049 const std::string type_and_name( extra_data.type().name() + std::string(":") + name );
00050 if( !extra_data_map_->empty() && force_unique ) {
00051 extra_data_map_t::iterator itr = extra_data_map_->find(type_and_name);
00052 TEST_FOR_EXCEPTION(
00053 itr != extra_data_map_->end(), std::invalid_argument
00054 ,"Error, the type:name pair \'" << type_and_name << "\' already exists and force_unique==true!" );
00055 }
00056 (*extra_data_map_)[type_and_name] = extra_data_entry_t(extra_data,destroy_when);
00057 }
00058
00059 any& RefCountPtr_node::get_extra_data( const std::string& type_name, const std::string& name )
00060 {
00061 TEST_FOR_EXCEPTION(
00062 extra_data_map_==NULL, std::invalid_argument
00063 ,"Error, no extra data has been set yet!" );
00064 const std::string type_and_name( type_name + std::string(":") + name );
00065 extra_data_map_t::iterator itr = extra_data_map_->find(type_and_name);
00066 TEST_FOR_EXCEPTION(
00067 itr == extra_data_map_->end(), std::invalid_argument
00068 ,"Error, the type:name pair \'" << type_and_name << "\' is not found!" );
00069 return (*itr).second.extra_data;
00070 }
00071
00072 void RefCountPtr_node::impl_pre_delete_extra_data()
00073 {
00074 for( extra_data_map_t::iterator itr = extra_data_map_->begin(); itr != extra_data_map_->end(); ++itr ) {
00075 extra_data_map_t::value_type &entry = *itr;
00076 if(entry.second.destroy_when == PRE_DESTROY)
00077 entry.second.extra_data = any();
00078 }
00079 }
00080
00081 }
00082 }
00083