Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
Teuchos_RCPNode.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef TEUCHOS_RCP_NODE_HPP
43 #define TEUCHOS_RCP_NODE_HPP
44 
45 
52 #include "Teuchos_ConfigDefs.hpp"
53 #include "Teuchos_any.hpp"
54 #include "Teuchos_map.hpp"
55 #include "Teuchos_ENull.hpp"
56 #include "Teuchos_Assert.hpp"
57 #include "Teuchos_Exceptions.hpp"
59 #include "Teuchos_toString.hpp"
61 
62 
63 namespace Teuchos {
64 
65 
71 
77 
83 
85 inline void debugAssertStrength(ERCPStrength strength)
86 {
87 #ifdef TEUCHOS_DEBUG
88  switch (strength) {
89  case RCP_STRONG:
90  // fall through
91  case RCP_WEAK:
92  return; // Fine
93  default:
95  }
96 #else
97  (void) strength; // Silence "unused variable" compiler warning.
98 #endif // TEUCHOS_DEBUG
99 }
100 
106 template<>
108 public:
109  static std::string toString( const ERCPStrength &t )
110  {
111  switch (t) {
112  case RCP_STRONG:
113  return "RCP_STRONG";
114  case RCP_WEAK:
115  return "RCP_WEAK";
116  default:
117  // Should never get here but fall through ...
118  break;
119  }
120  // Should never get here!
121 #ifdef TEUCHOS_DEBUG
123 #endif
124  return "";
125  // 2009/06/30: rabartl: The above logic avoid a warning from the Intel
126  // 10.1 compiler (remark #111) about the statement being unreachable.
127  //
128  // mfh (06 Mar 2013) This triggers a warning in Clang 3.2 with
129  // "-Weverything", because it's an unreachable statement. Alas,
130  // we can't please _all_ the compilers equally...
131  }
132 };
133 
134 
147 public:
149  RCPNode(bool has_ownership_in)
150  : has_ownership_(has_ownership_in), extra_data_map_(NULL)
151 #ifdef TEUCHOS_DEBUG
152  ,insertion_number_(-1)
153 #endif // TEUCHOS_DEBUG
154  {
155  count_[RCP_STRONG] = 0;
156  count_[RCP_WEAK] = 0;
157  }
159  virtual ~RCPNode()
160  {
161  if(extra_data_map_)
162  delete extra_data_map_;
163  }
165  int strong_count() const
166  {
167  return count_[RCP_STRONG];
168  }
170  int weak_count() const
171  {
172  return count_[RCP_WEAK];
173  }
175  int incr_count( const ERCPStrength strength )
176  {
177  debugAssertStrength(strength);
178  return ++count_[strength];
179  }
181  int deincr_count( const ERCPStrength strength )
182  {
183  debugAssertStrength(strength);
184  return --count_[strength];
185  }
187  void has_ownership(bool has_ownership_in)
188  {
189  has_ownership_ = has_ownership_in;
190  }
192  bool has_ownership() const
193  {
194  return has_ownership_;
195  }
197  void set_extra_data(
198  const any &extra_data, const std::string& name,
199  EPrePostDestruction destroy_when, bool force_unique );
201  any& get_extra_data( const std::string& type_name,
202  const std::string& name );
204  const any& get_extra_data( const std::string& type_name,
205  const std::string& name
206  ) const
207  {
208  return const_cast<RCPNode*>(this)->get_extra_data(type_name, name);
209  }
211  any* get_optional_extra_data(const std::string& type_name,
212  const std::string& name );
215  const std::string& type_name, const std::string& name
216  ) const
217  {
218  return const_cast<RCPNode*>(this)->get_optional_extra_data(type_name, name);
219  }
221  virtual bool is_valid_ptr() const = 0;
223  virtual void delete_obj() = 0;
225  virtual void throw_invalid_obj_exception(
226  const std::string& rcp_type_name,
227  const void* rcp_ptr,
228  const RCPNode* rcp_node_ptr,
229  const void* rcp_obj_ptr
230  ) const = 0;
232  virtual const std::string get_base_obj_type_name() const = 0;
233 #ifdef TEUCHOS_DEBUG
234 
235  virtual const void* get_base_obj_map_key_void_ptr() const = 0;
236 #endif
237 protected:
240  {
241  if(extra_data_map_)
242  impl_pre_delete_extra_data();
243  }
244 private:
246  extra_data_entry_t() : destroy_when(POST_DESTROY) {}
247  extra_data_entry_t( const any &_extra_data, EPrePostDestruction _destroy_when )
248  : extra_data(_extra_data), destroy_when(_destroy_when)
249  {}
252  };
253  typedef Teuchos::map<std::string,extra_data_entry_t> extra_data_map_t;
254  int count_[2];
256  extra_data_map_t *extra_data_map_;
257  // Above is made a pointer to reduce overhead for the general case when this
258  // is not used. However, this adds just a little bit to the overhead when
259  // it is used.
260  // Provides the "basic" guarantee!
261  void impl_pre_delete_extra_data();
262  // Not defined and not to be called
263  RCPNode();
264  RCPNode(const RCPNode&);
265  RCPNode& operator=(const RCPNode&);
266 #ifdef TEUCHOS_DEBUG
267  int insertion_number_;
268 public:
269  void set_insertion_number(int insertion_number_in)
270  {
271  insertion_number_ = insertion_number_in;
272  }
273  int insertion_number() const
274  {
275  return insertion_number_;
276  }
277 #endif // TEUCHOS_DEBUG
278 };
279 
280 
285 TEUCHOSCORE_LIB_DLL_EXPORT void throw_null_ptr_error( const std::string &type_name );
286 
287 
305 public:
306 
309 
313  : maxNumRCPNodes(0), totalNumRCPNodeAllocations(0),
314  totalNumRCPNodeDeletions(0)
315  {}
316  long int maxNumRCPNodes;
319  };
320 
322 
325 
331  static bool isTracingActiveRCPNodes();
332 
333 #if defined(TEUCHOS_DEBUG) && !defined(HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING)
334 
351  static void setTracingActiveRCPNodes(bool tracingActiveNodes);
352 #endif
353 
357  static int numActiveRCPNodes();
358 
360  static RCPNodeStatistics getRCPNodeStatistics() ;
361 
363  static void printRCPNodeStatistics(
364  const RCPNodeStatistics& rcpNodeStatistics, std::ostream &out);
365 
369  static void setPrintRCPNodeStatisticsOnExit(
370  bool printRCPNodeStatisticsOnExit);
371 
375  static bool getPrintRCPNodeStatisticsOnExit();
376 
391  static void printActiveRCPNodes(std::ostream &out);
392 
394 
399 
404  static void addNewRCPNode(RCPNode* rcp_node,
405  const std::string &info );
406 
412  static void removeRCPNode( RCPNode* rcp_node );
413 
422  template<class T>
423  static const void* getRCPNodeBaseObjMapKeyVoidPtr(T *p)
424  {
425 #ifdef HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR
426  return getBaseObjVoidPtr(p);
427 #else
428  // This will not return the base address for polymorphic types if
429  // multiple inheritance and/or virtual bases are used but returning the
430  // static_cast should be okay in how it is used. It is just that the
431  // RCPNode tracing support will not always be able to figure out if two
432  // pointers of different type are pointing to the same object or not.
433  return static_cast<const void*>(p);
434 #endif
435  }
436 
443  static RCPNode* getExistingRCPNodeGivenLookupKey(
444  const void* lookupKey);
445 
452  template<class T>
454  {
455  return getExistingRCPNodeGivenLookupKey(getRCPNodeBaseObjMapKeyVoidPtr(p));
456  }
457 
459  static std::string getActiveRCPNodeHeaderString();
460 
462  static std::string getCommonDebugNotesString();
463 
465 
466 };
467 
468 
469 #ifdef TEUCHOS_DEBUG
470 # define TEUCHOS_RCP_INSERION_NUMBER_STR() \
471  " insertionNumber: " << rcp_node_ptr->insertion_number() << "\n"
472 #else
473 # define TEUCHOS_RCP_INSERION_NUMBER_STR()
474 #endif
475 
476 
482 template<class T, class Dealloc_T>
483 class RCPNodeTmpl : public RCPNode {
484 public:
486  RCPNodeTmpl(T* p, Dealloc_T dealloc, bool has_ownership_in)
487  : RCPNode(has_ownership_in), ptr_(p),
488 #ifdef TEUCHOS_DEBUG
489  base_obj_map_key_void_ptr_(RCPNodeTracer::getRCPNodeBaseObjMapKeyVoidPtr(p)),
490  deleted_ptr_(0),
491 #endif
492  dealloc_(dealloc)
493  {}
495  RCPNodeTmpl(T* p, Dealloc_T dealloc, bool has_ownership_in, ENull)
496  : RCPNode(has_ownership_in), ptr_(p),
497 #ifdef TEUCHOS_DEBUG
498  base_obj_map_key_void_ptr_(0),
499  deleted_ptr_(0),
500 #endif
501  dealloc_(dealloc)
502  {}
504  Dealloc_T& get_nonconst_dealloc()
505  { return dealloc_; }
507  const Dealloc_T& get_dealloc() const
508  { return dealloc_; }
511  {
512 #ifdef TEUCHOS_DEBUG
513  TEUCHOS_TEST_FOR_EXCEPTION( ptr_!=0, std::logic_error,
514  "Error, the underlying object must be explicitly deleted before deleting"
515  " the node object!" );
516 #endif
517  }
519  virtual bool is_valid_ptr() const
520  {
521  return ptr_ != 0;
522  }
528  virtual void delete_obj()
529  {
530  if (ptr_!= 0) {
531  this->pre_delete_extra_data(); // May throw!
532  T* tmp_ptr = ptr_;
533 #ifdef TEUCHOS_DEBUG
534  deleted_ptr_ = tmp_ptr;
535 #endif
536  ptr_ = 0;
537  if (has_ownership()) {
538 #ifdef TEUCHOS_DEBUG
539  try {
540 #endif
541  dealloc_.free(tmp_ptr);
542 #ifdef TEUCHOS_DEBUG
543  }
544  catch(...) {
545  // Object was not deleted due to an exception!
546  ptr_ = tmp_ptr;
547  throw;
548  }
549 #endif
550  }
551  // 2008/09/22: rabartl: Above, we have to be careful to set the member
552  // this->ptr_=0 before calling delete on the object's address in order
553  // to avoid a double call to delete in cases of circular references
554  // involving weak and strong pointers (see the unit test
555  // circularReference_c_then_a in RCP_UnitTests.cpp). NOTE: It is
556  // critcial that no member of *this get accesses after
557  // dealloc_.free(...) gets called! Also, in order to provide the
558  // "strong" guarantee we have to include the above try/catch. This
559  // overhead is unfortunate but I don't know of any other way to
560  // statisfy the "strong" guarantee and still avoid a double delete.
561  }
562  }
565  const std::string& rcp_type_name,
566  const void* rcp_ptr,
567  const RCPNode* rcp_node_ptr,
568  const void* rcp_obj_ptr
569  ) const
570  {
571  TEUCHOS_TEST_FOR_EXCEPT_MSG( ptr_!=0, "Internal coding error!" );
572  const T* deleted_ptr =
573 #ifdef TEUCHOS_DEBUG
574  deleted_ptr_
575 #else
576  0
577 #endif
578  ;
579  TEUCHOS_ASSERT(rcp_node_ptr);
581  "Error, an attempt has been made to dereference the underlying object\n"
582  "from a weak smart pointer object where the underling object has already\n"
583  "been deleted since the strong count has already gone to zero.\n"
584  "\n"
585  "Context information:\n"
586  "\n"
587  " RCP type: " << rcp_type_name << "\n"
588  " RCP address: " << rcp_ptr << "\n"
589  " RCPNode type: " << typeName(*this) << "\n"
590  " RCPNode address: " << rcp_node_ptr << "\n"
592  " RCP ptr address: " << rcp_obj_ptr << "\n"
593  " Concrete ptr address: " << deleted_ptr << "\n"
594  "\n"
596  );
597  // 2008/09/22: rabartl: Above, we do not provide the concreate object
598  // type or the concrete object address. In the case of the concrete
599  // object address, in a non-debug build, we don't want to pay a price
600  // for extra storage that we strictly don't need. In the case of the
601  // concrete object type name, we don't want to force non-debug built
602  // code to have the require that types be fully defined in order to use
603  // the memory management software. This is related to bug 4016.
604 
605  }
607  const std::string get_base_obj_type_name() const
608  {
609 #ifdef TEUCHOS_DEBUG
610  return TypeNameTraits<T>::name();
611 #else
612  return "UnknownType";
613 #endif
614  }
615 #ifdef TEUCHOS_DEBUG
616 
617  const void* get_base_obj_map_key_void_ptr() const
618  {
619  return base_obj_map_key_void_ptr_;
620  }
621 #endif
622 private:
623  T *ptr_;
624 #ifdef TEUCHOS_DEBUG
625  const void *base_obj_map_key_void_ptr_;
626  T *deleted_ptr_;
627 #endif
628  Dealloc_T dealloc_;
629  // not defined and not to be called
630  RCPNodeTmpl();
631  RCPNodeTmpl(const RCPNodeTmpl&);
632  RCPNodeTmpl& operator=(const RCPNodeTmpl&);
633 
634 }; // end class RCPNodeTmpl<T>
635 
636 
645 public:
651  void foo();
652 private:
653  static int count_;
654 };
655 
656 
657 } // namespace Teuchos
658 
659 
660 namespace {
661 // This static variable is declared before all other static variables that
662 // depend on RCP or other classes. Therefore, this static variable will be
663 // deleted *after* all of these other static variables that depend on RCP or
664 // created classes go away! This ensures that the node tracing machinery is
665 // setup and torn down correctly (this is the same trick used by the standard
666 // stream objects in many compiler implementations).
667 Teuchos::ActiveRCPNodesSetup local_activeRCPNodesSetup;
668 } // namespace (anonymous)
669 
670 
671 namespace Teuchos {
672 
690 public:
692  RCPNodeHandle (ENull null_arg = null)
693  : node_ (0), strength_ (RCP_STRONG)
694  {
695  (void) null_arg; // Silence "unused variable" compiler warning.
696  }
697 
700  ERCPStrength strength_in = RCP_STRONG,
701  bool newNode = true)
702  : node_ (node), strength_ (strength_in)
703  {
704 #ifdef TEUCHOS_DEBUG
705  TEUCHOS_ASSERT(node);
706 #endif // TEUCHOS_DEBUG
707 
708  bind();
709 
710 #ifdef TEUCHOS_DEBUG
711  // Add the node if this is the first RCPNodeHandle to get it. We have
712  // to add it because unbind() will call the remove_RCPNode(...) function
713  // and it needs to match when node tracing is on from the beginning.
714  if (RCPNodeTracer::isTracingActiveRCPNodes() && newNode) {
715  std::ostringstream os;
716  os << "{T=Unknown, ConcreteT=Unknown, p=Unknown,"
717  << " has_ownership="<<node_->has_ownership()<<"}";
718  RCPNodeTracer::addNewRCPNode(node_, os.str());
719  }
720 #else
721  (void) newNode; // Silence "unused variable" compiler warning.
722 #endif // TEUCHOS_DEBUG
723  }
724 
725 #ifdef TEUCHOS_DEBUG
726 
727  template<typename T>
728  RCPNodeHandle (RCPNode* node, T *p, const std::string &T_name,
729  const std::string &ConcreteT_name,
730  const bool has_ownership_in,
731  ERCPStrength strength_in = RCP_STRONG)
732  : node_ (node), strength_ (strength_in)
733  {
734  TEUCHOS_ASSERT(strength_in == RCP_STRONG); // Can't handle weak yet!
735  TEUCHOS_ASSERT(node_);
736  bind();
738  std::ostringstream os;
739  os << "{T="<<T_name<<", ConcreteT="<< ConcreteT_name
740  <<", p="<<static_cast<const void*>(p)
741  <<", has_ownership="<<has_ownership_in<<"}";
742  RCPNodeTracer::addNewRCPNode(node_, os.str());
743  }
744  }
745 #endif // TEUCHOS_DEBUG
746 
748  RCPNodeHandle (const RCPNodeHandle& node_ref)
749  : node_ (node_ref.node_), strength_ (node_ref.strength_)
750  {
751  bind();
752  }
753 
755  void swap (RCPNodeHandle& node_ref) {
756  std::swap (node_ref.node_, node_);
757  std::swap (node_ref.strength_, strength_);
758  }
759 
765  RCPNodeHandle& operator= (const RCPNodeHandle& node_ref) {
766  // Assignment to self check: Note, We don't need to do an assigment to
767  // self check here because such a check is already done in the RCP and
768  // ArrayRCP classes.
769  // Take care of this's existing node and object
770  unbind(); // May throw in some cases
771  // Assign the new node
772  node_ = node_ref.node_;
773  strength_ = node_ref.strength_;
774  bind();
775  // Return
776  return *this;
777  }
778 
781  unbind();
782  }
783 
785  RCPNodeHandle create_weak() const {
786  if (node_) {
787  return RCPNodeHandle(node_, RCP_WEAK, false);
788  }
789  return RCPNodeHandle();
790  }
792  RCPNodeHandle create_strong() const {
793  if (node_) {
794  return RCPNodeHandle(node_, RCP_STRONG, false);
795  }
796  return RCPNodeHandle();
797  }
799  RCPNode* node_ptr() const {
800  return node_;
801  }
803  bool is_node_null() const {
804  return node_==0;
805  }
809  bool is_valid_ptr() const {
810  if (node_) {
811  return node_->is_valid_ptr();
812  }
813  return true; // Null is a valid ptr!
814  }
817  bool same_node(const RCPNodeHandle &node2) const {
818  return node_ == node2.node_;
819  }
821  int strong_count() const {
822  if (node_) {
823  return node_->strong_count();
824  }
825  return 0;
826  }
828  int weak_count() const {
829  if (node_) {
830  return node_->weak_count();
831  }
832  return 0;
833  }
835  int total_count() const {
836  if (node_) {
837  return node_->strong_count() + node_->weak_count();
838  }
839  return 0;
840  }
842  int count() const {
843  if (node_) {
844  return node_->strong_count();
845  }
846  return 0;
847  }
850  return strength_;
851  }
853  void has_ownership(bool has_ownership_in)
854  {
855  if (node_)
856  node_->has_ownership(has_ownership_in);
857  }
859  bool has_ownership() const
860  {
861  if (node_)
862  return node_->has_ownership();
863  return false;
864  }
867  const any &extra_data, const std::string& name,
868  EPrePostDestruction destroy_when, bool force_unique
869  )
870  {
871  debug_assert_not_null();
872  node_->set_extra_data(extra_data, name, destroy_when, force_unique);
873  }
875  any& get_extra_data( const std::string& type_name,
876  const std::string& name
877  )
878  {
879  debug_assert_not_null();
880  return node_->get_extra_data(type_name, name);
881  }
883  const any& get_extra_data( const std::string& type_name,
884  const std::string& name
885  ) const
886  {
887  return const_cast<RCPNodeHandle*>(this)->get_extra_data(type_name, name);
888  }
891  const std::string& type_name, const std::string& name
892  )
893  {
894  debug_assert_not_null();
895  return node_->get_optional_extra_data(type_name, name);
896  }
899  const std::string& type_name, const std::string& name
900  ) const
901  {
902  return const_cast<RCPNodeHandle*>(this)->get_optional_extra_data(type_name, name);
903  }
906  {
907 #ifdef TEUCHOS_DEBUG
908  if (!node_)
909  throw_null_ptr_error(typeName(*this));
910 #endif
911  }
913  template<class RCPType>
914  void assert_valid_ptr(const RCPType& rcp_obj) const
915  {
916  if (!node_)
917  return; // Null is a valid pointer!
918  if (!is_valid_ptr()) {
919  node_->throw_invalid_obj_exception( typeName(rcp_obj),
920  this, node_, rcp_obj.access_private_ptr() );
921  }
922  }
924  template<class RCPType>
925  void debug_assert_valid_ptr(const RCPType& rcp_obj) const
926  {
927 #ifdef TEUCHOS_DEBUG
928  assert_valid_ptr(rcp_obj);
929 #endif
930  }
931 #ifdef TEUCHOS_DEBUG
932  const void* get_base_obj_map_key_void_ptr() const
933  {
934  if (node_)
935  return node_->get_base_obj_map_key_void_ptr();
936  return 0;
937  }
938 #endif
939 private:
942  inline void bind()
943  {
944  if (node_)
945  node_->incr_count(strength_);
946  }
947  inline void unbind()
948  {
949  // Optimize this implementation for count > 1
950  if (node_ && node_->deincr_count(strength_)==0) {
951  // If we get here, the reference count has gone to 0 and something
952  // interesting is going to happen. In this case, we need to
953  // reincrement the count back to 1 and call the more complex function
954  // that will either delete the object or delete the node.
955  node_->incr_count(strength_);
956  unbindOne();
957  }
958  // If we get here, either node_==0 or the count is still greater than 0.
959  // In this case, nothing interesting is going to happen so we are done!
960  }
961  void unbindOne(); // Provides the "strong" guarantee!
962 
963 };
964 
965 
970 inline
971 std::ostream& operator<<(std::ostream& out, const RCPNodeHandle& node)
972 {
973  return (out << node.node_ptr());
974 }
975 
976 
987 public:
990  : node_(node)
991  {}
998  {
999  if (node_) {
1000  node_->has_ownership(false); // Avoid actually deleting ptr_
1001  node_->delete_obj(); // Sets the pointer ptr_=0 to allow RCPNode delete
1002  delete node_;
1003  }
1004  }
1006  RCPNode* get() const
1007  {
1008  return node_;
1009  }
1011  void release()
1012  {
1013  node_ = 0;
1014  }
1015 private:
1017  RCPNodeThrowDeleter(); // Not defined
1018  RCPNodeThrowDeleter(const RCPNodeThrowDeleter&); // Not defined
1019  RCPNodeThrowDeleter& operator=(const RCPNodeThrowDeleter&); // Not defined
1020 };
1021 
1022 
1023 //
1024 // Unit testing support
1025 //
1026 
1027 
1028 #if defined(TEUCHOS_DEBUG) && !defined(HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING)
1029 
1030 class SetTracingActiveNodesStack {
1031 public:
1032  SetTracingActiveNodesStack()
1033  {RCPNodeTracer::setTracingActiveRCPNodes(true);}
1034  ~SetTracingActiveNodesStack()
1035  {RCPNodeTracer::setTracingActiveRCPNodes(false);}
1036 };
1037 
1038 # define SET_RCPNODE_TRACING() Teuchos::SetTracingActiveNodesStack setTracingActiveNodesStack;
1039 
1040 #else
1041 
1042 # define SET_RCPNODE_TRACING() (void)0
1043 
1044 #endif // defined(TEUCHOS_DEBUG) && !defined(HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING)
1045 
1046 
1047 } // end namespace Teuchos
1048 
1049 
1050 #endif // TEUCHOS_RCP_NODE_HPP
Dangling reference error exception class.
const Dealloc_T & get_dealloc() const
bool has_ownership() const
int weak_count() const
The weak count for this RCPNode, or 0 if the node is NULL.
ERCPStrength
Used to specify if the pointer is weak or strong.
Modified boost::any class for holding a templated value.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
const any * get_optional_extra_data(const std::string &type_name, const std::string &name) const
virtual void throw_invalid_obj_exception(const std::string &rcp_type_name, const void *rcp_ptr, const RCPNode *rcp_node_ptr, const void *rcp_obj_ptr) const
static const void * getRCPNodeBaseObjMapKeyVoidPtr(T *p)
Get a const void* address to be used as the lookup key for an RCPNode given its embedded object&#39;s typ...
static bool isTracingActiveRCPNodes()
Return if we are tracing active nodes or not.
static std::string toString(const ERCPStrength &t)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Dealloc_T & get_nonconst_dealloc()
int deincr_count(const ERCPStrength strength)
any & get_extra_data(const std::string &type_name, const std::string &name)
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
RCPNodeHandle(ENull null_arg=null)
Default constructor.
void debug_assert_valid_ptr(const RCPType &rcp_obj) const
any * get_optional_extra_data(const std::string &type_name, const std::string &name)
ERCPNodeLookup
Used to determine if RCPNode lookup is performed or not.
void release()
Releaes the RCPNode pointer before the destructor is called.
const std::string get_base_obj_type_name() const
std::ostream & operator<<(std::ostream &out, const RCPNodeHandle &node)
Ouput stream operator for RCPNodeHandle.
Modified boost::any class, which is a container for a templated value.
Definition: Teuchos_any.hpp:86
RCPNodeHandle(const RCPNodeHandle &node_ref)
Copy constructor.
extra_data_entry_t()
RCPNodeHandle(RCPNode *node, ERCPStrength strength_in=RCP_STRONG, bool newNode=true)
Constructor that takes a pointer to an RCPNode.
Sets up node tracing and prints remaining RCPNodes on destruction.
void has_ownership(bool has_ownership_in)
static std::string getCommonDebugNotesString()
Common error message string on how to debug RCPNode problems.
Debug-mode RCPNode tracing class.
virtual void delete_obj()
Delete the underlying object.
Node class to keep track of address and the reference count for a reference-counted utility class and...
RCPNodeTmpl(T *p, Dealloc_T dealloc, bool has_ownership_in, ENull)
For undefined types .
Templated implementation class of RCPNode that has the responsibility for deleting the reference-coun...
#define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...
#define TEUCHOSCORE_LIB_DLL_EXPORT
void assert_valid_ptr(const RCPType &rcp_obj) const
void debugAssertStrength(ERCPStrength strength)
int incr_count(const ERCPStrength strength)
RCPNodeHandle create_strong() const
Return a strong handle.
ERCPStrength strength() const
The strength of this handle.
int strong_count() const
const any * get_optional_extra_data(const std::string &type_name, const std::string &name) const
const any & get_extra_data(const std::string &type_name, const std::string &name) const
RCPNode(bool has_ownership_in)
#define TEUCHOS_RCP_INSERION_NUMBER_STR()
void set_extra_data(const any &extra_data, const std::string &name, EPrePostDestruction destroy_when, bool force_unique)
static RCPNode * getExistingRCPNode(T *p)
Return a raw pointer to an existing owning RCPNode given the address to the underlying object if it e...
void debug_assert_not_null() const
Provides std::map class for deficient platforms.
int weak_count() const
EPrePostDestruction
Used to specify a pre or post destruction of extra data.
Handle class that manages the RCPNode&#39;s reference counting.
int strong_count() const
The strong count for this RCPNode, or 0 if the node is NULL.
void has_ownership(bool has_ownership_in)
~RCPNodeThrowDeleter()
Called with node_!=0 when an exception is thrown.
int total_count() const
The sum of the weak and string counts.
extra_data_map_t * extra_data_map_
bool is_valid_ptr() const
Whether the underlying pointer is valid.
RCPNodeTmpl(T *p, Dealloc_T dealloc, bool has_ownership_in)
For defined types.
extra_data_entry_t(const any &_extra_data, EPrePostDestruction _destroy_when)
bool same_node(const RCPNodeHandle &node2) const
Whether the RCPNode for which node2 is a handle is the same RCPNode as this object&#39;s RCPNode...
Deletes a (non-owning) RCPNode but not it&#39;s underlying object in case of a throw. ...
bool is_node_null() const
Whether the underlying RCPNode is NULL.
#define TEUCHOS_ASSERT(assertion_test)
This macro is throws when an assert fails.
const any & get_extra_data(const std::string &type_name, const std::string &name) const
RCPNode * node_ptr() const
Return a pointer to the underlying RCPNode.
Default traits class for converting objects into strings.
Teuchos::map< std::string, extra_data_entry_t > extra_data_map_t
EPrePostDestruction destroy_when
RCPNodeHandle create_weak() const
Return a weak handle.
virtual bool is_valid_ptr() const
int count() const
The strong count; retained for backwards compatibility.
any extra_data
Defines basic traits returning the name of a type in a portable and readable way. ...
void swap(RCPNodeHandle &node_ref)
Swap the contents of node_ref with *this.
static void addNewRCPNode(RCPNode *rcp_node, const std::string &info)
Add new RCPNode to the global list.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...