00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file String_Manager_T.h 00006 * 00007 * $Id: String_Manager_T.h 74014 2006-08-14 13:52:22Z johnnyw $ 00008 * 00009 * @author Johnny Willemsen <jwillemsen@remedy.nl> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef TAO_STRING_MANAGER_T 00014 #define TAO_STRING_MANAGER_T 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include /**/ "tao/TAO_Export.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #include "tao/Basic_Types.h" 00025 #include "tao/String_Traits_Base_T.h" 00026 00027 #include <algorithm> 00028 00029 /****************************************************************/ 00030 00031 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00032 00033 namespace TAO 00034 { 00035 template <typename charT> 00036 class String_Manager_T 00037 { 00038 public: 00039 typedef charT character_type; 00040 typedef TAO::details::string_traits_base <charT> s_traits; 00041 00042 /// Default CTOR will initialize the underlying ptr_ to empty string. 00043 inline String_Manager_T (void) : ptr_ (s_traits::default_initializer()) 00044 { 00045 } 00046 00047 /// Copy constructor 00048 inline String_Manager_T (const String_Manager_T<charT> &rhs) : 00049 ptr_ (s_traits::duplicate (rhs.ptr_)) 00050 { 00051 } 00052 00053 /// Constructor from const char* makes a copy. 00054 inline String_Manager_T (const character_type *s) : 00055 ptr_ (s_traits::duplicate (s)) 00056 { 00057 } 00058 00059 /// Destructor 00060 inline ~String_Manager_T (void) { 00061 s_traits::release (this->ptr_); 00062 } 00063 00064 /// Assignment from another managed type 00065 inline String_Manager_T &operator= (const String_Manager_T<charT> &rhs) { 00066 // Strongly exception safe by means of copy and non-throwing swap 00067 // technique. 00068 String_Manager_T <character_type> tmp (rhs); 00069 std::swap (this->ptr_, tmp.ptr_); 00070 return *this; 00071 } 00072 00073 /// Assignment from var type will make a copy 00074 inline String_Manager_T &operator= (const typename s_traits::string_var& value) { 00075 // Strongly exception safe by means of copy and non-throwing swap 00076 // technique. 00077 String_Manager_T <character_type> tmp (value.in ()); 00078 std::swap (this->ptr_, tmp.ptr_); 00079 return *this; 00080 } 00081 00082 /// Assignment from a constant * will make a copy 00083 inline String_Manager_T &operator= (const character_type *p) { 00084 // Strongly exception safe by means of copy and non-throwing swap 00085 // technique. 00086 String_Manager_T <character_type> tmp (p); 00087 std::swap (this->ptr_, tmp.ptr_); 00088 return *this; 00089 } 00090 00091 /// Assignment from char* will not make a copy. The String_Manager_T will now 00092 /// own the string. 00093 inline String_Manager_T &operator= (character_type *p) { 00094 s_traits::release (this->ptr_); 00095 this->ptr_ = p; 00096 return *this; 00097 } 00098 00099 /// Cast (read-only) 00100 inline operator const character_type*() const { 00101 return this->ptr_; 00102 } 00103 00104 /// For in parameter. 00105 inline const character_type *in (void) const { 00106 return this->ptr_; 00107 } 00108 00109 /// For inout parameter. 00110 inline character_type *&inout (void) { 00111 return this->ptr_; 00112 } 00113 00114 /// for out parameter. 00115 inline character_type *&out (void) { 00116 s_traits::release (this->ptr_); 00117 this->ptr_ = 0; 00118 return this->ptr_; 00119 } 00120 00121 /// For string of return type. 00122 inline character_type *_retn (void) { 00123 character_type *temp = this->ptr_; 00124 this->ptr_ = 0; 00125 return temp; 00126 } 00127 00128 private: 00129 /// The underlying string 00130 character_type *ptr_; 00131 }; 00132 00133 typedef TAO::String_Manager_T<CORBA::Char> String_Manager; 00134 typedef TAO::String_Manager_T<CORBA::WChar> WString_Manager; 00135 } 00136 00137 TAO_END_VERSIONED_NAMESPACE_DECL 00138 00139 #include /**/ "ace/post.h" 00140 #endif /* TAO_STRING_MANAGER_T */